Pike v8.0 release 1738

Method Stdio.Fd()->open()


Method open

int open(string filename, string mode)
int open(string filename, string mode, int access)
int open(int fd, string mode)

Description

Open a file, or use an existing fd.

If filename is given, attempt to open the named file. If fd is given instead, it should be the file descriptor for an already opened file, which will then be used by this object.

mode describes how the file is opened. It's a case-insensitive string consisting of one or more of the following letters:

"r"

Open for reading.

"w"

Open for writing.

"a"

Append new data to the end.

"c"

Create the file if it doesn't exist already.

"t"

Truncate the file to zero length if it already contains data. Use only together with "w".

"x"

Open exclusively - the open fails if the file already exists. Use only together with "c". Note that it's not safe to assume that this is atomic on some systems.

access specifies the permissions to use if a new file is created. It is a UNIX style permission bitfield:

0400

User has read permission.

0200

User has write permission.

0100

User has execute permission.

0040

Group has read permission.

0020

Group has write permission.

0010

Group has execute permission.

0004

Others have read permission.

0002

Others have write permission.

0001

Others have execute permission.

It's system dependent on which of these bits that are actually heeded. If access is not specified, it defaults to 00666, but note that on UNIX systems it's masked with the process umask before use.

Returns

Returns nonzero on success and 0 (zero) on failure. If there is a failure then errno returns the error code.

See also

close()