File Primitives | |
Macros | |
access | Test file accessibility. |
basename | Return the last component of a pathname. |
chdir | Change directory. |
chmod | Change mode. |
chown | Change owner. |
compare_files | Binary file compare. |
copy_ea_info | Copy file extended information. |
del | Delete a file. |
dirname | Report the parent directory name of a file pathname. |
edit_file | Edit a file. |
edit_file2 | Extended file edit. |
exist | Check file existence. |
expandpath | Expand the path. |
fclose | Close a stream. |
feof | Test end-of-file indicator on a stream. |
ferror | Test error indicator on a stream. |
fflush | Flush a stream. |
file_canon | Canonicalize a path. |
file_match | File match utility. |
file_pattern | Directory file pattern. |
filename_match | Perform file pattern matching. |
filename_realpath | Return a resolved pathname. |
find_file | Read next directory entry. |
find_file2 | Extended read next directory entry. |
find_macro | Determine path of a macro object. |
fioctl | File miscellaneous control. |
flock | File lock operations. |
fmktemp | Make a unique filename. |
fopen | Open a stream. |
fread | Read from a stream. |
fseek | Reposition a file-position indicator in a stream. |
fstat | Stream status information. |
ftell | Report the file-position indicator of a stream. |
ftest | Test file type. |
ftruncate | Truncate the specified file. |
fwrite | Write to a stream. |
glob | Generate pathnames matching a pattern. |
inq_buffer | Retrieve a buffer identifier. |
inq_file_magic | Retrieve the file type detection rules. |
inq_home | Retrieve the user home directory. |
inq_tmpdir | Get the temporary-file directory. |
inq_vfs_mounts | Retrieve list of mounts. |
link | Link a file. |
lstat | Get symbolic link status. |
mkdir | Create a directory. |
mktemp | Make a temporary filename. |
output_file | Change the output file-name. |
read_ea | Read file extended information. |
read_file | Read into the current buffer. |
readlink | Read the contents of a symbolic link. |
realpath | Resolve a pathname. |
remove | Remove a file. |
rename | Rename a file. |
rmdir | Remove directory. |
searchpath | Searches for a given file in a specified path. |
set_binary_size | Set binary chunk size. |
set_ea | Set file extended information. |
set_file_magic | Define the file type detection rules. |
splitpath | Searches for a given file in a specified path. |
stat | Obtain file information. |
symlink | Create a symbolic link. |
umask | Set and get the file mode creation mask. |
unlink | Unlink a file. |
vfs_mount | Mount a virtual file-system. |
vfs_unmount | Unmount a virtual file-system. |
File Modes | Traditional Unix file mode consist of a number of components including type, permissions including special bits. |
int access( string path, int mode )
Test file accessibility.
The access() primitive is used to check the accessibility of a file. The file parameter is the name of a directory or file which is to be tested and mode are a set of access bits which are used to check the effective access.
When the value of mode is zero, only the existence of the file is verified. The meaning of mode is operating system dependent yet most operating systems support the following definitions:
F_OK | Check if file exists (0). |
X_OK | Check to see if file is executable (1). |
W_OK | Check if file is writable (2). |
R_OK | Check if file is readable (3). |
On successful return this primitive returns >= 0; -1 is returned on an error, and the global variable errno is set to the reason for the failure.
A GriefEdit extension.
int basename( string pathname, [string suffix] )
Return the last component of a pathname.
The basename() primitive returns a string containing the final component of a pathname contained in the string path argument, deleting trailing path separators.
To accomplish this, basename first checks to see if name consists of nothing. but slash (/) or backslash (\) characters. If so, basename replaces name with a single slash and the process is complete. If not, basename removes any trailing slashes. If slashes still remain, basename strips off all leading characters up to and including the final slash.
If you specify suffix and the remaining portion of name contains a suffix which matches suffix, basename removes that suffix.
The basename() primitive returns a string containing the final component of the specified pathname after processing following the above rules.
int chdir( string path )
Change directory.
The chdir() primitive changes the current directory on the specified drive to the specified path.
Unlike cd no shell expansion shall occur.
The chdir() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
A GriefEdit extension.
int chmod( string path, int mode )
Change mode.
The chmod() primitive changes the permissions for a file specified by path to be the settings in the mode given by permission.
The access permissions for the file or directory are specified as a combination of bits which are operating system specific.
The chmod() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
int chown( string path, int owner, int group )
Change owner.
The chown() primitive is reserved for future use.
The chown() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
int compare_files( [int flags], string file1, string file2 )
Binary file compare.
The compare_files performs simple comparison byte-for-byte of the on disk images of the two file file1 and file2.
The flags are intended for future options, supporting simple line processing.
It can be used to quickly determine if two files are identical (byte for byte). Note that if either file is an active buffer, no unsaved changes shall be included.
In contrast, the <diff_buffers> primitive is used to compare files and mark up the differences.
Returns 1 if the files are identical, 0 if they differ. -1 if the first file cannot be read, -2 if the second file cannot be read.
A GriefEdit extension.
<diff_buffers>
int del( string name )
Delete a file.
The del() primitive deletes the specified file name.
This function is provided for compatibility using the remove interface; see the remove primitive and the brief macro module for details.
name | String containing the file to be removed. |
remove, delete_buffer
int dirname( string path )
Report the parent directory name of a file pathname.
The dirname() primitive shall take a string path that contains a pathname, and return a string containing that is a pathname of the parent directory of that file. Trailing directory separators (/ and \) characters in the path are not counted as part of the path.
If path does not contain a directory separator (/ and \) or is an empty string, then dirname shall return a string “.”.
The dirname() primitive returns string containing the parent directory name of a file pathname, otherwise a string containing “.”.
A GriefEdit extension.
int edit_file( ... )
Edit a file.
The edit_file() primitive creates a new buffer, loads the contents, attaches the buffer to the current window and executes any registered macros, see register_macro.
The argument specification is a set of one or more strings with optional leading integer modes. Modes control the flags under which the subsequent files are processed.
If the specified file is already within another buffer, that buffer becomes the current buffer and is attached to the current window.
If more than one argument is specified; either directly or as the result of file expansion; then a separate edit action is performed on each file, with the current buffer being the last processed file.
The edit_file() primitive performs file name globbing in a fashion similar to the csh shell. It returns a list of the files whose names match any of the pattern arguments.
The pattern arguments may contain any of the following special characters:
~[user/] | Home directory of either the current or the specified user. |
? | Matches any single character. |
* | Matches any sequence of zero or more characters. |
[ch] | Matches any single character in chars. If ch’s contains a sequence of the form a-b then any character between a and b (inclusive) will match. |
\x | Matches the character x. |
When multiple files are matched, note that the return value represents only the last file processed.
During file loading GRIEF performs a number of tests against the sections of the file content in an attempt to determine the file encoding. These operations are generally invisible to end user and behave on most file types without interaction.
The current default scanners include, see set_file_magic for additional details on each.
mark | Encoding: < marker > |
utf32bom | UTF-32 BOM marker. |
utf16bom | UTF-16 BOM marker. |
udet | Mozilla Universal Character Detector. |
magic | File magic. |
binary | Possible binary image. |
ascii | ASCII only (7-bit). |
latin1 | Latin-1 (ISO-8859-x) data. |
big5 | Chinese Big5. |
gb18030 | Chinese GB-18030. |
shiftjis | Shift-JIS. |
xascii | Extended ASCII. |
... | Argument specification is a set of one or more strings with optional leading integer modes. Modes control the flags under which the subsequent files are processed, see examples. Unless specified files are loaded using EDIT_NORMAL. If no arguments are specified, the user shall be prompted for a file specification. |
Constant |
Description |
---|---|
EDIT_NORMAL |
Default mode; auto-guess the file type. |
EDIT_BINARY |
Force file to be read in binary mode, see set_binary_size. |
EDIT_ASCII |
Force file to be read in ASCII mode. |
EDIT_STRIP_CR |
Force CR removal on input and write them on output. |
EDIT_STRIP_CTRLZ |
Force Ctrl-Z removal. |
EDIT_SYSTEM |
System buffer. |
EDIT_RC |
Enable extended return codes. |
EDIT_QUICK |
Quick detection, removes more costly character-encoding methods. |
EDIT_AGAIN |
<edit_again> implementation. |
EDIT_LOCAL |
Edit locally, do not rely on the disk being stable. |
EDIT_READONLY |
Set as read-only. |
EDIT_LOCK |
Lock on read (strict-locking). |
EDIT_NOLOCK |
Disable auto-locking. |
EDIT_PREVIEW |
Limit the load to the window size. |
The edit_file() primitive returns a positive value on success, 0 if the user was prompted and cancelled, otherwise -1 on error.
If more than one argument is specified; either directly or as the result of file expansion; the return relates to the last loaded file.
Under EDIT_RC the return code is extended to differentiation between success conditions as follows.
Value |
Desciption |
---|---|
-1 |
Error. |
0 |
Cancelled. |
1 |
Successfully loaded buffer. |
2 |
New image, file created. |
3 |
Pre-existing buffer, not reloaded. |
Expand and load all .cpp files located within the current working directory.
edit_file(".cpp");
Loads a system buffer with the content from config.ini sourced from the users home directory.
edit_file(EDIT_SYSTEM, "~/config.ini");
The feature set exposed differs from implementations. It is therefore advised that the symbolic constants are using within a #ifdef construct.
edit_file2, read_file, attach_buffer, call_registered_macro, create_buffer, set_buffer, set_file_magic
int edit_file2( [int &files], [string encoding], [int mode], string|list file )
Extended file edit.
The edit_file2() primitive extends the functionality provided by edit_file with the leading parameter of encoding.
files | Optional integer variable when supplied shall be populated with the number of files loaded. |
encoding | String containing the character encoding of the source file. |
... | See edit_file |
The edit_file2() primitive returns a positive value on success, 0 if the user was prompted and cancelled, otherwise -1 on error.
See edit_file for additional return information.
A GriefEdit extension.
edit_file, read_file, attach_buffer, call_registered_macro, create_buffer, set_buffer, set_file_magic
int exist( string path, [int canon = TRUE] )
Check file existence.
The exist() primitive tests whether of the specified file path exists.
If canon is not specified, then the filename is canonised first. This involves expanding any tilde prefixes and converting DOS style filenames to Unix style ones.
The exist() primitive returns non-zero if the file exists, otherwise 0 on error. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
string expandpath( string path, [int env] )
Expand the path.
The expandpath() primitive expands any shell style home directory ~[user] references/short-hands contained within the specified path, returning the result.
The supported shell constructs are.
~/ | is expanded to your current home directory. |
~user/ | is expanded to the specified users home directory (unix only). |
If env is specified and is non-zero, then the any embedded environment variable references are also expanded following the following syntax. When a macro is not defined it expands to \”\” (an empty string), and {} are synonyms for ().
$(name) | Expands to value of name. |
${name} | Expands to value of name. |
$name/ | Expands to value of name. |
The expandpath() primitive returns a string containing the expanded path following the above rules, otherwise an empty string.
A GriefEdit extension.
int fclose( int handle )
Close a stream.
The fclose() primitive shall cause the stream pointed to by stream to be flushed and the associated file to be closed. Any unwritten buffered data for the stream shall be written to the file; any unread buffered data shall be discarded.
On successful completion, fclose() shall return 0; otherwise, it shall return -1 and set errno to indicate the error.
A GriefEdit extension.
int feof( int handle )
Test end-of-file indicator on a stream.
The feof() primitive shall test the end-of-file indicator for the stream pointed to by stream.
The feof() primitive returns non-zero if and only if the end-of-file indicator is set for stream.
A GriefEdit extension.
The feof() primitive is reserved for future use, and currently returns -1 in all cases.
int ferror( int handle, [int clearerr] )
Test error indicator on a stream.
The ferror() primitive shall test the error indicator for the stream referenced by handle.
The ferror() primitive shall return non-zero if and only if the error indicator is set for stream.
A GriefEdit extension.
The ferror() primitive is reserved for future use, and currently returns -1 in all cases.
int fflush( int handle, [int sync] )
Flush a stream.
The fflush() primitive is reserved for future use.
The fflush function returns non-zero if a write error occurs and zero otherwise. When an error has occurred, errno contains a value indicating the type of error that has been detected
An experimental GriefEdit extension; functionality may change.
The fflush() primitive is reserved for future use, and currently returns -1 in all cases.
string file_canon( string filepath )
Canonicalize a path.
The file_canon() primitive performs canonicalizes the specified path filepath and returns a new path.
The file_canon() primitive returns the canonicalized file path.
A GriefEdit extension.
int file_match( pattern, file, [flags] )
File match utility.
The file_match() primitive performs wild-card name matching, which has two major uses. It could be used by an application or utility that needs to read a directory and apply a pattern against each entry.
The find_file() primitive is an example of this. It can also be used by the ts macro to process its pattern operands, or by applications that need to match strings in a similar manner.
The file_match() primitive is intended to imply filename match, rather than pathname match. The default action of this primitive is to match filenames, rather than path names, since it gives no special significance to the slash character.
pattern can be a list of search expressions or a string containing a single expression. file is the file-name that shall be tested.
If supplied, flags allows control over how directory delimiters slash(/) and dots (.) are matched within file-name. Otherwise it defaults to setting the MATCH_PERIODA and MATCH_NOCASE based on the current operating environment similar to ones used during edit_file() pattern matching.
The following patterns matching a single character match a single character: ordinary characters, special pattern characters and pattern bracket expressions. The pattern bracket expression will also match a single collating element.
An ordinary character is a pattern that matches itself. It can be any character in the supported character set except for NUL, those special shell characters that require quoting, and the following three special pattern characters.
When unquoted and outside a bracket expression, the following three characters will have special meaning in the specification of patterns:
? | A question-mark is a pattern that will match any character. |
* | An asterisk is a pattern that will match multiple characters, as described in Patterns Matching Multiple Characters, see below. |
[ | The open bracket will introduce a pattern bracket expression, see below. |
The following rules are used to construct patterns matching multiple characters from patterns matching a single character:
[ introduces a pattern bracket expression, that will matches a single collating element contained in the non-empty set of collating elements. The following rules apply:
Within bracket expressions, the name of a character class enclosed in [: and :] stands for the list of all characters belonging to that class.
Standard (POSIX style) character classes are;
alnum | An alphanumeric (letter or digit). |
alpha | A letter. |
blank | A space or tab character. |
cntrl | A control character. |
csym | An alphanumeric (letter or digit) or or underscore character. |
digit | A decimal digit. |
graph | A character with a visible representation. |
lower | A lower-case letter. |
An alphanumeric (same as alnum). | |
punct | A punctuation character. |
space | A character producing white space in displayed text, space or a tab. |
upper | An upper-case letter. |
xdigit | A hexadecimal digit. |
If supplied the flags argument shall modify the interpretation of pattern and string. It is the bitwise-inclusive OR of zero or more of the flags defined in grief.h.
MATCH_PATHNAME - If the MATCH_PATHNAME flag is set in flags, then a slash character (‘/’) in string shall be explicitly matched by a slash in pattern; it shall not be matched by either the asterisk (*) or question-mark (?) special characters, nor by a bracket expression ([]). If the MATCH_PATHNAME flag is not set, the slash character shall be treated as an ordinary character.
MATCH_NOCASE - If the MATCH_NOCASE flag is set in flags, then the pattern is treated non-case sensitively, i.e. A matches a. Otherwise the search is performed with case being sensitive.
MATCH_NOESCAPE - If MATCH_NOESCAPE is not set in flags, a backslash character (\\) in pattern followed by any other character shall match that second character in string. In particular, “\\” shall match a backslash in string. If MATCH_NOESCAPE is set, a backslash character shall be treated as an ordinary character.
MATCH_PERIOD - If MATCH_PERIOD is set, a leading period in string will match a period in pattern; where the location of “leading” is indicated by the value of MATCH_PATHNAME as follows:
If not set, no special restrictions are placed on matching a period.
MATCH_PERIODA, MATCH_PERIODQ and MATCH_PERIODB - If set these allow selective control whether the asterisk (*) or question mark (?) special characters, nor by a bracket ([]) expression have affect.
a[bc]
matches the strings ab and ac.
a*d
matches the strings ad, abd and abcd, but not the string abc.
a*d*
matches the strings ad, abcd, abcdef, aaaad and adddd.
*a*d
matches the strings ad, abcd, efabcd, aaaad and adddd.
file_match() does not perform tilde expansion (See: expandpath).
The file_match() primitive returns 1 if file matches the specified pattern; returns 0 if pattern isnt matched. If pattern is a list, then the index into the list that matched the expression or -1.
A GriefEdit extension.
int file_pattern( string filespec )
Directory file pattern.
The file_pattern() primitive sets the search pattern for files, using find_file, and reset the internal status to the first matching file.
filespec | String containing the file pattern specification which should evaluate to a file name or a wild-card filename, see the file_match for details regarding the supported wildcard. |
The file_pattern() primitive returns 0 on success, otherwise -1 on error. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
This interface enforces the rule (MATCH_PERIODA) that a leading “” wont match any files which begin with a “.” as such use “?” to match all files contained within a directory. See file_match for details on the filespec syntax.
int filename_match( string file, declare pattern )
Perform file pattern matching.
The filename_match() primitive is similar to the file_match() primitive but is provided for CRiSP ™ compatibility. It is used to compare a filename to see if it matches a filename regular expression.
A filename expression is a regular expression similar to that accepted by the command line shells on Unix systems (e.g. you can use * for wildcard, ? for wild-character, and [..] to select a range of characters).
file is the filename that shall be tested. pattern can be a list of search expressions or a string containing a single expression (See: file_match) for details on the expression syntax.
The filname_match() primitive return value is dependent on the pattern type. If pattern is a string, then 1 if the filename matches; 0 otherwise. If pattern is a list, then the index into the list that matched the expression or -1.
Functionality has not been formally verified against CRiSPEdit and whether it supports the [..]+ expression construct.
string filename_realpath( string pathname )
Return a resolved pathname.
The filename_realpath() primitive shall derive, from the pathname an absolute pathname that names the same file, whose resolution does not involve ., .., or symbolic links.
The file_realpath() primitive returns the resolved file if successful otherwise the original pathname.
int find_file( [string &filename], [int &size], [int &mtime], [int &ctime], [int &mode] )
Read next directory entry.
The find_file() primitive retrieves the next file which matches the current file pattern. The active source directory and pattern are controlled using file_pattern.
The following example retrieves are .txt files within the current working directory.
string name;
int size;
file_pattern("*.txt");
while (file_find(name)) {
parsename(name, size);
}
This primitive is used in conjunction with file_pattern.
filename | Optional string, is populated with the base filename; without any path. |
size | Optional integer, if specified is populated with the size of the related file in bytes. |
mtime | Optional integer, populated with the files modification time (See: time). |
ctime | Optional integer, populated with the time of the last status change. |
mode | Mode of file (See: stat). |
Returns zero if there are no more files; returns 1 if next directory entry successfully received.
The mtime, ctime and mode parameters are GriefEdit extensions.
file_pattern, find_file2, file_glob, expandpath, stat, mode_string
int find_file2( string filename, [int &size], [int &mtime], [int &ctime], [int &atime], [int &mode], [int &uid], [string &uid2name], [int &gid], [string &gid2name], [int &nlink], [int &inode] )
Extended read next directory entry.
The find_file2() primitive is an extended version of find_file returning additional file information on which matching file.
filename | Optional string, is populated with the base filename; without any path. |
size | Optional integer, if specified is populated with the size of the related file in bytes. |
mtime | Optional integer, populated with the files modification time (See: time). |
ctime | Optional integer, populated with the time of the last status change. |
atime | Optional integer, populated with the last access time. |
mode | Optional integer, mode of file (See: stat). |
uid | Optional integer, user identifier of the file. |
uid2name | User name associated with the file uid. |
gid | Optional integer, group identifier of the file. |
gid2name | Group name associated with the file gid. |
nlink | Optional integer, number of hard links to the file. |
inode | Optional integer, populated with the file-system internal node number. |
Returns zero if there are no more files; returns 1 if next directory entry successfully received.
A GriefEdit extension.
file_pattern, find_file, file_glob, expandpath, stat, mode_string
string find_macro( string filename )
Determine path of a macro object.
The find_module resolves the full-path to the macro object filename. Using the same mechanism as load_macro, the macro object search path environment variable GRPATH is utilised to search for the specified macro object.
filename | String containing the macro object to resolve. If the specified file has an extension, then an exact match is located. Otherwise files matching one of the following extensions are .cm, .cr, and .m are located. |
The find_module returns a string containing the full-path to the resolved macro object, otherwise an empty string if the object could not be found.
n/a
int fmktemp( string template );
Make a unique filename.
The fmktemp() primitive shall replace the contents of the string template by a unique filename, and return a stream for the file open for reading and writing.
The primitive is equivalent to the mkstemp().
The function thus prevents any possible race condition between testing whether the file exists and opening it for use. The string in template should look like a filename with six trailing X s; fmktemp replaces each X with a character from the portable filename character set.
The characters are chosen such that the resulting name does not duplicate the name of an existing file at the time of a call to fmktemp.
Upon successful completion, fmktemp() shall return an open stream and return the resulting filename. Otherwise, -1 shall be returned if no suitable file could be created.
A GriefEdit extension.
int fopen( string path, int|string flags, [int mode = 0644], [int bufsiz] )
Open a stream.
The fopen() primitive shall open the file whose pathname is the string path, and associates a stream with it.
The flags argument contains a string. If the string is one of the following, the file shall be opened in the indicated mode.
r | Open file for reading. |
w | Truncate to zero length or create file for writing. |
a | Append; open or create file for writing at end-of-file. |
r+ | Open file for update (reading and writing). |
w+ | Truncate to zero length or create file for update. |
a+ | Append; open or create file for update, writing at end-of-file. |
wx | create text file for writing with exclusive access. |
wbx | create binary file for writing with exclusive access. |
w+x | create text file for update with exclusive access. |
w+bx | create binary file for update with exclusive access. |
path | String containing either the full or relative path name of a file to be opened. |
flags | Creation flags, see above. |
mode | Optional creation mode. |
bufsiz | Optionally stream buffer size, in bytes. |
Upon successful completion, fopen() shall return a handle to the stream. Otherwise, -1 shall be returned, and errno shall be set to indicate the error.
A GriefEdit extension.
int fread( int handle, string buffer, [int bufsiz = BUFSIZ], [int null = ' '] )
Read from a stream.
The fread() primitive shall read into the array pointed to by ptr up to nitems elements whose size is specified by size in bytes, from the stream referenced by handle.
handle | Stream handle. |
buffer | String buffer to be written. |
bufsiz | Optional length of buffer to be read. |
Upon successful completion, fread() shall return the number of elements successfully read which is less than bufsiz only if a read error or end-of-file is encountered.
If nitems is 0, fread() shall return 0 and the contents of the array and the state of the stream remain unchanged. Otherwise, if a read error occurs, the error indicator for the stream shall be set, and errno shall be set to indicate the error.
A GriefEdit extension.
int fseek( int handle, int offset, int whence )
Reposition a file-position indicator in a stream.
The fseek() primitive shall set the file-position indicator for the stream pointed to by stream. If a read or write error occurs, the error indicator for the stream shall be set and fseek() fails.
The argument offset is the position to seek to relative to one of three positions specified by the argument whence.
SEEK_SET | The new file position is computed relative to the start of the file. The value of offset must not be negative. |
SEEK_CUR | The new file position is computed relative to the current file position. The value of offset may be positive, negative or zero. |
SEEK_END | The new file position is computed relative to the end of the file. |
handle | Stream handle. |
offset | The new position, measured in bytes from the beginning of the file, shall be obtained by adding offset to the position specified by whence. |
whence | The specified point is the beginning of the file for SEEK_SET, the current value of the file-position indicator for SEEK_CUR, or end-of-file for SEEK_END. |
On success the fseek() functions returns, otherwise -1 and set errno to indicate the error.
A GriefEdit extension.
int fstat( int handle, [int size], [int mtime], [int ctime], [int atime], [int mode], [int uid], [string uid2name], [int gid], [string gid2name], [int nlink] )
Stream status information.
The fstat() primitive obtain information about the file referenced by the handle handle.
This information is returned in the parameters following the handle parameter (if supported by the underlying filesystem)
size | Total file size, in bytes. |
mode | File’s mode (See: chmod). |
mtime | The files “last modified” time (See: time). |
atime | Time the file was “last accessed”. |
ctime | Time of the files “last status change”. |
uid | user-id. |
gid | group-id. |
nlink | Number of hard links. |
The fstat function returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, errno contains a value indicating the type of error that has been detected.
A GriefEdit extension.
int ftell( int handle )
Report the file-position indicator of a stream.
The ftell() primitive shall obtain the current value of the file-position indicator for the stream pointed to by stream.
On successful completion, ftell() shall return the current value of the file-position indicator for the stream measured in bytes from the beginning of the file.
Otherwise, ftell() shall return -1, and set errno to indicate the error.
A GriefEdit extension.
int ftest( int|string condition, string path )
Test file type.
The ftest() primitive tests the type of the specified file path against the type condition. The file test operations are modelled on standard unix test operators as follows.
a | True if file exists. |
b | True if file exists and is a block special file. |
B | True if file exists and is a possible binary stream. |
c | True if file exists and is a character special file. |
d | True if file exists and is a directory. |
e | True if file exists. |
f | True if file exists and is a regular file. |
g | True if file exists and its set group ID flag is set. |
G | True if file exists and its group matches the effective group ID of this process. |
h | True if file exists and is a symbolic link. |
k | True if file exists and has its sticky bit set. |
L | True if file exists and is a symbolic link. |
N | True if file exists and has been modified since last access. |
O | True if file exists and is owned by the effective user ID of this process. |
p | True if file is a named pipe (FIFO). |
r | True if file exists and is readable. |
s | True if file exists and has a size greater than zero. |
S | True if file exists and is a socket. |
u | True if file exists and its set-user-ID flag is set. |
w | True if file exists and is writable. True will indicate only that the write flag is on. The file will not be writable on a read-only file system even if this test indicates true. |
x | True if file exists and is executable. True will indicate only that the execute flag is on. If file is a directory, true indicates that file can be searched. |
The ftest() primitive returns the result of the test operation either 1 when true otherwise 0.
A GriefEdit extenions.
int ftruncate( int handle, [int size] )
Truncate the specified file.
The ftruncate() primitive cause the regular file referenced by handle to be truncated to a size of precisely length bytes.
If the file previously was larger than this size, the extra data is lost. If the file previously was shorter, it is extended, and the extended part reads as null bytes (\0).
The file offset is not changed.
With ftruncate(), the file must be open for writing.
The ftruncate function returns zero on success. When an error has occurred, errno contains a value indicating the type of error that has been detected
A GriefEdit extension.
The ftruncate() primitive is reserved for future use, and currently returns -1 in all cases.
int fwrite( int handle, string buffer, [int length] )
Write to a stream.
The fwrite() primitive shall write, from the string buffer, up to length, to the stream pointed to by handle. If omitted, length by default to the string current length.
The file-position indicator for the stream (if defined) shall be advanced by the number of bytes successfully written. If an error occurs, the resulting value of the file-position indicator for the stream is unspecified.
handle | Stream handle. |
buffer | String buffer to be written. |
length | Optional length of buffer to be written. |
The fwrite() primitive shall return the number of elements successfully written, which may be less than length if a write error is encountered.
If length is 0, fwrite() shall return 0 and the state of the stream remains unchanged. Otherwise, if a write error occurs, the error indicator for the stream shall be set, and errno shall be set to indicate the error.
A GriefEdit extension.
string glob( string pattern )
Generate pathnames matching a pattern.
The glob() primitive expands the specified pattern into single string similar to that which occurs on the shell command line.
* | Match any string of characters. |
[] | Character class. |
? | Match any single character. |
~ | User name home directory. |
\x | Quote the next metacharacter x. |
The glob() primitive returns a string containing the result of the pattern expansion on success, otherwise an empty string.
A GriefEdit extension.
int inq_buffer( [string filename] )
Retrieve a buffer identifier.
The inq_buffer() primitive retrieves either the identifier associated with the buffer containing the specified file filename, otherwise if omitted the identifier of the current buffer.
bufname | Optional string containing the file name to be matched against existing buffers. |
The inq_buffer() primitive returns the unique identifier associated with the referenced file or the current buffer if no file_name was specified. If the specified file_name was not matched, zero is returned.
If omitted then the current buffer is returned.
Unlike BRIEF partial matches do not occur.
attach_buffer, create_buffer, delete_buffer, next_buffer, set_buffer
string inq_file_magic( [int &isdefault] )
Retrieve the file type detection rules.
The inq_file_magic primitive retrieves the current file character encoding detection rules. The returned shall contain one or comma separated detector names with optional arguments, see set_file_magic.
mark,utf8,udet,xascii,ascii
n/a
The inq_file_magic() primitive returns a string containing the current encoder specification.
A GriefEdit extension.
string inq_tmpdir()
Get the temporary-file directory.
The inq_tmpdir() primitive retrieves the temporary file directory. The directory is determined by the current environment, which is host specific, for example on UNIX systems the default value of this property is typically “/tmp” or “/var/tmp”; on Microsoft Windows systems it is typically “c:\temp”.
On XP and greater the system folder local application data directory is queried.
If this fails, the function checks for the existence of environment variables in the following order and uses the first path found:
TMPDIR is the canonical Unix environment variable that should be used to specify a temporary directory for scratch space.
Other forms accepted are TEMP, TEMPDIR and TMP, but these alternatives are used more commonly by non-POSIX operating systems or non-conformant programs.
none
The inq_tmpdir() primitive returns a string containing the temporary file directory.
A GriefEdit extension.
list inq_vfs_mounts()
Retrieve list of mounts.
The inq_vfs_mounts() primitive retrieves a list of three elements describing each of the current mounted virtual file-systems.
none
Returns a list of mount points, each mount description contains the following elements.
mountpoint | String containing the mount point, being the logical path representing the root of the mounted resource. |
prefix | Prefix string, unique name detailing the underlying file-syste type, examples include ftp and gzip. |
flags | Integer flags. |
A GriefEdit extension.
int link( string path1, string path2 )
Link a file.
The link() primitive is reserved for future use.
The link() primitive shall create a new link (directory entry) for the existing file, path1.
The path1 argument points to a pathname naming an existing file. The path2 argument points to a pathname naming the new directory entry to be created. The link() primitive shall atomically create a new link for the existing file and the link count of the file shall be incremented by one.
If path1 names a directory, link() shall fail unless the process has appropriate privileges and the implementation supports using link() on directories.
If path1 names a symbolic link, it is implementation-defined whether link() follows the symbolic link, or creates a new link to the symbolic link itself.
If link() fails, no link shall be created and the link count of the file shall remain unchanged.
Upon successful completion, link shall return 0; otherwise, it shall return -1 and set the global errno to indicate the error.
A GriefEdit extension.
int lstat( string path, [int size], [int mtime], [int ctime], [int atime], [int mode], [int uid], [string uid2name], [int gid], [string gid2name], [int nlink], [int inode] )
Get symbolic link status.
The lstat() primitive shall be equivalent to stat, except when path refers to a symbolic link. In that case lstat shall return information about the link, while stat shall return information about the file the link references.
For symbolic links, the mode member shall contain meaningful information when used with the file type macros, and the size member shall contain the length of the pathname contained in the symbolic link. File mode bits and the contents of the remaining members of the stat structure are unspecified. The value returned in the size member is the length of the contents of the symbolic link, and does not count any trailing null.
path | String containing the file path. |
size | Optional integer, if specified is populated with the size of the related file in bytes. |
mtime | Optional integer, populated with the files modification time (See: time). |
ctime | Optional integer, populated with the time of the last status change. |
atime | Optional integer, populated with the last access time. |
mode | Optional integer, mode of file ((see File Modes )). |
uid | Optional integer, user identifier of the file. |
uid2name | User name associated with the file uid. |
gid | Optional integer, group identifier of the file. |
gid2name | Group name associated with the file gid. |
nlink | Optional integer, number of hard links to the file. |
inode | Optional integer, populated with the file-system internal node number. |
The lstat() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
A GriefEdit extension.
int mkdir( string pathname, int mode = 0755 )
Create a directory.
The mkdir() primitive creates a new subdirectory with name path. The path can be either relative to the current working directory or it can be an absolute path name.
mode is the protection codes used to create the directory. If omitted, the value 0755 (-rwxr-xr-x) will be used.
The mkdir() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
string mktemp( string path )
Make a temporary filename.
The mktemp() primitive shall replace the contents of the string path to by template by a unique filename and return template.
The application shall initialize template to be a filename with six trailing ‘X’s. mktemp() shall replace each X with a single byte character from the portable filename character set.
The mktemp() primitive shall return the string template. If a unique name cannot be created, template shall point to an empty string.
int output_file( [string filename] )
Change the output file-name.
The output_file() primitive changes the file-name associated with the current buffer to filename; the new name should be unique, it cannot be the file-name of an exist buffer or file.
By default the associated file-name associated with a buffer is the file-name specified on an edit_file or create_buffer.
If filename is omitted the user shall be prompted as follows;
Enter new output file name:
Once changed backups shall be created under the new file-name, not the original name.
filename | Optional string containing the new output file-name, if omitted the user is prompted. |
The output_file() primitive returns greater than zero on success, otherwise zero or less on error.
The following error conditions shall be reported to the user;
Duplicate buffer name 'xxx'.
Output file 'xxx' already exists.
n/a
int read_file( [string filename], [int glob = TRUE], [string encoding = NULL] )
Read into the current buffer.
The read_file() primitive reads the content of the specified file filename into the current buffer.
If filename is omitted the user shall be prompted as follows;
File to read:
filename | Optional string containing the file to read, if omitted the user shall be prompted. |
glob | Optional boolean flag, if either TRUE or omitted the filename shall be expanded, see expandpath. |
encoding | Optional string containing the character encoding to be applied to the source file. |
The read_file() primitive returns a positive value on success, 0 if the user was prompted and canceled, otherwise -1 on error.
n/a
string|int readlink( string path, [string &link] )
Read the contents of a symbolic link.
The readlink() primitive shall place the contents of the symbolic link referred to by path in the string link.
If link is omitted the return value is a string. Upon successful completion readlink() shall return the resolved link, otherwise it shall return an empty string and set the global errno to indicate the error.
Then link is given the return value is an int. Upon successful completion, readlink shall return the count of character placed in the string. Otherwise, it shall return a value of -1, and set the global errno to indicate the error.
A GriefEdit extension.
int realpath( string pathname, string resolved_path )
Resolve a pathname.
The realpath() primitive shall derive, from the pathname an absolute pathname that names the same file, whose resolution does not involve ., .., or symbolic links.
The realpath() primitive returns 0 if successful otherwise -1 on error. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
A GriefEdit extension.
int remove( string filename )
Remove a file.
The remove() primitive deletes the file whose name is contained within the string filename.
The remove() primitive returns zero if successful, and a non-zero value (-1)f otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
int rename( string old, string new )
Rename a file.
The rename() primitive causes the file whose name is indicated by the string old to be renamed to the name given by the string new.
The rename() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
int rmdir( string path )
Remove directory.
The rmdir() primitive removes (deletes) the specified directory. The directory must not contain any files or directories. The path can be either relative to the current working directory or it can be an absolute path name.
The rmdir() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
int searchpath( [string path], string filename, [string extension], string & result, [int mode], [int expand = FALSE] )
Searches for a given file in a specified path.
The searchpath() primitives searches the directory path path for a instance of the file name file. path is a list of delimiter separated directory names, with the same syntax as the shell variable GRPATH.
path | Optional string containing the path to be searched for the file. If omitted the system PATH specification shall be referenced. |
filename | String containing the name of the file for which to search. |
extension | Optional string containing the file extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension. If a file name extension is not required or if the file name contains an extension, this parameter can be NULL. |
result | String variable reference to be populated with the first instance of the file resolved along the given search path. |
The expandsearch() primitive returns the length of the string that is copied to the buffer result; otherwise on failure returns a value of zero.
A GriefEdit extension.
int set_binary_size( [int size] )
Set binary chunk size.
The set_binary_size() primitive sets the chunk or block size utilised when loading binary file images. Each chunk shall be represented within the buffer as a single line.
Note:! If the specified value is equal or less-then zero (<= 0), then files shall never be interpreted as binary when read; instead the default system specific type as be applied.
size | Optional integer number, if omitted the current size is not changed. |
The set_binary_size() primitive returns the previous chunk size.
n/a
int set_file_magic( [string encoding], [int cost] )
Define the file type detection rules.
The set_file_magic primitive configures the global file character encoding detection logic.
spec | Optional file character encoding specification. If a non-empty string the detection rules shall be set to the given specification, whereas an empty string shall clear the current user specification, enabling the system default. If the specification is omitted the current rules remain unchanged. |
cost | Optional integer, stating the character cost the detection logic is permitted to incur. |
The order below is somewhat important as the MBCS checks can result in false positives, as such are generally last in line.
Name |
Default |
Description |
---|---|---|
mark |
yes |
Explicit “Encoding: <marker>” within the leading file content. |
utf32bom |
yes |
UTF-32 BOM marker. |
utf16bom |
yes |
UTF-16 BOM marker. |
utf8 |
yes |
UTF-8 |
bom |
yes |
Non UTF BOM markers. |
udet |
yes |
Mozilla Universal Character Detector, see libcharudet. |
magic |
yes |
File magic, see libmagic. |
binary |
yes |
Possible binary image. |
ascii |
yes |
ASCII only (7-bit). |
latin1 |
yes |
Latin-1 (ISO-8859-x) data. |
big5 |
yes |
Chinese Big5. |
gb18030 |
yes |
Chinese GB-18030. |
shiftjis |
yes |
Shift-JIS. |
xascii |
yes |
Extended ASCII. |
charset |
no |
Explicit character-set. |
guess |
n/a |
see libguess. |
Without going into the full details of each search algorithms, several are summarised below.
Markup languages have ways of specifying the encoding in a signature near the top of the file.
The following appears inside the <head> area of an HTML page.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
In XML, the XML declaration specifies the encoding.
<?xml version="1.0" encoding="iso-8859-1"?>
Recognised formats are.
grief/vim | encoding:<xxx> |
emacs | coding:<xxx> |
html | charset=[“’]<xxx>[“’] |
BOM stands for Byte Order Mark which literally is meant to distinguish between little-endian LE and big-endian BE byte order. For UTF-32 and UTF-16 the code point U+FEFF (“zero width no-break space”) are used.
UTF-32 Big Endian 0X00,0X00,0XFE,0XFF
UTF-32 Little Endian 0XFF,0XFE,0X00,0X00
UTF-16 Big Endian 0XFE,0XFF
UTF-16 Little Endian 0XFF,0XFE
UTF-8 auto-detection (when there is no UTF-8 BOM), performs UTF-8 decoding on the file looking for an invalid UTF-8 sequence; correct UTF-8 sequences look like this:
0xxxxxxx ASCII < 0x80 (128)
110xxxxx 10xxxxxx 2-byte >= 0x80
1110xxxx 10xxxxxx 10xxxxxx 3-byte >= 0x400
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 4-byte >= 0x10000
BOM stands for Byte Order Mark which literally is meant to distinguish between little-endian LE and big-endian BE byte order.
For Unicode files, the BOM (“Byte Order Mark” also called the signature or preamble) is a set of leading bytes at the beginning used to indicate the type of Unicode encoding.
The key to the BOM is that it is generally not included with the content of the file when the file’s text is loaded into memory, but it may be used to affect how the file is loaded into memory.
Recognised sequences include;
UTF-32 Big Endian 0X00,0X00,0XFE,0XFF
UTF-32 Little Endian 0XFF,0XFE,0X00,0X00
UTF-16 Big Endian 0XFE,0XFF
UTF-16 Little Endian 0XFF,0XFE
UTF-7 0X2B,0X2F,0X76,0X38
UTF-7 0X2B,0X2F,0X76,0X39
UTF-7 0X2B,0X2F,0X76,0X2B
UTF-7 0X2B,0X2F,0X76,0X2F
UTF-EBCDIC 0XDD,0X73,0X66,0X73
GB18030 0X84,0X31,0X95,0X33
BOCU-1 0XFB,0XEE,0X28,0xFF
BOCU-1 0XFB,0XEE,0X28
SCSU 0X0E,0XFE,0XFF
UTF-1 0XF7,0X64,0X4C
UTF-8 0XEF,0XBB,0XBF
Mozilla Universal Character Detector employs a composite approach that utilizes Code Scheme, Character Distribution and 2-Char Sequence Distribution methods to identify language/encodings has been proven to be very effective and efficient in our environment; see libcharudet.
http://www-archive.mozilla.org- /projects- /intl- /UniversalCharsetDetection.html
Performs Big5 decoding on the file looking for an invalid sequences.
Big5 does not conform to the ISO-2022 standard, but rather bears a certain similarity to Shift-JIS.
It is a double-byte character set with the following structure.
First Byte: 0xA1 - 0xf9 (non-user-defined characters)
or 0x81 - 0xfe (extended range)
Second Byte: 0x40 - 0x7e or 0xa1 - 0xfe
Performs GB18030 decoding on the file looking for an invalid sequences.
GB18030-2000 has the following significant properties;
GB18030-2000 encodes characters in sequences of one, two, or four bytes. The following are valid byte sequences (byte values are hexadecimal):
Single-byte: 0x00-0x7f
Two-byte: 0x81-0xfe + 0x40-0x7e, 0x80-0xfe
Four-byte: 0x81-0xfe + 0x30-0x39 + 0x81-0xfe + 0x30-0x39
The single-byte portion applies the coding structure and principles of the standard GB 11383 (identical to ISO 4873:1986) by using the code points 0x00 through 0x7f.
The two-byte portion uses two eight-bit binary sequences to express a character. The code points of the first (leading) byte range from 0x81 through 0xfe. The code points of the second (trailing) byte ranges from 0x40 through 0x7e and 0x80 through 0xfe.
The four-byte portion uses the code points 0x30 through 0x39, which are vacant in GB 11383, as an additional means to extend the two-byte encodings, thus effectively increasing the number of four-byte codes to now include code points ranging from 0x81308130 through 0xfe39fe39.
GB18030-2000 has 1.6 million valid byte sequences, but there are only 1.1 million code points in Unicode, so there are about 500, 000 byte sequences in GB18030-2000 that are currently unassigned.
Performs Shift-JIS decoding on the file looking for an invalid sequences.
ASCII: 0x21 - 0x7F (also allow control)
Katakana: 0xA1 - 0xDF
JIS X 0208 character
First byte: 0x81 - 0x9F or 0xE0 - 0xEF
Second byte (old 1st): 0x40 - 0x9E
Second byte (even 1st): 0xA0 - 0xFD
libguess employs discrete-finite automata to deduce the character set of the input buffer. The advantage of this is that all character sets can be checked in parallel, and quickly. Right now, libguess passes a byte to each DFA on the same pass, meaning that the winning character set can be deduced as efficiently as possible; see libguess.
The set_file_magic() primitive returns a positive value on success, otherwise -1 on error.
A GriefEdit extension.
int splithpath( string path, [string &dir], [string &name], [string &ext], [string &drive] )
Searches for a given file in a specified path.
The splitpath() primitive break a path into components.
path | Full path. |
dir | Optional string variable reference to be populated with the directory path, including trailing slash. Forward slashes(/ ), backslashes(\), or both may be used. |
name | Optional string variable reference to be populated with the base filename (no extension). |
ext | Optional string variable reference to be populated with the filename extension, including leading period (.) |
drive | Optional string variable reference to be populated with the drive letter, followed by a colon(:). |
The splitpath() primitive returns pothing.
A GriefEdit extension.
int stat( [string path], [int size], [int mtime], [int ctime], [int atime], [int mode], [int uid], [string uid2name], [int gid], [string gid2name], [int nlink], [int inode] )
Obtain file information.
The stat() primitive obtain information about the file or directory referenced in path.
This information is returned in the parameters following the path parameter (if supported by the underlying filesystem).
path | String containing the file path. If omitted the statistics of the current buffer shall be retrieved. |
size | Optional integer, if specified is populated with the size of the related file in bytes. |
mtime | Optional integer, populated with the files modification time (See: time). |
ctime | Optional integer, populated with the time of the last status change. |
atime | Optional integer, populated with the last access time. |
mode | Optional integer, mode of file ((see File Modes )). |
uid | Optional integer, user identifier of the file. |
uid2name | User name associated with the file uid. |
gid | Optional integer, group identifier of the file. |
gid2name | Group name associated with the file gid. |
nlink | Optional integer, number of hard links to the file. |
inode | Optional integer, populated with the file-system internal node number. |
The stat() primitive returns zero if successful, and a non-zero value (-1) otherwise. When an error has occurred, the global errno contains a value indicating the type of error that has been detected.
n/a
int symlink( string path1, string path2 )
Create a symbolic link.
The symlink() primitive shall create a symbolic link called path2 that contains the string path1.
In other words, path2 is the name of the symbolic link created, path1 is the string contained in the symbolic link.
If the symlink() primitive fails for any reason other than any file named by path2 shall be unaffected.
Upon successful completion, symlink() shall return 0; otherwise, it shall return -1 and set the global errno to indicate the error.
A GriefEdit extension.
int umask( int cmask = NULL )
Set and get the file mode creation mask.
The umask() primitive shall set the processes file mode creation mask to cmask and return the previous value of the mask.
Only the file permission bits of cmask are used; the meaning of the other bits is implementation-defined.
The process’ file mode creation mask is used to turn off permission bits in the mode argument supplied during calls to the following functions:
The file permission bits in the value returned by umask() shall be the previous value of the file mode creation mask.
int unlink( string path )
Unlink a file.
The unlink() primitive is reserved for future use.
The unlink() primitive shall remove a link to a file. If path names a symbolic link, unlink() shall remove the symbolic link named by path and shall not affect any file or directory named by the contents of the symbolic link. Otherwise, unlink() shall remove the link named by the pathname pointed to by path and shall decrement the link count of the file referenced by the link.
When the file’s link count becomes 0 and no process has the file open, the space occupied by the file shall be freed and the file shall no longer be accessible. If one or more processes have the file open when the last link is removed, the link shall be removed before unlink() returns, but the removal of the file contents shall be postponed until all references to the file are closed.
The path argument shall not name a directory unless the process has appropriate privileges and the implementation supports using unlink() on directories.
Upon successful completion, link shall return 0; otherwise, it shall return -1 and set the global errno to indicate the error.
A GriefEdit extension.
int vfs_mount( string mountpoint, int flags = 0, string vfsname, [string arguments] )
Mount a virtual file-system.
The vfs_mount() primitive mounts a virtual file-system.
mountpoint | String containing the mount point, being the logical path representing the root of the mounted resource. |
flags | Integer mount flags. |
vfsname | String containing the virtual file-system driver to be applied. |
arguments | Optional string arguments to be passed upon the underlying vfs implementation; the format and values required are specific to the virtual file-system driver referenced within vfsname. |
The vfs_mount() primitive returns 0 on success, otherwise -1 on error and errno contains a value indicating the type of error that has been detected.
A GriefEdit extension.
int vfs_unmount( string mountpoint, int flags = 0 )
Unmount a virtual file-system.
The vfs_unmount() primitive unmounts the specified virtual file-system referenced by mountpoint.
mountpoint | String containing the mount point, being the logical path representing the root of the mounted resource. |
flags | Optional integer unmount flags. |
The vfs_unmount() primitive returns 0 on success, otherwise -1 on error and errno contains a value indicating the type of error that has been detected.
A GriefEdit extension.
Traditional Unix file mode consist of a number of components including type, permissions including special bits.
The mode_string primitive creates a human readable string version of these bits in a system independent form.
The file type is represented by the following constants.
S_IFBLK | Block special. |
S_IFCHR | Character special. |
S_IFIFO | FIFO special. |
S_IFREG | Regular. |
S_IFDIR | Directory. |
S_IFLNK | Symbolic link. |
S_IFSOCK | Socket. |
Permissions on Unix-like systems are managed in three distinct classes. These classes are known as user, group, and others.
Files and directories are owned by a user. The owner determines the file’s owner class. Distinct permissions apply to the owner.
Files and directories are assigned a group, which define the file’s group class. Distinct permissions apply to members of the file’s group. The owner may be a member of the file’s group.
Users who are not the owner, nor a member of the group, comprise a file’s others class. Distinct permissions apply to others.
The effective permissions are determined based on the user’s class. For example, the user who is the owner of the file will have the permissions given to the owner class regardless of the permissions assigned to the group class or others class.
For each group there are three specific permissions on Unix-like systems that apply to each class:
The file permissions are represented by the following constants.
Read, write, execute/search by owner.
S_IRUSR | Read permission, owner. |
S_IWUSR | Write permission, owner. |
S_IXUSR | Execute/search permission, owner. |
Read, write, execute/search by group.
S_IRGRP | Read permission, group. |
S_IWGRP | Write permission, group. |
S_IXGRP | Execute/search permission, group. |
Read, write, execute/search by others.
S_IROTH | Read permission, others. |
S_IWOTH | Write permission, others. |
S_IXOTH | Execute/search permission, others. |
Unix-like systems typically employ three additional modes. These are actually attributes but are referred to as permissions or modes. These special modes are for a file or directory overall, not by a class.
The special bits are represented by the following constants.
S_ISUID | Set-user-ID on execution. |
S_ISGID | Set-group-ID on execution. |
S_ISVTX | On directories, restricted deletion flag. [Option End] |
$Id: $
To send feedback on this topic email: grie@gmai l.com fedit
Copyright © Adam Young All Rights Reserved.
Test file accessibility.
int access( string path, int mode )
Return the last component of a pathname.
int basename( string pathname, [string suffix] )
Change directory.
int chdir( string path )
Change mode.
int chmod( string path, int mode )
Change owner.
int chown( string path, int owner, int group )
Binary file compare.
int compare_files( [int flags], string file1, string file2 )
Copy file extended information.
int copy_ea_info( string sourcename, string destname )
Delete a file.
int del( string name )
Report the parent directory name of a file pathname.
int dirname( string path )
Edit a file.
int edit_file( ... )
Extended file edit.
int edit_file2( [int &files], [string encoding], [int mode], string|list file )
Check file existence.
int exist( string path, [int canon = TRUE] )
Expand the path.
string expandpath( string path, [int env] )
Close a stream.
int fclose( int handle )
Test end-of-file indicator on a stream.
int feof( int handle )
Test error indicator on a stream.
int ferror( int handle, [int clearerr] )
Flush a stream.
int fflush( int handle, [int sync] )
Canonicalize a path.
string file_canon( string filepath )
File match utility.
int file_match( pattern, file, [flags] )
Directory file pattern.
int file_pattern( string filespec )
Perform file pattern matching.
int filename_match( string file, declare pattern )
Return a resolved pathname.
string filename_realpath( string pathname )
Read next directory entry.
int find_file( [string &filename], [int &size], [int &mtime], [int &ctime], [int &mode] )
Extended read next directory entry.
int find_file2( string filename, [int &size], [int &mtime], [int &ctime], [int &atime], [int &mode], [int &uid], [string &uid2name], [int &gid], [string &gid2name], [int &nlink], [int &inode] )
Determine path of a macro object.
string find_macro( string filename )
File miscellaneous control.
int fioctl( int handle, .. )
File lock operations.
int flock( int handle, .. )
Make a unique filename.
int fmktemp( string template );
Open a stream.
int fopen( string path, int|string flags, [int mode = 0644], [int bufsiz] )
Read from a stream.
int fread( int handle, string buffer, [int bufsiz = BUFSIZ], [int null = ' '] )
Reposition a file-position indicator in a stream.
int fseek( int handle, int offset, int whence )
Stream status information.
int fstat( int handle, [int size], [int mtime], [int ctime], [int atime], [int mode], [int uid], [string uid2name], [int gid], [string gid2name], [int nlink] )
Report the file-position indicator of a stream.
int ftell( int handle )
Test file type.
int ftest( int|string condition, string path )
Truncate the specified file.
int ftruncate( int handle, [int size] )
Write to a stream.
int fwrite( int handle, string buffer, [int length] )
Generate pathnames matching a pattern.
string glob( string pattern )
Retrieve a buffer identifier.
int inq_buffer( [string filename] )
Retrieve the file type detection rules.
string inq_file_magic( [int &isdefault] )
Retrieve the user home directory.
string inq_home()
Get the temporary-file directory.
string inq_tmpdir()
Retrieve list of mounts.
list inq_vfs_mounts()
Link a file.
int link( string path1, string path2 )
Get symbolic link status.
int lstat( string path, [int size], [int mtime], [int ctime], [int atime], [int mode], [int uid], [string uid2name], [int gid], [string gid2name], [int nlink], [int inode] )
Create a directory.
int mkdir( string pathname, int mode = 0755 )
Make a temporary filename.
string mktemp( string path )
Change the output file-name.
int output_file( [string filename] )
Read file extended information.
int read_ea( string filename, ... )
Read into the current buffer.
int read_file( [string filename], [int glob = TRUE], [string encoding = NULL] )
Read the contents of a symbolic link.
string|int readlink( string path, [string &link] )
Resolve a pathname.
int realpath( string pathname, string resolved_path )
Remove a file.
int remove( string filename )
Rename a file.
int rename( string old, string new )
Remove directory.
int rmdir( string path )
Searches for a given file in a specified path.
int searchpath( [string path], string filename, [string extension], string & result, [int mode], [int expand = FALSE] )
Set binary chunk size.
int set_binary_size( [int size] )
Set file extended information.
int set_ea( string filename, ... )
Define the file type detection rules.
int set_file_magic( [string encoding], [int cost] )
Searches for a given file in a specified path.
int splithpath( string path, [string &dir], [string &name], [string &ext], [string &drive] )
Obtain file information.
int stat( [string path], [int size], [int mtime], [int ctime], [int atime], [int mode], [int uid], [string uid2name], [int gid], [string gid2name], [int nlink], [int inode] )
Create a symbolic link.
int symlink( string path1, string path2 )
Set and get the file mode creation mask.
int umask( int cmask = NULL )
Unlink a file.
int unlink( string path )
Mount a virtual file-system.
int vfs_mount( string mountpoint, int flags = 0, string vfsname, [string arguments] )
Unmount a virtual file-system.
int vfs_unmount( string mountpoint, int flags = 0 )
Last system errno number.
extern int errno;
Filename comparison.
int strfilecmp( string file1, string file2, [int length] )
Change directory.
int cd( [string dir] )
Get current working directory.
int getwd( int ignored, string dir )
Register a callback procedure.
int register_macro( int type, string macro, [int local = FALSE] )
Attach a buffer to a window.
void attach_buffer( int bufnum )
Invoke registered macro callbacks.
int call_registered_macro( int type )
Create and load a buffer.
int create_buffer( string bufname, [string filename], [int sysflag = FALSE], [int editflags = 0], [string encoding = ""] )
Set the current buffer.
int set_buffer( int bufnum )
Return names of files that match patterns.
list file_glob( string files )
Retrieve an environment variable.
string getenv( string name )
Get the current system time.
int time( [int &hour], [int &min], [int &sec], [int &msec] )
Conversion stat mode to a string representation.
string mode_string( [int mode], [int format = 0], [string path] )
Load a macro object.
int load_macro( string filename, [int reload = 1] )
Macro object search path.
extern const string GRPATH;
Register location of one or more macros.
void autoload( string filename, string function, ... )
Delete a buffer.
void delete_buffer( int bufnum )
Identifier of the next buffer.
int next_buffer( [int sysflag = 0], [int previous], [int tab] )
Retrieve the user name.
string inq_username()
Retrieve a buffers line terminator.
int inq_terminator( [int bufnum], [string &term] )