write . files . sncode
WRITE(1e)
NAME
write - Write in a file.
SYNOPSIS
write([permissions:integer, owner:"rwx", group:"rwx", other:"rwx"], error:variable, create:true|false,append:true|false,data="…",file="…") DESCRIPTION
This function is used to write in a files. Parameter error is used to catch error and set the variable with the error. This associative array will contains the followings variables: - Error message if any : "errmsg":"", - Filename that was executed : "filename":"/usr/local/website/v5/html/tests/test.sn", - C file where the error occured : "cfile":"files.c", - Error code : "errcode":0, - If the file was included "filefrom":"/usr/local/website/v5/html/tests/test.sn", - Line where the error occured : "line":1, - C line where the error occured : "cline":3790, - User who compile the file : "compileuid":0, - Compilation date : "date":"" If create is false and the destination does not exist an error is set. create is true by default. If append is false, the destination file is truncated if it exist. If the destination file does not exist and it is created, the permissions can be specified with the followings: 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: File and Data can be specified multiple time. ORDER OF PARAMETER IS IMPORTANT. PUT APPEND AND CREATE BEFORE FILE AND DATA!!!!
Note: In the followings examples, the _ between the { should be removed to make it work.
%include "/includes/extenso.sn";
{_{ %define FILE_SOURCE_PERMS 0x1000; // Copy source file’s 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
Note: In the followings examples, the _ between the { should be removed to make it work.
res={_{ write("toto.txt"); }}. return Data and file must be defined res={_{ write("/tmp/ex1", data:"xyz", data:"abc"); read("/tmp/ex1"); remove("/tmp/ex1");}}. return res=xyzabc. res={_{ write("/tmp/ex1", data:"xyz", append:false, data:"abc"); read("/tmp/ex1"); remove("/tmp/ex1");}}. return res=abc. res={_{ write(owner:"r",group:"",other:"","/tmp/ex1", data:"xyz"); a = stat("/tmp/ex1"); printf("%x",a.fileperms); read("/tmp/ex1"); remove("/tmp/ex1");}}. return res=400xyz. res={_{ write(owner:"r",group:"",other:"","/tmp/ex1", data:"xyz", file:"/tmp/ex2", data:"123"); read("/tmp/ex1"); read("/tmp/ex2"); remove("/tmp/ex1", "/tmp/ex2");}}. return res=xyz123. res={_{ write(data:"test",create:false,"/tmp/toto.txt"); }} return File ... does not exist
AUTHOR
Written by Pierre Laplante, <laplante@sednove.com>