c++ - unable to `open` the file , but `lseek` is done without error -
i working on unix system calls. here in code want open file , perform lseek operation on file. please following code.
#include <stdio.h> #include <fcntl.h> #include <sys/types.h> #include <unistd.h> int main(void) { int fd; fd = open("testfile.txt", o_rdonly); if(fd < 0 ); printf("problem in openning file \n"); if(lseek(fd,0,seek_cur) == -1) printf("cant seek\n"); else printf("seek ok\n"); exit(0); } my output :
problem in openning file seek ok my question :
1) why open system call giving me negative file descriptor ? (i have conformed testfile.txt file within same directory)
2) here unable open file(as because open() returns me negative file descriptor) , how lseek successful without opening file?
in fact, open file successfully.
just if(fd < 0 ); wrong, need remove ;
Comments
Post a Comment