[Top] [Prev] [Next]

open

open, create - open/create a file for reading or writing

Synopsis

include "sys.m";
sys:= load Sys Sys->PATH;
open:  fn(file: string, omode: int)      : ref FD;
create:fn(file: string, omode, perm: int): ref FD;

Description

open (file, omode)

The open function opens the file for I/O and returns an associated file descriptor. The omode argument is one of
Sys->OREAD

open for reading

Sys->OWRITE

open for writing

Sys->ORDWR

open for reading and writing

The following values may be OR'ed with the above values for additional actions:
Sys->OTRUNC

Truncate the file before opening it; this requires write permission even if omode is Sys->OREAD.

Sys->ORCLOSE

Remove the file on closure.

The open function returns nil if the file does not exist or the user does not have permission to open it as requested (see stat for a description of permissions).

create (file, omode, perm)

The create function creates a new file or prepares to rewrite an existing file, opens it according to omode (as described for open), and returns an associated file descriptor.

If the file is new, the owner is set to the user id of the creating process group, the group to that of the containing directory, and the permissions to perm AND'ed with the permissions of the containing directory. See The create Transaction section of open.

If the file already exists, it is truncated to 0 length, and the permissions, owner, and group remain unchanged.

The created file will be a directory if the Sys->CHDIR bit is set in omode.

The create function returns nil if the path up to the last element of file cannot be evaluated, if the user does not have write permission in the final directory, or if the file already exists and does not permit the access defined by omode.

If the file is new and the directory in which it is created is a union directory (see Limbo System Modules) then the constituent directory where the file is created depends on the structure of the union: see bind.

Caveat

There is no explicit 'close' routine; when the last reference to the file descriptor is released, the system closes the associated file.

For devices and network protocols where shutdown must be guaranteed, write a "hangup" message to the associated control file and use the return value of the write to verify closure. For example, see ip.

See Also

Limbo System Modules: bind, stat, and open



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.