diff options
-rw-r--r-- | utils/time-sync/time-sync.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/utils/time-sync/time-sync.c b/utils/time-sync/time-sync.c index ebb46ed2fc..ed4ef3ce42 100644 --- a/utils/time-sync/time-sync.c +++ b/utils/time-sync/time-sync.c | |||
@@ -16,6 +16,7 @@ | |||
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #define _XOPEN_SOURCE /* to enable strptime() */ | ||
19 | #include <stdlib.h> | 20 | #include <stdlib.h> |
20 | #include <stdio.h> | 21 | #include <stdio.h> |
21 | #include <time.h> | 22 | #include <time.h> |
@@ -27,14 +28,27 @@ int | |||
27 | main (int argc, char **argv) | 28 | main (int argc, char **argv) |
28 | { | 29 | { |
29 | if (argc < 2) { | 30 | if (argc < 2) { |
30 | printf ("usage: %s <device>\n", basename(argv[0])); | 31 | printf ("usage: %s <device> [time]\n", basename(argv[0])); |
31 | return 1; | 32 | return 1; |
32 | } | 33 | } |
33 | 34 | ||
34 | if (sync_time (argv[1], NULL)) { | 35 | struct tm time; |
35 | printf ("Error occured while syncing time.\n"); | 36 | struct tm* ptime = NULL; |
37 | if (argc > 2) { | ||
38 | if(strptime(argv[2], "%Y-%m-%dT%H:%M:%S", &time)) { | ||
39 | ptime = &time; | ||
40 | } | ||
41 | else { | ||
42 | printf ("Could not parse time. Using local time.\n"); | ||
43 | printf ("Time string needs to use the format YYYY-MM-DDThh:mm:ss\n"); | ||
44 | printf ("(ISO 8601 format)\n"); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | if (sync_time (argv[1], ptime)) { | ||
49 | printf ("Error occured while syncing time.\n"); | ||
36 | } else { | 50 | } else { |
37 | printf ("Time was synced!\n"); | 51 | printf ("Time was synced!\n"); |
38 | } | 52 | } |
39 | 53 | ||
40 | return 0; | 54 | return 0; |