Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Dmitry V. Levin | 0c8853c | 2016-01-02 13:28:43 +0000 | [diff] [blame] | 28 | #include "tests.h" |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 29 | #include <assert.h> |
| 30 | #include <errno.h> |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 31 | #include <fcntl.h> |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 32 | #include <stdint.h> |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 33 | #include <stdio.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/time.h> |
| 36 | |
| 37 | #if defined HAVE_UTIMENSAT \ |
| 38 | && defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW \ |
| 39 | && defined UTIME_NOW && defined UTIME_OMIT |
| 40 | |
| 41 | static void |
| 42 | print_ts(const struct timespec *ts) |
| 43 | { |
| 44 | printf("{%ju, %ju}", (uintmax_t) ts->tv_sec, (uintmax_t) ts->tv_nsec); |
| 45 | } |
| 46 | |
| 47 | int |
| 48 | main(void) |
| 49 | { |
| 50 | struct timeval tv; |
| 51 | struct timespec ts[2]; |
| 52 | |
| 53 | if (gettimeofday(&tv, NULL)) |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 54 | perror_msg_and_skip("gettimeofday"); |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 55 | |
| 56 | ts[0].tv_sec = tv.tv_sec; |
| 57 | ts[0].tv_nsec = tv.tv_usec; |
| 58 | ts[1].tv_sec = tv.tv_sec - 1; |
| 59 | ts[1].tv_nsec = tv.tv_usec + 1; |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 60 | |
| 61 | #define PREFIX "utimensat(AT_FDCWD, \"utimensat\\nfilename\", [" |
| 62 | |
| 63 | printf(PREFIX); |
| 64 | print_ts(&ts[0]); |
| 65 | printf(", "); |
| 66 | print_ts(&ts[1]); |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 67 | printf("], AT_SYMLINK_NOFOLLOW) = -1 ENOENT "); |
| 68 | |
| 69 | assert(utimensat(AT_FDCWD, "utimensat\nfilename", ts, |
| 70 | AT_SYMLINK_NOFOLLOW) == -1); |
| 71 | if (ENOENT != errno) |
| 72 | error_msg_and_skip("utimensat"); |
| 73 | printf("(%m)\n"); |
| 74 | |
| 75 | printf(PREFIX "UTIME_NOW, UTIME_OMIT], AT_SYMLINK_NOFOLLOW) = -1 ENOENT "); |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 76 | |
| 77 | ts[0].tv_nsec = UTIME_NOW; |
| 78 | ts[1].tv_nsec = UTIME_OMIT; |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 79 | assert(utimensat(AT_FDCWD, "utimensat\nfilename", ts, |
| 80 | AT_SYMLINK_NOFOLLOW) == -1); |
| 81 | if (ENOENT != errno) |
| 82 | error_msg_and_skip("utimensat"); |
| 83 | printf("(%m)\n"); |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 84 | |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 85 | puts("+++ exited with 0 +++"); |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | #else |
| 90 | |
Dmitry V. Levin | 0077704 | 2016-01-06 11:49:27 +0000 | [diff] [blame] | 91 | SKIP_MAIN_UNDEFINED("HAVE_UTIMENSAT && AT_FDCWD && AT_SYMLINK_NOFOLLOW" |
| 92 | " && UTIME_NOW && UTIME_OMIT") |
Dmitry V. Levin | 78e48eb | 2015-07-15 15:34:59 +0000 | [diff] [blame] | 93 | |
| 94 | #endif |