]> granicus.if.org Git - strace/blob - tests/getcwd.c
tests: extend TEST_NETLINK_OBJECT macro
[strace] / tests / getcwd.c
1 #include "tests.h"
2
3 #include <asm/unistd.h>
4
5 #ifdef __NR_getcwd
6
7 # include <stdio.h>
8 # include <unistd.h>
9 # include <sys/param.h>
10
11 int
12 main(void)
13 {
14         long res;
15         char cur_dir[PATH_MAX + 1];
16         static const size_t bogus_size = (size_t) 0xbadc0deddeadfaceULL;
17
18         res = syscall(__NR_getcwd, cur_dir, sizeof(cur_dir));
19
20         if (res <= 0)
21                 perror_msg_and_fail("getcwd");
22
23         printf("getcwd(");
24         print_quoted_string(cur_dir);
25         printf(", %zu) = %ld\n", sizeof(cur_dir), res);
26
27         res = syscall(__NR_getcwd, cur_dir, 0);
28         printf("getcwd(%p, 0) = %s\n", cur_dir, sprintrc(res));
29
30         res = syscall(__NR_getcwd, NULL, bogus_size);
31         printf("getcwd(NULL, %zu) = %s\n", bogus_size, sprintrc(res));
32
33         res = syscall(__NR_getcwd, (void *) -1L, sizeof(cur_dir));
34         printf("getcwd(%p, %zu) = %s\n",
35                (void *) -1L, sizeof(cur_dir), sprintrc(res));
36
37         puts("+++ exited with 0 +++");
38
39         return 0;
40 }
41
42 #else
43
44 SKIP_MAIN_UNDEFINED("__NR_getcwd");
45
46 #endif