blob: 58da81a664fa027eb3a5398c3989e5c9bb290d96 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
Dmitry V. Levin00777042016-01-06 11:49:27 +00002 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00003 * 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. Levin0c8853c2016-01-02 13:28:43 +000028#include "tests.h"
Dmitry V. Levin00777042016-01-06 11:49:27 +000029#include <assert.h>
30#include <errno.h>
Dmitry V. Levin78e48eb2015-07-15 15:34:59 +000031#include <fcntl.h>
Dmitry V. Levin00777042016-01-06 11:49:27 +000032#include <stdint.h>
Dmitry V. Levin78e48eb2015-07-15 15:34:59 +000033#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
41static void
42print_ts(const struct timespec *ts)
43{
44 printf("{%ju, %ju}", (uintmax_t) ts->tv_sec, (uintmax_t) ts->tv_nsec);
45}
46
47int
48main(void)
49{
50 struct timeval tv;
51 struct timespec ts[2];
52
53 if (gettimeofday(&tv, NULL))
Dmitry V. Levin00777042016-01-06 11:49:27 +000054 perror_msg_and_skip("gettimeofday");
Dmitry V. Levin78e48eb2015-07-15 15:34:59 +000055
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. Levin78e48eb2015-07-15 15:34:59 +000060
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. Levin00777042016-01-06 11:49:27 +000067 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. Levin78e48eb2015-07-15 15:34:59 +000076
77 ts[0].tv_nsec = UTIME_NOW;
78 ts[1].tv_nsec = UTIME_OMIT;
Dmitry V. Levin00777042016-01-06 11:49:27 +000079 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. Levin78e48eb2015-07-15 15:34:59 +000084
Dmitry V. Levin78e48eb2015-07-15 15:34:59 +000085 puts("+++ exited with 0 +++");
Dmitry V. Levin78e48eb2015-07-15 15:34:59 +000086 return 0;
87}
88
89#else
90
Dmitry V. Levin00777042016-01-06 11:49:27 +000091SKIP_MAIN_UNDEFINED("HAVE_UTIMENSAT && AT_FDCWD && AT_SYMLINK_NOFOLLOW"
92 " && UTIME_NOW && UTIME_OMIT")
Dmitry V. Levin78e48eb2015-07-15 15:34:59 +000093
94#endif