tell()

Returns the current offset for a file.

  #include <extras/extras_io.h>
  
  long int tell(int fildes);    
Parameter

fildes

The file descriptor.

Remarks

This function returns the current offset for the file associated with the file descriptor fildes. The value is the number of bytes from the file's beginning.

If it is successful, tell() returns the offset. If it encounters an error, tell() returns -1L.

This facility is not specified in the ISO/IEC standards. It is an EWL extension of the standard libraries.

This facility may not be available on some configurations of the EWL.

Listing: Example of tell() usage

#include <stdio.h>

#include <extras/extras_io.h>

int main(void)

{

int fd;

long int pos;

char hello[] = "je me souviens";

fd = open("mytest", O_RDWR | O_CREAT | O_TRUNC);

write(fd, hello, sizeof(hello));

pos = tell(fd);

if (pos < 0)

exit(1);

printf("%ld.", pos);

close(fd);

return 0;

}

Output:

14