Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / solaris / proc_aout.c
blob872426e1214014a39ee6a13b9b383984170f6329
1 /* Test whether /proc/{self,$PID}/path/a.out is correctly simulated. */
3 #include <limits.h>
4 #include <stdio.h>
5 #include <strings.h>
6 #include <unistd.h>
7 #include <sys/fcntl.h>
9 static void test_readlink(const char *cwd, const char *label,
10 const char *path)
12 char buf[PATH_MAX];
13 int n;
15 if ((n = readlink(path, buf, sizeof(buf) - 1)) >= 0) {
16 const char *p;
17 size_t len = strlen(cwd);
19 buf[n] = '\0';
21 p = buf;
22 if (!strncmp(buf, cwd, len))
23 p += len;
24 printf("Result of readlink(\"%s\"): %s\n", label, p);
26 else
27 perror("readlink");
30 static void test_readlinkat(const char *cwd, const char *label,
31 const char *path)
33 char buf[PATH_MAX];
34 int n;
36 if ((n = readlinkat(AT_FDCWD, path, buf, sizeof(buf) - 1)) >= 0) {
37 const char *p;
38 size_t len = strlen(cwd);
40 buf[n] = '\0';
42 p = buf;
43 if (!strncmp(buf, cwd, len))
44 p += len;
45 printf("Result of readlinkat(\"%s\"): %s\n", label, p);
47 else
48 perror("readlinkat");
51 int main(void)
53 char cwd[PATH_MAX];
54 char path[PATH_MAX];
56 cwd[0] = '\0';
57 if (!getcwd(cwd, sizeof(cwd) - 1)) /* '-1' to make room for '/' */
58 perror("getcwd");
59 strcat(cwd, "/");
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);
69 return 0;