Messages in this thread | | | Date | Tue, 07 Dec 1999 18:21:53 -0500 (EST) | From | afei@jhu ... | Subject | Compilation problem |
| |
The question is a little bit off the kernel discussion, but nevertheless related:
I am working on filesystem and I need to analyze the filesystem. I wrote a C program that calls the "getdents" function. The man page says it is not a good idea to use it but that is the very function I need. The problem is now I cannot link the program with "getdents", although I can find it in libc.a with "nm". I tried "readdir 2" the system call version, but it results in SIGSEGV. What shall I do? --------code segment printf("pass 2: using linux system call getdents\n"); if( (fd = open("/home/feiliu", O_RDONLY)) <0){printf("open: abort\n"); exit(1);} /* if( getdents(fd, &dir, 1) == -1) {printf("getdents: abort\n"); exit(1);};*/ if( readdir(fd, &dir, 1) == -1) {printf("getdents: abort\n"); exit(1);}; printf("%d %d %d %s\n", dir.d_ino, dir.d_off, dir.d_reclen, dir.d_name);
-------with getdents [feiliu@map src]$ nm /usr/lib/libc.a|grep getdents getdents.o: getdents64.o: [feiliu@map src]$ gcc -L/usr/lib -g -o tdir dir.c /tmp/ccfre2LK.o: In function `main': /home/feiliu/OS418/src/dir.c:76: undefined reference to `getdents' collect2: ld returned 1 exit status
-------with readdir 2 (gdb) n 77 if( readdir(fd, &dir, 1) == -1) {printf("getdents: abort\n"); exit(1);} ; (gdb) n
Program received signal SIGSEGV, Segmentation fault. __readdir (dirp=0x6) at ../sysdeps/unix/readdir.c:43 ../sysdeps/unix/readdir.c:43: No such file or directory. (gdb) quit T
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |