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

FpOpen

Open file and return file descriptor

Declaration

Source position: line 0

function FpOpen(

  path: PChar;

  flags: cint;

  Mode: TMode

):cint;

function FpOpen(

  path: PChar;

  flags: cint

):cint;

function FpOpen(

  path: AnsiString;

  flags: cint

):cint;

function FpOpen(

  path: AnsiString;

  flags: cint;

  Mode: TMode

):cint;

function FpOpen(

  path: String;

  flags: cint

):cint;

function FpOpen(

  path: String;

  flags: cint;

  Mode: TMode

):cint;

Description

FpOpen opens a file in Path with flags flags and mode Mode One of the following:

O_RdOnly
File is opened Read-only
O_WrOnly
File is opened Write-only
O_RdWr
File is opened Read-Write

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

O_Creat
File is created if it doesn't exist.
O_Excl
If the file is opened with O_Creat and it already exists, the call wil fail.
O_NoCtty
If the file is a terminal device, it will NOT become the process' controlling terminal.
O_Trunc
If the file exists, it will be truncated.
O_Append
the file is opened in append mode. Before each write, the file pointer is positioned at the end of the file.
O_NonBlock
The file is opened in non-blocking mode. No operation on the file descriptor will cause the calling process to wait till.
O_NDelay
Idem as O_NonBlock
O_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.
O_NoFollow
if the file is a symbolic link, the open fails. (linux 2.1.126 and higher only)
O_Directory
if the file is not a directory, the open fails. (linux 2.1.126 and higher only)

Path 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

Extended error information can be retrieved using fpGetErrno.

See also

FpClose

  

Close file descriptor

FpRead

  

Read data from file descriptor

FpWrite

  

Write data to file descriptor

FpFTruncate

  

Truncate file on certain size.

FpLSeek

  

Set file pointer position.

Example

Program Example19;

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

Uses BaseUnix;

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

Var FD : Cint;

begin
  FD:=fpOpen ('Test.dat',O_WrOnly or O_Creat);
  if FD>0 then
    begin
    if length(Line)<>fpwrite (FD,Line[1],Length(Line)) then
      Writeln ('Error when writing to file !');
    fpClose(FD);
    end;
end.
The latest version of this document can be found at lazarus-ccr.sourceforge.net.