8.2.14 File types

File types are represented as records. Typed files and untyped files are represented as a fixed record:

  PrivDataLength=3*SizeOf(SizeInt) + 5*SizeOf(pointer);  
  filerec = packed record  
    handle   : THandle;  
    mode     : longint;  
    recsize  : Sizeint;  
    _private : array[1..PrivDataLength] of byte;  
    userdata : array[1..32] of byte;  
    name     : array[0..filerecnamelength] of char;  

Text files are described using the following record:

  TextBuf = array[0..255] of char;  
  textrec = packed record  
    handle    : THandle;  
    mode      : longint;  
    bufsize   : SizeInt;  
    _private  : SizeInt;  
    bufpos    : SizeInt;  
    bufend    : SizeInt;  
    bufptr    : ^textbuf;  
    openfunc  : pointer;  
    inoutfunc : pointer;  
    flushfunc : pointer;  
    closefunc : pointer;  
    userdata  : array[1..32] of byte;  
    name      : array[0..255] of char;  
    LineEnd   : TLineEndStr;  
    buffer    : textbuf;  

The handle field returns the file handle (if the file is opened), as returned by the operating system.
The mode field can take one of several values. When it is fmclosed, then the file is closed, and the handle field is invalid. When the value is equal to fminput, it indicates that the file is opened for read only access. fmoutput indicates write only access, and the fminout indicates read-write access to the file.
The name field is a null terminated character string representing the name of the file.
The userdata field is never used by Free Pascal file handling routines, and can be used for special purposes by software developers.