1 /* Test whether /proc/{self,$PID}/path/a.out is correctly simulated. */
9 static void test_readlink(const char *cwd
, const char *label
,
15 if ((n
= readlink(path
, buf
, sizeof(buf
) - 1)) >= 0) {
17 size_t len
= strlen(cwd
);
22 if (!strncmp(buf
, cwd
, len
))
24 printf("Result of readlink(\"%s\"): %s\n", label
, p
);
30 static void test_readlinkat(const char *cwd
, const char *label
,
36 if ((n
= readlinkat(AT_FDCWD
, path
, buf
, sizeof(buf
) - 1)) >= 0) {
38 size_t len
= strlen(cwd
);
43 if (!strncmp(buf
, cwd
, len
))
45 printf("Result of readlinkat(\"%s\"): %s\n", label
, p
);
57 if (!getcwd(cwd
, sizeof(cwd
) - 1)) /* '-1' to make room for '/' */
61 snprintf(path
, sizeof(path
), "/proc/%ld/path/a.out", (long)getpid());
63 test_readlink(cwd
, "/proc/self/path/a.out", "/proc/self/path/a.out");
64 test_readlink(cwd
, "/proc/<pid>/path/a.out", path
);
66 test_readlinkat(cwd
, "/proc/self/path/a.out", "/proc/self/path/a.out");
67 test_readlinkat(cwd
, "/proc/<pid>/path/a.out", path
);