[Overview][Constants][Types][Procedures and functions][Variables][Index] | Reference for unit 'oldlinux' (#rtl)

# fdOpen

Open file and return file descriptor

## Declaration

Source position: line 0

`function fdOpen(`
`pathname: string;`
`flags: LongInt`
`):LongInt; function fdOpen(`
`pathname: string;`
`flags: LongInt;`
`mode: LongInt`
`):LongInt; function fdOpen(`
`pathname: pchar;`
`flags: LongInt`
`):LongInt; function fdOpen(`
`pathname: pchar;`
`flags: LongInt;`
`mode: LongInt`
`):LongInt;`

## Description

fdOpen opens a file in PathName with flags flags One of the following:

Open_RdOnly
  File is opened Read-only
Open_WrOnly
  File is opened Write-only
Open_RdWr
  File is opened Read-Write

The flags may beOR-ed with one of the following constants:

Open_Creat
  File is created if it doesn't exist.
Open_Excl
  If the file is opened with Open_Creat and it already exists, the call wil fail.
Open_NoCtty
  If the file is a terminal device, it will NOT become the process' controlling terminal.
Open_Trunc
  If the file exists, it will be truncated.
Open_Append
  the file is opened in append mode. Before each write, the file pointer is positioned at the end of the file.
Open_NonBlock
  The file is opened in non-blocking mode. No operation on the file descriptor will cause the calling process to wait till.
Open_NDelay
  Idem as Open_NonBlock
Open_Sync
  The file is opened for synchronous IO. Any write operation on the file will not return untill the data is physically written to disk.
Open_NoFollow
  if the file is a symbolic link, the open fails. (linux 2.1.126 and higher only)
Open_Directory
  if the file is not a directory, the open fails. (linux 2.1.126 and higher only)

PathName can be of type PChar or String. The optional mode argument specifies the permissions to set when opening the file. This is modified by the umask setting. The real permissions are Mode and not umask. The return value of the function is the filedescriptor, or a negative value if there was an error.

## Errors

Errors are returned in LinuxError.

## See also

fdClose |  | Close file descriptor
fdRead |  | Read data from file descriptor
fdWrite |  | Write data to file descriptor
fdTruncate |  | Truncate file on certain size.
fdFlush |  | Flush kernel file buffer
fdSeek |  | Set file pointer position.

## Example

    Program Example19;

    { Program to demonstrate the fdOpen, fdwrite and fdCLose functions. }

    Uses oldlinux;

    Const Line : String[80] = 'This is easy writing !';

    Var FD : Longint;

    begin
      FD:=fdOpen ('Test.dat',Open_WrOnly or Open_Creat);
      if FD>0 then
        begin
        if length(Line)<>fdwrite (FD,Line[1],Length(Line)) then
          Writeln ('Error when writing to file !');
        fdClose(FD);
        end;
    end.

Documentation generated on: Feb 26 2014