Mercurial > hg > toybox
comparison toys/posix/touch.c @ 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 | 0d19abb90c52 |
children | 910a958980dc |
comparison
equal
deleted
inserted
replaced
1510:4f3a5d600803 | 1511:df792340e3f7 |
---|---|
34 // Fetch access and/or modification time of a file | 34 // Fetch access and/or modification time of a file |
35 int fetch(char *file, struct timeval *tv, unsigned flags) | 35 int fetch(char *file, struct timeval *tv, unsigned flags) |
36 { | 36 { |
37 struct stat st; | 37 struct stat st; |
38 | 38 |
39 if (stat(TT.file, &st)) return 1; | 39 if (stat(file, &st)) return 1; |
40 | 40 |
41 if (flags & FLAG_a) { | 41 if (flags & FLAG_a) { |
42 tv[0].tv_sec = st.st_atime; | 42 tv[0].tv_sec = st.st_atime; |
43 tv[0].tv_usec = st.st_atim.tv_nsec/1000; | 43 tv[0].tv_usec = st.st_atim.tv_nsec/1000; |
44 } | 44 } |
71 | 71 |
72 if (toys.optflags & FLAG_d) { | 72 if (toys.optflags & FLAG_d) { |
73 date = TT.date; | 73 date = TT.date; |
74 i = strlen(date); | 74 i = strlen(date); |
75 if (i) { | 75 if (i) { |
76 // Trailing Z means UTC timezone, don't expect libc to know this. | |
77 if (toupper(date[i-1])=='Z') { | |
78 date[i-1] = 0; | |
79 setenv("TZ", "UTC0", 1); | |
80 localtime_r(&(tv->tv_sec), &tm); | |
81 } | |
76 s = strptime(date, "%Y-%m-%dT%T", &tm); | 82 s = strptime(date, "%Y-%m-%dT%T", &tm); |
77 if (s && *s=='.') { | 83 if (s && *s=='.') { |
78 sscanf(s, ".%d%n", &i, &len); | 84 sscanf(s, ".%d%n", &i, &len); |
79 s += len; | 85 s += len; |
80 tv->tv_usec = i; | 86 tv->tv_usec = i; |