Next: , Previous: , Up: Packages   [Contents][Index]

5.6 I/O-Extensions

If 'i/o-extensions is provided (by linking in ioext.o), Line I/O in SLIB, and the following functions are defined:

Function: stat <port-or-string>

Returns a vector of integers describing the argument. The argument can be either a string or an open input port. If the argument is an open port then the returned vector describes the file to which the port is opened; If the argument is a string then the returned vector describes the file named by that string. If there exists no file with the name string, or if the file cannot be accessed #f is returned. The elements of the returned vector are as follows:

0 st_dev

ID of device containing a directory entry for this file

1 st_ino

Inode number

2 st_mode

File type, attributes, and access control summary

3 st_nlink

Number of links

4 st_uid

User ID of file owner

5 st_gid

Group ID of file group

6 st_rdev

Device ID; this entry defined only for char or blk spec files

7 st_size

File size (bytes)

8 st_atime

Time of last access

9 st_mtime

Last modification time

10 st_ctime

Last file status change time

Function: getpid

Returns the process ID of the current process.

Function: try-create-file name modes perms

If the file with name name already exists, return #f, otherwise try to create and open the file like try-open-file, See Files and Ports. If the optional integer argument perms is provided, it is used as the permissions of the new file (modified by the current umask).

Function: reopen-file filename modes port

Closes port port and reopens it with filename and modes. reopen-file returns #t if successful, #f if not.

Function: duplicate-port port modes

Creates and returns a duplicate port from port. Duplicate unbuffered ports share one file position. modes are as for open-file.

Function: redirect-port! from-port to-port

Closes to-port and makes to-port be a duplicate of from-port. redirect-port! returns to-port if successful, #f if not. If unsuccessful, to-port is not closed.

Function: opendir dirname

Returns a directory object corresponding to the file system directory named dirname. If unsuccessful, returns #f.

Function: readdir dir

Returns the string name of the next entry from the directory dir. If there are no more entries in the directory, readdir returns a #f.

Function: rewinddir dir

Reinitializes dir so that the next call to readdir with dir will return the first entry in the directory again.

Function: closedir dir

Closes dir and returns #t. If dir is already closed,, closedir returns a #f.

Function: directory-for-each proc directory

proc must be a procedure taking one argument. ‘Directory-For-Each’ applies proc to the (string) name of each file in directory. The dynamic order in which proc is applied to the filenames is unspecified. The value returned by ‘directory-for-each’ is unspecified.

Function: directory-for-each proc directory pred

Applies proc only to those filenames for which the procedure pred returns a non-false value.

Function: directory-for-each proc directory match

Applies proc only to those filenames for which (filename:match?? match) would return a non-false value (see Filenames in SLIB).

(require 'directory)
(directory-for-each print "." "[A-Z]*.scm")
-|
"Init.scm" 
"Iedline.scm" 
"Link.scm" 
"Macro.scm" 
"Transcen.scm" 
"Init5f4.scm" 
Function: directory*-for-each proc path-glob

path-glob is a pathname whose last component is a (wildcard) pattern (see Filenames in SLIB). proc must be a procedure taking one argument. ‘directory*-for-each’ applies proc to the (string) name of each file in the current directory. The dynamic order in which proc is applied to the filenames is unspecified. The value returned by ‘directory*-for-each’ is unspecified.

Function: mkdir path mode

The mkdir function creates a new, empty directory whose name is path. The integer argument mode specifies the file permissions for the new directory. See The Mode Bits for Access Permission in Gnu C Library, for more information about this.

mkdir returns if successful, #f if not.

Function: rmdir path

The rmdir function deletes the directory path. The directory must be empty before it can be removed. rmdir returns if successful, #f if not.

Function: chdir filename

Changes the current directory to filename. If filename does not exist or is not a directory, #f is returned. Otherwise, #t is returned.

Function: getcwd

The function getcwd returns a string containing the absolute file name representing the current working directory. If this string cannot be obtained, #f is returned.

Function: rename-file oldfilename newfilename

Renames the file specified by oldfilename to newfilename. If the renaming is successful, #t is returned. Otherwise, #f is returned.

Function: copy-file oldfilename newfilename

Copies the file specified by oldfilename to newfilename. If the copying is successful, #t is returned. Otherwise, #f is returned.

Function: chmod file mode

The function chmod sets the access permission bits for the file named by file to mode. The file argument may be a string containing the filename or a port open to the file.

chmod returns if successful, #f if not.

Function: utime pathname acctime modtime

Sets the file times associated with the file named pathname to have access time acctime and modification time modtime. utime returns if successful, #f if not.

Function: umask mode

The function umask sets the file creation mask of the current process to mask, and returns the previous value of the file creation mask.

Function: fileno port

Returns the integer file descriptor associated with the port port. If an error is detected, #f is returned.

Function: access pathname how

Returns #t if the file named by pathname can be accessed in the way specified by the how argument. The how argument can be the logior of the flags:

  1. File-exists?
  2. File-is-executable?
  3. File-is-writable?
  1. File-is-readable?

Or the how argument can be a string of 0 to 3 of the following characters in any order. The test performed is the and of the associated tests and file-exists?.

x

File-is-executable?

w

File-is-writable?

r

File-is-readable?

Function: execl command arg0 …
Function: execlp command arg0 …

Transfers control to program command called with arguments arg0 …. For execl, command must be an exact pathname of an executable file. execlp searches for command in the list of directories specified by the environment variable PATH. The convention is that arg0 is the same name as command.

If successful, this procedure does not return. Otherwise an error message is printed and the integer errno is returned.

Function: execv command arglist
Function: execvp command arglist

Like execl and execlp except that the set of arguments to command is arglist.

Function: putenv string

adds or removes definitions from the environment. If the string is of the form ‘NAME=VALUE’, the definition is added to the environment. Otherwise, the string is interpreted as the name of an environment variable, and any definition for this variable in the environment is removed.

Names of environment variables are case-sensitive and must not contain the character =. System-defined environment variables are invariably uppercase.

Putenv is used to set up the environment before calls to execl, execlp, execv, execvp, system, or open-pipe (see open-pipe).

To access environment variables, use getenv (see getenv in SLIB).


Next: , Previous: , Up: Packages   [Contents][Index]