These procedures allow querying and setting file system attributes (such as owner, permissions, sizes and types of files); deleting, copying, renaming and linking files; creating and removing directories and querying their contents; syncing the file system and creating special files.
Test accessibility of a file under the real UID and GID of the calling process. The return is
#tif path exists and the permissions requested by how are all allowed, or
how is an integer which is one of the following values, or a bitwise-OR (
logior) of multiple values.— Variable: F_OK
Test for existence of the file. This is implied by each of the other tests, so there's no need to combine it with them.
It's important to note that
access?does not simply indicate what will happen on attempting to read or write a file. In normal circumstances it does, but in a set-UID or set-GID program it doesn't because
access?tests the real ID, whereas an open or execute attempt uses the effective ID.
A program which will never run set-UID/GID can ignore the difference between real and effective IDs, but for maximum generality, especially in library functions, it's best not to use
access?to predict the result of an open or execute, instead simply attempt that and catch any exception.
The main use for
access?is to let a set-UID/GID program determine what the invoking user would have been allowed to do, without the greater (or perhaps lesser) privileges afforded by the effective ID. For more on this, see Testing File Access.
Return an object containing various information about the file determined by obj. obj can be a string containing a file name or a port or integer file descriptor which is open on a file (in which case
fstatis used as the underlying system call).
The object returned by
statcan be passed as a single parameter to the following procedures, all of which return integers:— Scheme Procedure: stat:ino st
The file serial number, which distinguishes this file from all other files on the same device.— Scheme Procedure: stat:mode st
The mode of the file. This is an integer which incorporates file type information and file permission bits. See also
stat:permsbelow.— Scheme Procedure: stat:rdev st
Device ID; this entry is defined only for character or block special files. On some systems this field is not available at all, in which case
#f.— Scheme Procedure: stat:blksize st
The optimal block size for reading or writing the file, in bytes. On some systems this field is not available, in which case
stat:blksizereturns a sensible suggested block size.— Scheme Procedure: stat:blocks st
The amount of disk space that the file occupies measured in units of 512 byte blocks. On some systems this field is not available, in which case
In addition, the following procedures return the information from
stat:modein a more convenient form:— Scheme Procedure: stat:type st
A symbol representing the type of file. Possible values are ‘regular’, ‘directory’, ‘symlink’, ‘block-special’, ‘char-special’, ‘fifo’, ‘socket’, and ‘unknown’.
stat, but does not follow symbolic links, i.e., it will return information about a symbolic link itself, not the file it points to. path must be a string.
Return the value of the symbolic link named by path (a string), i.e., the file that the link points to.
Change the ownership and group of the file referred to by object to the integer values owner and group. object can be a string containing a file name or, if the platform supports
fchown(see File Owner), a port or integer file descriptor which is open on the file. The return value is unspecified.
If object is a symbolic link, either the ownership of the link or the ownership of the referenced file will be changed depending on the operating system (lchown is unsupported at present). If owner or group is specified as
-1, then that ID is not changed.
Changes the permissions of the file referred to by obj. obj can be a string containing a file name or a port or integer file descriptor which is open on a file (in which case
fchmodis used as the underlying system call). mode specifies the new permissions as a decimal number, e.g.,
(chmod "foo" #o755). The return value is unspecified.
utimesets the access and modification times for the file named by path. If actime or modtime is not supplied, then the current time is used. actime and modtime must be integer time values as returned by the
current-timeprocedure.(utime "foo" (- (current-time) 3600))
will set the access time to one hour in the past and the modification time to the current time.
Deletes (or “unlinks”) the file whose path is specified by str.
Copy the file specified by oldfile to newfile. The return value is unspecified.
Renames the file specified by oldname to newname. The return value is unspecified.
Creates a new name newpath in the file system for the file named by oldpath. If oldpath is a symbolic link, the link may or may not be followed depending on the system.
Create a symbolic link named newpath with the value (i.e., pointing to) oldpath. The return value is unspecified.
Create a new directory named by path. If mode is omitted then the permissions of the directory file are set using the current umask (see Processes). Otherwise they are set to the decimal value specified with mode. The return value is unspecified.
Remove the existing directory named by path. The directory must be empty for this to succeed. The return value is unspecified.
Return a boolean indicating whether object is a directory stream as returned by
Return (as a string) the next directory entry from the directory stream stream. If there is no remaining entry to be read then the end of file object is returned.
Reset the directory port stream so that the next call to
readdirwill return the first directory entry.
Close the directory stream stream. The return value is unspecified.
Here is an example showing how to display all the entries in a directory:
(define dir (opendir "/usr/lib")) (do ((entry (readdir dir) (readdir dir))) ((eof-object? entry)) (display entry)(newline)) (closedir dir)
Flush the operating system disk buffers. The return value is unspecified.
Creates a new special file, such as a file corresponding to a device. path specifies the name of the file. type should be one of the following symbols: ‘regular’, ‘directory’, ‘symlink’, ‘block-special’, ‘char-special’, ‘fifo’, or ‘socket’. perms (an integer) specifies the file permissions. dev (an integer) specifies which device the special file refers to. Its exact interpretation depends on the kind of special file being created.
E.g.,(mknod "/dev/fd0" 'block-special #o660 (+ (* 2 256) 2))
The return value is unspecified.
Care must be taken when using
tmpnam. In between choosing the name and creating the file another program might use that name, or an attacker might even make it a symlink pointing at something important and causing you to overwrite that.
The safe way is to create the file using
O_EXCLto avoid any overwriting. A loop can try again with another name if the file exists (error
mkstemp!below does that.
tmpl is a string specifying where the file should be created: it must end with ‘XXXXXX’ and those ‘X’s will be changed in the string to return the name of the file. (
port-filenameon the port also gives the name.)
POSIX doesn't specify the permissions mode of the file, on GNU and most systems it's
#o600. An application can use
chmodto relax that if desired. For example
umask, which is usual for ordinary file creation,(let ((port (mkstemp! (string-copy "/tmp/myfile-XXXXXX")))) (chmod port (logand #o666 (lognot (umask)))) ...)
Return the directory name component of the file name filename. If filename does not contain a directory component,
Return the base name of the file name filename. The base name is the file name without any directory components. If suffix is provided, and is equal to the end of basename, it is removed also.(basename "/tmp/test.xml" ".xml") ⇒ "test"