how to seek to the end of file to determine the file size?

Abhilash Muthuraj picture Abhilash Muthuraj · Oct 13, 2011 · Viewed 26k times · Source

I'm trying to get file size in c programming using seek. I can't use fseek, stat.size nor ftell, there's a custom operating system UNIX in which I need to run.

How can I find out filesize just by using seek? Is it possible?

  FILE *fd = open(argv[1], "r");

  if(fd == NULL)
  {
    printf("Not able to open the file : %s\n", argv[1]);
    return;
  }

  // Set the pointer to the end
  seek(fd, 0, SEEK_END);

Answer

Nordic Mainframe picture Nordic Mainframe · Oct 13, 2011

seek? You mean lseek probably. Have a look at the manual page. What does lseek return?