7.  Files and Directories  

(unix-stat file)

The UNIX stat()/fstat() system call. file is either a filename or a file descriptor.

unix-stat returns a stat-record with the following fields:

|Field |  Type   |        Contents         |
|type  | symbol  | file type               |
|mode  | integer | file access mode        |
|ino   | integer | inode number            |
|dev   | integer | device number           |
|nlink | integer | number of links to file |
|uid   | integer | file owner's user-ID    |
|gid   | integer | file owner's group-ID   |
|size  | integer | file size               |
|atime | integer | last access time        |
|mtime | integer | last modified time      |
|ctime | integer | last inode change time  |

The file type is one of the symbols directory, character-special, block-special, regular, symlink, socket, fifo, or unknown.

(unix-access? filename mode)

unix-access? is based on the access() system call. mode is a list of zero or more of the symbols read, write, and execute. The empty list can be used to test for existence of the file. The procedure returns #t if the specified access is granted, #f otherwise.

(unix-chdir filename)

The UNIX chdir() system call. unix-chdir returns the non-printing object.

(unix-chmod filename mode)

The UNIX chmod() system call. mode is an integer. unix-chmod returns the non-printing object.

(unix-chown filename uid gid)

The UNIX chown() system call. uid and gid are integers. unix-chown returns the non-printing object.

(unix-unlink filename)

The UNIX unlink() system call. unix-unlink returns the non-printing object.

(unix-link filename1 filename2)

The UNIX link() system call. unix-link returns the non-printing object.

(unix-rename filename1 filename2)

The UNIX rename() system call. unix-rename returns the non-printing object.

On platforms where the rename() function is not available, the operation is performed by the equivalent sequence of link() and unlink() calls with interrupts disabled (certain restrictions apply in this case, e.g. directories cannot be renamed).

(unix-mkdir filename mode)

The UNIX mkdir() system call. mode is an integer. unix-mkdir returns the non-printing object.

(unix-rmdir filename)

The UNIX rmdir() system call. unix-rmdir returns the non-printing object.

(unix-utime filename)
(unix-utime filename atime mtime)

The UNIX utime() function. unix-utime sets the last access and last modification time of the given file to the current time (first form) or to the specified times (second form). atime and mtime are integers. unix-utime returns the non-printing object.

(unix-read-directory filename)

This procedure returns the contents of the specified directory as a list of filenames (strings). filename must be the name of a directory. unix-read-directory is based on the opendir(), readdir(), and closedir() functions.


;;; Return directory contents as list of (filename . filetype) pairs
(define (get-files-and-types directory)
    (lambda (file)
      (cons file (stat-type (unix-stat file))))
    (unix-read-directory directory)))

(pp (get-files-and-types "."))

(unix-tempname directory)
(unix-tempname directory prefix)

unix-tempname returns a pathname that can be used as the name of a temporary file (typically in /tmp or /usr/tmp). The newly created pathname is not the name of an existing file.

directory (a string or symbol) can be used to specify the directory component of the pathname; prefix (string or symbol), if present, may be used as a prefix for the filename component of the pathname. However, both arguments may be ignored by unix-tempname.

unix-tempname is based on one of the UNIX functions tempnam(), mktemp(), and tmpnam() (in that order); if none of these functions is available, an algorithm similar to the one employed by UNIX mktemp() is used.

Markup created by unroff 1.0,    September 24, 1996,    net@informatik.uni-bremen.de