Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 1 | #ifdef HAVE_CONFIG_H |
| 2 | # include "config.h" |
| 3 | #endif |
| 4 | |
| 5 | #include <stdint.h> |
| 6 | #include <fcntl.h> |
| 7 | #include <stdio.h> |
| 8 | #include <sys/stat.h> |
| 9 | #include <sys/time.h> |
| 10 | |
| 11 | #if defined HAVE_UTIMENSAT \ |
| 12 | && defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW \ |
| 13 | && defined UTIME_NOW && defined UTIME_OMIT |
| 14 | |
| 15 | static void |
| 16 | print_ts(const struct timespec *ts) |
| 17 | { |
| 18 | printf("{%ju, %ju}", (uintmax_t) ts->tv_sec, (uintmax_t) ts->tv_nsec); |
| 19 | } |
| 20 | |
| 21 | int |
| 22 | main(void) |
| 23 | { |
| 24 | struct timeval tv; |
| 25 | struct timespec ts[2]; |
| 26 | |
| 27 | if (gettimeofday(&tv, NULL)) |
| 28 | return 77; |
| 29 | |
| 30 | ts[0].tv_sec = tv.tv_sec; |
| 31 | ts[0].tv_nsec = tv.tv_usec; |
| 32 | ts[1].tv_sec = tv.tv_sec - 1; |
| 33 | ts[1].tv_nsec = tv.tv_usec + 1; |
| 34 | if (!utimensat(AT_FDCWD, "utimensat\nfilename", ts, |
| 35 | AT_SYMLINK_NOFOLLOW)) |
| 36 | return 77; |
| 37 | |
| 38 | #define PREFIX "utimensat(AT_FDCWD, \"utimensat\\nfilename\", [" |
| 39 | |
| 40 | printf(PREFIX); |
| 41 | print_ts(&ts[0]); |
| 42 | printf(", "); |
| 43 | print_ts(&ts[1]); |
| 44 | puts("], AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)"); |
| 45 | |
| 46 | ts[0].tv_nsec = UTIME_NOW; |
| 47 | ts[1].tv_nsec = UTIME_OMIT; |
| 48 | if (!utimensat(AT_FDCWD, "utimensat\nfilename", ts, |
| 49 | AT_SYMLINK_NOFOLLOW)) |
| 50 | return 77; |
| 51 | |
| 52 | printf(PREFIX); |
| 53 | puts("UTIME_NOW, UTIME_OMIT], AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)"); |
| 54 | puts("+++ exited with 0 +++"); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | #else |
| 60 | |
| 61 | int |
| 62 | main(void) |
| 63 | { |
| 64 | return 77; |
| 65 | } |
| 66 | |
| 67 | #endif |