/* Tests of fdutimensat.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <stdio.h>
#include <stdlib.h>
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "ignore-value.h"
+#include "macros.h"
#define BASE "test-fdutimensat.t"
static int
do_futimens (int fd, struct timespec const times[2])
{
- return fdutimensat (dfd, NULL, fd, times);
+ return fdutimensat (fd, dfd, NULL, times, 0);
}
/* Test the use of file descriptors alongside a name. */
do_fdutimens (char const *name, struct timespec const times[2])
{
int result;
+ int nofollow_result;
+ int nofollow_errno;
int fd = openat (dfd, name, O_WRONLY);
if (fd < 0)
fd = openat (dfd, name, O_RDONLY);
errno = 0;
- result = fdutimensat (dfd, name, fd, times);
+ nofollow_result = fdutimensat (fd, dfd, name, times, AT_SYMLINK_NOFOLLOW);
+ nofollow_errno = errno;
+ result = fdutimensat (fd, dfd, name, times, 0);
+ ASSERT (result == nofollow_result
+ || (nofollow_result == -1 && nofollow_errno == ENOSYS));
if (0 <= fd)
{
int saved_errno = errno;
return lutimensat (dfd, name, times);
}
+/* Wrap fdutimensat to behave like lutimens. */
+static int
+do_lutimens1 (const char *name, struct timespec const times[2])
+{
+ return fdutimensat (-1, dfd, name, times, AT_SYMLINK_NOFOLLOW);
+}
+
/* Wrap fdutimensat to behave like utimens. */
static int
do_utimens (const char *name, struct timespec const times[2])
{
- return fdutimensat (dfd, name, -1, times);
+ return fdutimensat (-1, dfd, name, times, 0);
}
int
-main ()
+main (void)
{
int result1; /* Skip because of no symlink support. */
int result2; /* Skip because of no futimens support. */
int fd;
/* Clean up any trash from prior testsuite runs. */
- ASSERT (system ("rm -rf " BASE "*") == 0);
+ ignore_value (system ("rm -rf " BASE "*"));
/* Basic tests. */
result1 = test_utimens (do_utimens, true);
result3 = test_lutimens (do_lutimens, (result1 + result2) == 0);
/* We expect 0/0, 0/77, or 77/77, but not 77/0. */
ASSERT (result1 <= result3);
+ ASSERT (test_lutimens (do_lutimens1, (result1 + result2) == 0) == result3);
dfd = open (".", O_RDONLY);
ASSERT (0 <= dfd);
ASSERT (test_utimens (do_utimens, false) == result1);
ASSERT (test_utimens (do_fdutimens, false) == result1);
ASSERT (test_futimens (do_futimens, false) == result2);
ASSERT (test_lutimens (do_lutimens, false) == result3);
+ ASSERT (test_lutimens (do_lutimens1, false) == result3);
/* Directory relative tests. */
ASSERT (mkdir (BASE "dir", 0700) == 0);
fd = creat ("file", 0600);
ASSERT (0 <= fd);
errno = 0;
- ASSERT (fdutimensat (fd, ".", AT_FDCWD, NULL) == -1);
+ ASSERT (fdutimensat (AT_FDCWD, fd, ".", NULL, 0) == -1);
ASSERT (errno == ENOTDIR);
{
struct timespec ts[2] = { { Y2K, 0 }, { Y2K, 0 } };
struct stat st;
- ASSERT (fdutimensat (dfd, BASE "dir/file", fd, ts) == 0);
+ ASSERT (fdutimensat (fd, dfd, BASE "dir/file", ts, 0) == 0);
ASSERT (stat ("file", &st) == 0);
ASSERT (st.st_atime == Y2K);
ASSERT (get_stat_atime_ns (&st) == 0);
ASSERT (close (fd) == 0);
ASSERT (close (dfd) == 0);
errno = 0;
- ASSERT (fdutimensat (dfd, ".", -1, NULL) == -1);
+ ASSERT (fdutimensat (-1, dfd, ".", NULL, 0) == -1);
ASSERT (errno == EBADF);
/* Cleanup. */