[Top]
Stdio
Stdio.File
|
Method Stdio.File()->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()
- Method
open
int open(string filename, string mode)
int open(string filename, string mode, int mask)
- Description
Open a file for read, write or append. The parameter mode should
contain one or more of the following letters:
"r" | Open file for reading.
|
"w" | Open file for writing.
|
"a" | Open file for append (use with "w" ).
|
"t" | Truncate file at open (use with "w" ).
|
"c" | Create file if it doesn't exist (use with "w" ).
|
"x" | Fail if file already exists (use with "c" ).
|
|
mode should always contain at least one of the letters
"r" or "w" .
The parameter mask is protection bits to use if the file is
created. Default is 0666 (read+write for all in octal
notation).
- Returns
This function returns 1 for success, 0 otherwise.
- See also
close() , create()
|