User Tools

Site Tools


# $EPIC: open.txt,v 1.5 2012/07/04 06:30:23 jnelson Exp $


$open(<filename> R|W)


Important: The <filename> can be surrounded by double quotes, which is different from most functions. You can use tilde-expansion for homedirs.

This opens a file for reading from the beginning, or writing to the end.

The return value is a file descriptor you can pass to read or write and eventually close.

This functions allows the client to open an arbitrary file for reading or writing. Write mode appends to the file. The function returns a file descriptor for the open file; the file descriptor is an integer. Tilde- expansion is permitted.


The $open() function is the doorway to external file access from within the client (aside from EXECing a process). Assuming the file has the appropriate permissions, it allows you to open the file for read or write access (but not both). Write access only appends to the file, so you'll need to use $unlink() or $rename() if you want to start fresh.


file descriptor, or -1 if error


R open file for reading
W open file for writing


$open(~/.ircrc W)                 open your .ircrc for writing
$open(~/.irclog R)                open your logfile for reading
$open(/etc/passwd W)              will probably fail
open.txt · Last modified: 2012/07/04 06:30 (external edit)