diff options
-rw-r--r-- | touch.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -163,7 +163,7 @@ static int getnext(const char *current, char **next, size_t ndigits, char *term, return ret; } -static struct timespec convert_date(const char *date) +static struct timespec convert_date(char *date) { struct timespec ts = { 0 }; struct tm tm = { 0 }; @@ -176,7 +176,13 @@ static struct timespec convert_date(const char *date) tm.tm_min = getnext(next, &next, 2, ":", 0, 59); tm.tm_sec = getnext(next, &next, 2, ".,", 0, 60); - /* TODO: frac */ + char *dec = strchr(date, '.') ? strchr(date, '.') : strchr(date, ','); + if (dec) { + *dec = '.'; + double d = strtod(dec, &next); + ts.tv_nsec = d * 1000000000; + } + /* TODO: tz */ /* TODO: time is too large */ @@ -240,6 +246,11 @@ int main(int argc, char *argv[]) } } + if (optind >= argc) { + fprintf(stderr, "touch: missing operands\n"); + return 1; + } + struct timespec times[2] = { { 0 } }; struct stat st; |