1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include <sys/syscall.h> 5 #include <unistd.h> 6 #include <fcntl.h> 7 8 #ifndef SYS___pthread_chdir 9 # define SYS___pthread_chdir 348 10 #endif 11 12 #ifndef SYS___pthread_fchdir 13 # define SYS___pthread_fchdir 349 14 #endif 15 __pthread_chdir(const char * path)16int __pthread_chdir(const char *path) 17 { 18 return syscall(SYS___pthread_chdir, path); 19 } 20 __pthread_fchdir(int dirfd)21int __pthread_fchdir(int dirfd) 22 { 23 return syscall(SYS___pthread_fchdir, dirfd); 24 } 25 main(void)26int main(void) 27 { 28 int dirfd; 29 30 dirfd = open("/", O_RDONLY); 31 if (dirfd == -1) 32 perror("open"), exit(1); 33 34 if (__pthread_chdir("/")) 35 perror("__pthread_chdir"); 36 37 if (__pthread_fchdir(dirfd)) 38 perror("__pthread_fchdir"); 39 40 return 0; 41 } 42