changeset 1511:df792340e3f7 draft

Bugfix from Ashwini Sharma: Z timezone required by posix for touch but not for libc, so we have to implement it here.
author Rob Landley <rob@landley.net>
date Wed, 01 Oct 2014 19:57:34 -0500
parents 4f3a5d600803
children 7afd32673a5c
files toys/posix/touch.c
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/touch.c	Sun Sep 28 19:34:53 2014 -0500
+++ b/toys/posix/touch.c	Wed Oct 01 19:57:34 2014 -0500
@@ -36,7 +36,7 @@
 {
   struct stat st;
 
-  if (stat(TT.file, &st)) return 1;
+  if (stat(file, &st)) return 1;
 
   if (flags & FLAG_a) {
     tv[0].tv_sec = st.st_atime;
@@ -73,6 +73,12 @@
       date = TT.date;
       i = strlen(date);
       if (i) {
+        // Trailing Z means UTC timezone, don't expect libc to know this.
+        if (toupper(date[i-1])=='Z') {
+          date[i-1] = 0;
+          setenv("TZ", "UTC0", 1);
+          localtime_r(&(tv->tv_sec), &tm);
+        }
         s = strptime(date, "%Y-%m-%dT%T", &tm);
         if (s && *s=='.') {
           sscanf(s, ".%d%n", &i, &len);