summaryrefslogtreecommitdiff
path: root/rsScript.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2011-11-09 18:02:20 -0800
committerStephen Hines <srhines@google.com>2011-11-10 15:44:25 -0800
commitd2432b9691869b5b40a5b49c682c40d917ea9dcb (patch)
tree319d508edc5feca1dba2859959238f7fe4c3907f /rsScript.cpp
parent5aa250bbf5d6d1dd0cf1ef4c16440d2968097771 (diff)
downloadrs-d2432b9691869b5b40a5b49c682c40d917ea9dcb.tar.gz
Fix setTimeZone() and use it properly in RSTest/rstime.
BUG=5470134 The original implementation for rsi_ScriptSetTimeZone() never actually did anything with the bytes received. This change allows it to safely update the timezone. RSTest is also updated to call setTimeZone(), so that users in different timezones can accurately get test results. Change-Id: I6cb1b3a0c3a417749ba39e0fe09cc9c7ab65c2e7
Diffstat (limited to 'rsScript.cpp')
-rw-r--r--rsScript.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/rsScript.cpp b/rsScript.cpp
index 93513fe3..16446ddd 100644
--- a/rsScript.cpp
+++ b/rsScript.cpp
@@ -15,6 +15,7 @@
*/
#include "rsContext.h"
+#include <time.h>
using namespace android;
using namespace android::renderscript;
@@ -89,8 +90,22 @@ void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint3
}
void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
- Script *s = static_cast<Script *>(vs);
- s->mEnviroment.mTimeZone = timeZone;
+ // We unfortunately need to make a new copy of the string, since it is
+ // not NULL-terminated. We then use setenv(), which properly handles
+ // freeing/duplicating the actual string for the environment.
+ char *tz = (char *) malloc(length + 1);
+ if (!tz) {
+ LOGE("Couldn't allocate memory for timezone buffer");
+ return;
+ }
+ strncpy(tz, timeZone, length);
+ tz[length] = '\0';
+ if (setenv("TZ", tz, 1) == 0) {
+ tzset();
+ } else {
+ LOGE("Error setting timezone");
+ }
+ free(tz);
}
void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,