tell

determine the current file position

Synopsis:

#include <unistd.h>
long int tell( int filedes );

Description:

The tell() function determines the current file position for any subsequent read() or write() operation (that is, any subsequent unbuffered file operation). The filedes value is the file descriptor returned by a successful execution of the open() function.

The returned value may be used in conjunction with the lseek() function to reset the current file position.

Returns:

When an error occurs, -1 is returned, errno contains a value that indicates the type of error that has been detected.

Otherwise, the current file position is returned in a system-dependent manner. A value of 0 indicates the start of the file.

See also:

chsize(), close(), creat(), dup(), dup2(), eof(), errno, exec... functions, fcntl(), filelength(), fileno(), fstat(), isatty(), lseek(), open(), read(), setmode(), sopen(), stat(), umask(), write()

Examples:

#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

char buffer[]
    = { "A text record to be written" };

void main()
  {
    int filedes ;
    int size_written;

    /* open a file for output          */
    /* replace existing file if it exists */
    filedes = open( "file",
        O_WRONLY | O_CREAT | O_TRUNC,
        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );

    if( filedes != -1 ) {

      /* print file position */
      printf( "%ld\n", tell( filedes ) );

      /* write the text */
      size_written = write( filedes , buffer,
                sizeof( buffer ) );

      /* print file position */
      printf( "%ld\n", tell( filedes ) );

      /* close the file */
      close( filedes );
    }
  }

produces the output:

0
28

Classification:

WATCOM

Systems:

All (except Netware, DOS/PM)