Site Tools


open

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

open [2012/07/04 06:30] (current)
Line 1: Line 1:
 +# $EPIC: open.txt,v 1.5 2012/07/04 06:30:23 jnelson Exp $
 +======Synopsis:​======
 +$__open__(%%<​filename>​%% R|W)
 +
 +======Technical:​======
 +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.
 +
 +======Practical:​======
 +The $__open__() function is the doorway to external file access from
 +within the client (aside from [[exec command|EXEC]]ing 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.
 +
 +======Returns:​======
 +file descriptor, or -1 if error
 +
 +======Options:​======
 +|   ​R ​  |open file for reading ​   |
 +|   ​W ​  |open file for writing ​   |
 +
 +======Examples:​======
 +<​file>​
 +$open(~/​.ircrc W)                 open your .ircrc for writing
 +$open(~/​.irclog R)                open your logfile for reading
 +$open(/​etc/​passwd W)              will probably fail
 +</​file>​
  
open.txt ยท Last modified: 2012/07/04 06:30 (external edit)