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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -