Common Lisp Package: OSICAT

Osicat is a lightweight operating system interface for Common Lisp on Unix-platforms. It is not a POSIX-style API, but rather a simple lispy accompaniment to the standard ANSI facilities. Osicat homepage: http://www.common-lisp.net/project/osicat/ Concepts: Designated directory When a relative pathname designator is used as a directory designator it is first resolved against *DEFAULT-PATHNAME-DEFAULT*, and then against the current directory. (With MERGE-PATHNAMES in both cases.)

README:

FUNCTION

Public

ABSOLUTE-PATHNAME (PATHSPEC &OPTIONAL (DEFAULT *DEFAULT-PATHNAME-DEFAULTS*))

Returns an absolute pathname corresponding to PATHSPEC by merging it with DEFAULT, and (CURRENT-DIRECTORY) if necessary.

ABSOLUTE-PATHNAME-P (PATHSPEC)

Returns T if the PATHSPEC designates an absolute pathname, NIL otherwise.

CURRENT-DIRECTORY

CURRENT-DIRECTORY returns the operating system's current directory, which may or may not correspond to *DEFAULT-PATHNAME-DEFAULTS*. SETF CURRENT-DIRECTORY changes the operating system's current directory to the PATHSPEC. An error is signalled if the PATHSPEC is wild or does not designate a directory.

DELETE-DIRECTORY (PATHSPEC)

Deletes the directory designated by PATHSPEC. Returns T. The directory must be empty. Symbolic links are not followed. Signals an error if PATHSPEC is wild, doesn't designate a directory, or if the directory could not be deleted.

DELETE-DIRECTORY-AND-FILES (DIRNAME &KEY (IF-DOES-NOT-EXIST ERROR))

Recursively deletes all files and directories within the directory designated by the non-wild pathname designator DIRNAME including DIRNAME itself. IF-DOES-NOT-EXIST must be one of :ERROR or :IGNORE where :ERROR means that an error will be signaled if the directory DIRNAME does not exist.

DIRECTORY-EXISTS-P (PATHSPEC)

Checks whether the file named by the pathname designator PATHSPEC exists and is a directory. Returns its truename if this is the case, NIL otherwise. Follows symbolic links.

DIRECTORY-PATHNAME-P (PATHSPEC)

Returns NIL if PATHSPEC (a pathname designator) does not designate a directory, PATHSPEC otherwise. It is irrelevant whether file or directory designated by PATHSPEC does actually exist.

ENVIRONMENT

ENVIRONMENT returns the current environment as an assoc-list. SETF ENVIRONMENT modifies the environment its argument. Often it is preferable to use SETF ENVIRONMENT-VARIABLE and MAKUNBOUND-ENVIRONMENT-VARIABLE to modify the environment instead of SETF ENVIRONMENT.

ENVIRONMENT-VARIABLE (NAME)

ENVIRONMENT-VARIABLE returns the environment variable identified by NAME, or NIL if one does not exist. NAME can either be a symbol or a string. SETF ENVIRONMENT-VARIABLE sets the environment variable identified by NAME to VALUE. Both NAME and VALUE can be either a symbols or strings. Signals an error on failure.

FILE-EXISTS-P (PATHSPEC &OPTIONAL FILE-KIND)

Checks whether the file named by the pathname designator PATHSPEC exists, if this is the case and FILE-KIND is specified it also checks the file kind. If the tests succeed, return two values: truename and file kind of PATHSPEC, NIL otherwise. Follows symbolic links.

FILE-KIND (PATHSPEC &KEY FOLLOW-SYMLINKS)

Returns a keyword indicating the kind of file designated by PATHSPEC, or NIL if the file does not exist. Does not follow symbolic links by default. Possible file-kinds in addition to NIL are: :REGULAR-FILE, :SYMBOLIC-LINK, :DIRECTORY, :PIPE, :SOCKET, :CHARACTER-DEVICE, and :BLOCK-DEVICE. If FOLLOW-SYMLINKS is non-NIL and PATHSPEC designates a broken symlink returns :BROKEN as second value. Signals an error if PATHSPEC is wild.

FILE-PERMISSIONS (PATHSPEC)

FILE-PERMISSIONS returns a list of keywords identifying the permissions of PATHSPEC. SETF FILE-PERMISSIONS sets the permissions of PATHSPEC as identified by the symbols in list. If PATHSPEC designates a symbolic link, that link is implicitly resolved. Permission symbols consist of :USER-READ, :USER-WRITE, :USER-EXEC, :GROUP-READ, :GROUP-WRITE, :GROUP-EXEC, :OTHER-READ, :OTHER-WRITE, :OTHER-EXEC, :SET-USER-ID, :SET-GROUP-ID, and :STICKY. Both signal an error if PATHSPEC is wild, or doesn't designate an existing file.

GET-MONOTONIC-TIME

Gets current time in seconds from a system's monotonic clock.

LIST-DIRECTORY (PATHSPEC &KEY BARE-PATHNAMES)

Returns a fresh list of pathnames corresponding to all files within the directory named by the non-wild pathname designator PATHSPEC. If BARE-PATHNAMES is non-NIL only the files's bare pathnames are returned (with an empty directory component), otherwise the files' pathnames are merged with PATHSPEC.

MAKUNBOUND-ENVIRONMENT-VARIABLE (NAME)

Removes the environment variable identified by NAME from the current environment. NAME can be either a string or a symbol. Returns the string designated by NAME. Signals an error on failure.

MAPDIR (FUNCTION PATHSPEC)

Applies function to each entry in directory designated by PATHSPEC in turn and returns a list of the results. Binds *DEFAULT-PATHNAME-DEFAULTS* to the directory designated by pathspec round to function call. If PATHSPEC designates a symbolic link, it is implicitly resolved. Signals an error if PATHSPEC is wild or doesn't designate a directory.

OPEN-TEMPORARY-FILE (&KEY (PATHSPEC *TEMPORARY-DIRECTORY*) (ELEMENT-TYPE 'CHARACTER) (EXTERNAL-FORMAT DEFAULT))

Creates a temporary file setup for input and output, and returns a stream connected to that file. PATHSPEC serves as template for the file to be created: a certain number of random characters will be concatenated to the file component of PATHSPEC. If PATHSPEC has no directory component, the file will be created inside *TEMPORARY-DIRECTORY*. The file itself is unlinked once it has been opened. ELEMENT-TYPE specifies the unit of transaction of the stream. Consider using WITH-TEMPORARY-FILE instead of this function. On failure, a FILE-ERROR may be signalled.

PATHNAME-AS-DIRECTORY (PATHSPEC)

Converts the non-wild pathname designator PATHSPEC to directory form.

PATHNAME-AS-FILE (PATHSPEC)

Converts the non-wild pathname designator PATHSPEC to file form.

PATHNAME-DIRECTORY-PATHNAME (PATHSPEC)

Returns the directory part of PATHSPEC as a pathname.

REGULAR-FILE-EXISTS-P (PATHSPEC)

Checks whether the file named by the pathname designator PATHSPEC exists and is a regular file. Returns its truename if this is the case, NIL otherwise. Follows symbolic links.

RELATIVE-PATHNAME-P (PATHSPEC)

Returns T if the PATHSPEC designates a relative pathname, NIL otherwise.

UNMERGE-PATHNAMES (PATHSPEC &OPTIONAL (DEFAULT *DEFAULT-PATHNAME-DEFAULTS*))

Removes those leading directory components from PATHSPEC that are shared with DEFAULT.

USER-INFO (ID)

USER-INFO returns the password entry for the given name or numerical user ID, as an assoc-list.

WALK-DIRECTORY (DIRNAME FN &KEY DIRECTORIES (IF-DOES-NOT-EXIST ERROR) (TEST (CONSTANTLY T)))

Recursively applies the function FN to all files within the directory named by the non-wild pathname designator DIRNAME and all of its sub-directories. Returns T on success. FN will only be applied to files for which the function TEST returns a true value. If DIRECTORIES is not NIL, FN and TEST are applied to directories as well. If DIRECTORIES is :DEPTH-FIRST, FN will be applied to the directory's contents first. If DIRECTORIES is :BREADTH-FIRST and TEST returns NIL, the directory's content will be skipped. IF-DOES-NOT-EXIST must be one of :ERROR or :IGNORE where :ERROR means that an error will be signaled if the directory DIRNAME does not exist.

Undocumented

SETFCURRENT-DIRECTORY (PATHSPEC)

SETFENVIRONMENT (ALIST)

SETFENVIRONMENT-VARIABLE (VALUE NAME)

SETFFILE-PERMISSIONS (PERMS PATHSPEC)

NATIVE-NAMESTRING (PATHNAME)

SYSTEM-ERROR (CONTROL-STRING &REST ARGS)

Private

Undocumented

%OPEN-TEMPORARY-FILE/FD-STREAMS (FILENAME ELEMENT-TYPE EXTERNAL-FORMAT)

%OPEN-TEMPORARY-FILE/NO-FD-STREAMS (FILENAME ELEMENT-TYPE EXTERNAL-FORMAT)

CALL-WITH-DIRECTORY-ITERATOR (PATHSPEC FUN)

COMPONENT-PRESENT-P (VALUE)

GET-FILE-KIND (FILE FOLLOW-P)

MAKE-FD-STREAM (FD &KEY DIRECTION ELEMENT-TYPE EXTERNAL-FORMAT PATHNAME FILE)

TO-SIMPLE-STRING (THING)

MACRO

Public

WITH-DIRECTORY-ITERATOR ((ITERATOR PATHSPEC) &BODY BODY)

PATHSPEC must be a valid directory designator: *DEFAULT-PATHNAME-DEFAULTS* is bound, and (CURRENT-DIRECTORY) is set to the designated directory for the dynamic scope of the body. Within the lexical scope of the body, ITERATOR is defined via macrolet such that successive invocations of (ITERATOR) return the directory entries, one by one. Both files and directories are returned, except '.' and '..'. The order of entries is not guaranteed. The entries are returned as relative pathnames against the designated directory. Entries that are symbolic links are not resolved, but links that point to directories are interpreted as directory designators. Once all entries have been returned, further invocations of (ITERATOR) will all return NIL. The value returned is the value of the last form evaluated in body. Signals an error if PATHSPEC is wild or does not designate a directory.

WITH-TEMPORARY-FILE ((STREAM &KEY (PATHSPEC *TEMPORARY-DIRECTORY*) (ELEMENT-TYPE 'CHARACTER) (EXTERNAL-FORMAT DEFAULT)) &BODY BODY)

Within the lexical scope of the body, STREAM is connected to a temporary file as created by OPEN-TEMPORARY-FILE. The file is closed automatically once BODY exits.

Private

Undocumented

%CLOSE-ON-ERROR (CLOSE-CLAUSE &BODY BODY)

GENERIC-FUNCTION

Public

Undocumented

SYSTEM-ERROR-CODE (CONDITION)

SYSTEM-ERROR-IDENTIFIER (CONDITION)

SYSTEM-ERROR-MESSAGE (CONDITION)

VARIABLE

Public

Undocumented

*TEMPORARY-DIRECTORY*

CONDITION

Public

SYSTEM-ERROR (CONTROL-STRING &REST ARGS)

Base class for errors signalled by Osicat.

CONSTANT

Private

Undocumented

+PERMISSIONS+