open . files . sncode
OPEN
NAME
open - Open a file
SYNOPSIS
open([permissions:integer, owner:"rwx", group:"rwx", other:"rwx",][read:bool,write:bool,append:true|false,create:true|false,error:variable,stdin:bool]"src filename")
append([permissions:integer, owner:"rwx", group:"rwx", other:"rwx",][read:bool,write:bool,append:true|false,create:true|false,error:variable]file:"src filename")
DESCRIPTION
This function is used to open a file for reading or writing.
The function return a file descriptor use by close, getline, getchar, seek and ungetchar.
If the argument to "append" is true and if the destination exists, then it will append to the file.
If the argument to "create" is false and if the destination file does not exist, the file won't be created.
File are open from the root of the file system.
The root of the filesystem is defined in the configuration file. See ExtensoConfig for more information.
If parameter stdin is true, than the function will open STDIN for input instead of a file. This is most usefull with the program sncode as in:
ct = open(stdin:true);
c = getline(ct);
all_line = "";
while c do
all_line .+= c;
c = getline(ct);
endw
close(ct);
email(from:"laplante@sednove.com",to:"laplante@sednove.com",subject:"Receive email",message:all_line);
The permissions of the destination file can be specified using permissions:
permissions:UREAD|UWRITE
or other permissions can be added using owner, group or other.
group:"rw" will add read and write permission to the group of the directory.
Include file "/includes/extenso.sn" contains definitions for permissions:
%include "/includes/extenso.sn"; {_{ // Definitions for function stat %define FILE_SOURCE_PERMS 0x1000; // Copy source file's permissions // Definitions for set file permissions %define USETID 0x8000; /* Set user id */ %define UREAD 0x0400; /* Read by user */ %define UWRITE 0x0200; /* Write by user */ %define UEXECUTE 0x0100; /* Execute by user */ %define GSETID 0x4000; /* Set group id */ %define GREAD 0x0040; /* Read by group */ %define GWRITE 0x0020; /* Write by group */ %define GEXECUTE 0x0010; /* Execute by group */ %define WSTICKY 0x2000; /* Sticky bit */ %define WREAD 0x0004; /* Read by others */ %define WWRITE 0x0002; /* Write by others */ %define WEXECUTE 0x0001; /* Execute by others */ %define OS_DEFAULT 0x0FFF; /* use OS's default permissions */ }}
EXAMPLES
ct = open(read:true,file:"/html/post1.html");
AUTHOR
Written by Pierre Laplante, <laplante@sednove.com>