diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-13 15:13:09 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-13 15:13:09 -0400 |
commit | cdd04374ed435fc75fb9a76298ed08074e8d5ed7 (patch) | |
tree | 476a46dd0c636f6e54009f9a5d90c0a188d7d75f | |
parent | 65cf227c67e1b293d7beb0ef3ecef50ad5223be8 (diff) |
-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; |