# HG changeset patch # User Rob Landley # Date 1410996250 18000 # Node ID 0d19abb90c5206b6a30bf3425178e10fdc1137d4 # Parent 91767d247a501b64bd843f853792b6a021518e51 Minor cleanup pass on touch. diff -r 91767d247a50 -r 0d19abb90c52 toys/posix/touch.c --- a/toys/posix/touch.c Wed Sep 17 08:26:07 2014 -0500 +++ b/toys/posix/touch.c Wed Sep 17 18:24:10 2014 -0500 @@ -53,30 +53,26 @@ void touch_main(void) { struct timeval tv[2]; - struct tm tm; - char **ss, *date, *s; - int flag, fd, i, len; + char **ss; + int flag, fd, i; // Set time from clock? gettimeofday(tv, NULL); - localtime_r(&(tv->tv_sec), &tm); - - // Set time from -d? if (toys.optflags & (FLAG_t|FLAG_d)) { + char *s, *date; + struct tm tm; + int len; + + localtime_r(&(tv->tv_sec), &tm); + + // Set time from -d? + if (toys.optflags & FLAG_d) { date = TT.date; i = strlen(date); - if (i && i < sizeof(toybuf)) { - // Trailing Z means UTC timezone, don't expect libc to know this. - if (toupper(date[i])=='Z') { - putenv("TZ=UTC"); - strcpy(toybuf, date); - toybuf[i] = 0; - date = toybuf; - gmtime_r(&(tv->tv_sec), &tm); - } + if (i) { s = strptime(date, "%Y-%m-%dT%T", &tm); if (s && *s=='.') { sscanf(s, ".%d%n", &i, &len); @@ -105,10 +101,7 @@ errno = 0; tv->tv_sec = mktime(&tm); - if (!s || *s || errno == EOVERFLOW) { - // Warn Indiana Jones the monkey died. - perror_exit("bad '%s'", date); - } + if (!s || *s || errno == EOVERFLOW) perror_exit("bad '%s'", date); } tv[1]=tv[0];