Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / memcheck / tests / freebsd / utimens.c
blob602a5aec535a1e72b997b6a5d56d27d8a19195d0
1 /*
2 * Tests for the utimens functions
4 * futimens
5 * utimensat
6 */
8 #include <sys/stat.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <dirent.h>
14 #include <fcntl.h>
16 int main(void)
18 char tmpfile1[] = "/tmp/testutimens1.XXXXXX";
19 char tmpfile2[] = "/tmp/testutimens2.XXXXXX";
20 int tmpfd1 = mkstemp(tmpfile1);
21 int tmpfd2 = mkstemp(tmpfile2);
22 close(tmpfd1);
23 close(tmpfd2);
24 struct timespec times[2];
25 times[0].tv_sec = 30;
26 times[0].tv_nsec = 271828;
27 times[1].tv_sec = 42;
28 times[1].tv_nsec = 314159;
30 if (-1 == futimens(tmpfd1, times))
32 perror("futimens failed:");
35 DIR* tmpdir = opendir("/tmp");
36 if (tmpdir) {
37 int tmpdirfd = dirfd(tmpdir);
38 if (-1 == utimensat(tmpdirfd, tmpfile2+5, times, AT_SYMLINK_NOFOLLOW))
40 perror("utimensat failed:");
43 close(tmpdirfd);
46 // some errors
47 struct timespec badtimes[2];
48 int badfd;
49 char* badname = strdup("foo");
50 free(badname);
51 futimens(badfd, badtimes);
52 utimensat(badfd, badname, badtimes, badfd);
54 unlink(tmpfile1);
55 unlink(tmpfile2);