]>
Commit | Line | Data |
---|---|---|
39236c6e A |
1 | #include <stdio.h> |
2 | #include <sys/stat.h> | |
3 | #include <unistd.h> | |
4 | #include <errno.h> | |
5 | #include <libproc.h> | |
6 | ||
7 | int main(){ | |
8 | int pipe_fds[2]; | |
9 | if (pipe(&pipe_fds[0]) < 0) { | |
10 | perror("pipe"); | |
11 | goto fail; | |
12 | } | |
13 | struct pipe_fdinfo pdinfo; | |
14 | /* from the headers | |
15 | int proc_pidfdinfo(int pid, int fd, int flavor, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
16 | */ | |
17 | int mypid = getpid(); | |
18 | int flavor = PROC_PIDFDPIPEINFO; | |
19 | int nv = proc_pidfdinfo(mypid, pipe_fds[0], flavor, (void *) &pdinfo, sizeof(pdinfo)); | |
20 | if (nv < 0) { | |
21 | perror("proc_pidinfo"); | |
22 | goto fail; | |
23 | } | |
24 | printf("handle value = %p \n", (void *)pdinfo.pipeinfo.pipe_handle); | |
25 | struct stat mystat; | |
26 | fstat(pipe_fds[0], &mystat); | |
27 | printf("ino value = %p \n", (void *)mystat.st_ino); | |
28 | ||
29 | if ( (uintptr_t)mystat.st_ino == (uintptr_t)pdinfo.pipeinfo.pipe_handle) | |
30 | goto success; | |
31 | fail: | |
32 | printf("[FAILED] fill_pipeinfo returned wrong values. (i.e. pipeinfo->pipe_handle != fstat->st_ino ) \n"); | |
33 | return -1; | |
34 | success: | |
35 | printf("[PASSED] fill_pipeinfo returned correct values. (i.e. pipeinfo->pipe_handle == fstat->st_ino ) \n"); | |
36 | return 0; | |
37 | } | |
38 |