standard.C.io.ftell

ftell is available since version 1.0.

Prototype:

number ftell(number fd)

Parameters

fd
[in] A valid file descriptor

Description:

The ftell function gets the current position of the file pointer (if any) associated with the file descriptor. The position is expressed as an offset relative to the beginning of the stream.
The value returned by ftell may not reflect the physical byte offset for streams opened in text mode, because text mode causes carriage return-linefeed translation. Use ftell with fseek to return to file locations correctly.

Note that when a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. For example, if a file is opened for an append and the last operation was a read, the file position is the point where the next read operation would start, not where the next write would start. (When a file is opened for appending, the file position is moved to end of file before any write operation.) If no I/O operation has yet occurred on a file opened for appending, the file position is the beginning of the file.

In text mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing, fopen and all related routines check for a CTRL+Z at the end of the file and remove it if possible. This is done because using ftell and fseek to move within a file that ends with a CTRL+Z may cause ftell to behave improperly near the end of the file.

Return value:

The value returned by ftell may not reflect the physical byte offset for streams opened in text mode, because text mode causes carriage return-linefeed translation.

Example
import standard.C.io
import standard.C.string

define FILENAME     "test.txt"

class Main {
     function Main() {
          var fd; 
          var position;
          var buffer = "";          

          // Open file for read 
          if (fd = fopen(FILENAME, "r")) {               
               // Move the pointer by reading data               
               fread(buffer, 1, 50, fd);
               // Get position after read: 
               position = ftell(fd);
               echo "Position after trying to read 50 bytes: $position";
               fclose(fd);               
          } else
               echo "Problem opening the file\n";
          
     }
}  

Results 
Position after trying to read 50 bytes: 50