change-directory chdir |
change-file-mode chmod |
change-file-owner chown |
create-directory mkdir |
create-fifo mkfifo |
create-pipe pipe |
create-session setsid |
create-symbolic-link link |
current-directory curdir |
current-effective-groupd-id getegid |
current-effective-user-id geteuid |
current-group-id getgid |
current-parent-id getppid |
current-process-id getpid |
current-user-id getuid |
delete-directory rmdir |
duplicate-fileno dup/dup2 |
_exit _exit |
file-close close |
file-access-time stat |
file-change-time stat |
file-modification-time stat |
file-execute-access? access |
file-open open |
file-lock fcntl |
file-position ftell/lseek |
file-read read |
file-read-access? access |
file-select select |
file-control fcntl |
file-stat stat |
file-test-lock fcntl |
file-truncate truncate/ftruncate |
file-unlock fcntl |
file-write write |
file-write-access? access |
get-groups getgroups |
get-host-name gethostname |
initialize-groups initgroups |
local-time->seconds mktime |
local-timezone-abbreviation localtime |
map-file-to-memory mmap |
open-input-file* fdopen |
open-output-file* fdopen |
open-input-pipe popen |
open-output-pipe popen |
port->fileno fileno |
process-execute execvp |
process-fork fork |
process-group-id getpgid |
process-signal kill |
process-wait waitpid |
close-input-pipe pclose |
close-output-pipe pclose |
read-symbolic-link readlink |
seconds->local-time localtime |
seconds->string ctime |
seconds->utc-time gmtime |
set-alarm! alarm |
set-buffering-mode! setvbuf |
set-file-position! fseek/seek |
set-groups! setgroups |
set-signal-mask! sigprocmask |
set-group-id! setgid |
set-process-group-id! setpgid |
set-user-id! setuid |
set-root-directory! chroot |
setenv setenv/putenv |
sleep sleep |
system-information uname |
terminal-name ttyname |
terminal-port? isatty |
time->string asctime |
unsetenv putenv |
unmap-file-from-memory munmap |
user-information getpwnam/getpwuid |
utc-time->seconds timegm |
@node Unit posix - Windows specific notes, , Unit posix - How Scheme procedures relate to UNIX C functions, Unit posix
@section Windows specific notes
@menu
* Unit posix - Windows specific notes - Procedure Changes::
* Unit posix - Windows specific notes - Unsupported Definitions::
* Unit posix - Windows specific notes - Additional Definitions::
* Unit posix - Windows specific notes - process-spawn::
@end menu
Use of UTF8 encoded strings is for pathnames is not supported. Windows uses a 16-bit UNICODE encoding with special system calls for wide-character support. Only single-byte string encoding can be used.
@node Unit posix - Windows specific notes - Procedure Changes, Unit posix - Windows specific notes - Unsupported Definitions, , Unit posix - Windows specific notes
@subsection Procedure Changes
Exceptions to the above procedure definitions.
@verbatim
[procedure] (create-pipe [MODE])
@end verbatim
The optional parameter @code{MODE}, default @code{open/binary | open/noinherit}. This can be @code{open/binary} or @code{open/text}, optionally or'ed with @code{open/noinherit}.
@verbatim
[procedure] (process-wait [PID [NOHANG]])
@end verbatim
@code{process-wait} always returns @code{#t} for a terminated process and only the exit status is available. (Windows does not provide signals as an interprocess communication method.)
@verbatim
[procedure] (process-execute PATHNAME [ARGUMENT-LIST [ENVIRONMENT-LIST [EXACT-FLAG]]])
[procedure] (process COMMAND ARGUMENT-LIST [ENVIRONMENT-LIST [EXACT-FLAG]])
[procedure] (process* COMMAND ARGUMENT-LIST [ENVIRONMENT-LIST [EXACT-FLAG]])
@end verbatim
The optional parameter @code{EXACT-FLAG}, default @code{#f}. When @code{#f} any argument string with embedded whitespace will be wrapped in quotes. When @code{#t} no such wrapping occurs.
@node Unit posix - Windows specific notes - Unsupported Definitions, Unit posix - Windows specific notes - Additional Definitions, Unit posix - Windows specific notes - Procedure Changes, Unit posix - Windows specific notes
@subsection Unsupported Definitions
The following definitions are not supported for native Windows builds (compiled with the Microsoft tools or with MinGW):
@verbatim
open/noctty open/nonblock open/fsync open/sync
perm/isvtx perm/isuid perm/isgid
file-select file-control
signal/... (except signal/term, signal/int, signal/fpe, signal/ill, signal/segv, signal/abrt, signal/break)
set-signal-mask! signal-mask signal-masked? signal-mask! signal-unmask!
user-information group-information get-groups set-groups! initialize-groups
errno/wouldblock
change-file-owner
current-user-id current-group-id current-effective-user-id current-effective-groupd-id
set-user-id! set-group-id!
create-session
process-group-id set-process-group-id!
create-symbolic-link read-symbolic-link
file-truncate
file-lock file-lock/blocking file-unlock file-test-lock
create-fifo fifo?
prot/...
map/...
map-file-to-memory unmap-file-from-memory memory-mapped-file-pointer memory-mapped-file?
set-alarm!
terminal-port? terminal-name
process-fork process-signal
parent-process-id
set-root-directory!
utc-time->seconds
@end verbatim
@node Unit posix - Windows specific notes - Additional Definitions, Unit posix - Windows specific notes - process-spawn, Unit posix - Windows specific notes - Unsupported Definitions, Unit posix - Windows specific notes
@subsection Additional Definitions
Only available for Windows
@itemize
@item open/noinherit
@end itemize
This variable is a mode value for @code{create-pipe}. Useful when spawning a child process.
@itemize
@item spawn/overlay
@item spawn/wait
@item spawn/nowait
@item spawn/nowaito
@item spawn/detach
@end itemize
These variables contains special flags that specify the exact semantics of @code{process-spawn}: @code{spawn/overlay} replaces the current process with the new one. @code{spawn/wait} suspends execution of the current process until the spawned process returns. @code{spawn/nowait} does the opposite (@code{spawn/nowaito} is identical, according to the Microsoft documentation) and runs the process asynchronously. @code{spawn/detach} runs the new process in the background, without being attached to a console.
@node Unit posix - Windows specific notes - process-spawn, , Unit posix - Windows specific notes - Additional Definitions, Unit posix - Windows specific notes
@subsection process-spawn
@verbatim
[procedure] (process-spawn MODE COMMAND [ARGUMENT-LIST [ENVIRONMENT-LIST [EXACT-FLAG]]])
@end verbatim
Creates and runs a new process with the given @code{COMMAND} filename and the optional @code{ARGUMENT-LIST} and @code{ENVIRONMENT-LIST}. @code{MODE} specifies how exactly the process should be executed and must be one or more of the @code{spawn/...} flags defined above.
The @code{EXACT-FLAG}, default @code{#f}, controls quote-wrapping of argument strings. When @code{#t} quote-wrapping is not performed.
Returns:
@itemize
@item the exit status when synchronous
@item the PID when asynchronous
@item -1 when failure
@end itemize
Previous: @ref{Unit srfi-18, Unit srfi-18}
Next: @ref{Unit utils, Unit utils}
@node Unit utils, Unit tcp, Unit posix, Top
@chapter Unit utils
@menu
* Unit utils - Environment Query::
* Unit utils - Pathname operations::
* Unit utils - Temporary files::
* Unit utils - Deleting a file without signalling an error::
* Unit utils - Iterating over input lines and files::
* Unit utils - Executing shell commands with formatstring and error checking::
* Unit utils - Reading a file's contents::
* Unit utils - Funky ports::
* Unit utils - Miscellaneous handy things::
@end menu
This unit contains file/pathname oriented procedures, apropos, plus acts as a "grab bag" for procedures without a good home, and which don't have to be available by default (as compared to the @ref{Unit extras, extras} unit).
This unit uses the @code{extras} and @code{regex} units.
@node Unit utils - Environment Query, Unit utils - Pathname operations, , Unit utils
@section Environment Query
@menu
* Unit utils - Environment Query - apropos::
* Unit utils - Environment Query - apropos-list::
@end menu
@node Unit utils - Environment Query - apropos, Unit utils - Environment Query - apropos-list, , Unit utils - Environment Query
@subsection apropos
@verbatim
[procedure] (apropos SYMBOL-PATTERN [ENVIRONMENT] [#:MACROS?])
@end verbatim
Displays symbols & type matching @code{SYMBOL-PATTERN} in the @code{ENVIRONMENT} on the @code{(current-output-port)}.
@table @b
@item @code{SYMBOL-PATTERN}
A symbol, string, or regex. When symbol or string substring matching is performed.
@item @code{ENVIRONMENT}
An environment. When missing the @code{(interaction-environment)} is assumed.
@item @code{#:MACROS?}
Keyword argument. A boolean. Include macro symbols? When missing @code{#f} is assumed.
@end table
@node Unit utils - Environment Query - apropos-list, , Unit utils - Environment Query - apropos, Unit utils - Environment Query
@subsection apropos-list
@verbatim
[procedure] (apropos-list SYMBOL-PATTERN [ENVIRONMENT] [#:MACROS?])
@end verbatim
Like @code{apropos} but returns a list of matching symbols.
@node Unit utils - Pathname operations, Unit utils - Temporary files, Unit utils - Environment Query, Unit utils
@section Pathname operations
@menu
* Unit utils - Pathname operations - absolute-pathname?::
* Unit utils - Pathname operations - decompose-pathname::
* Unit utils - Pathname operations - make-pathname::
* Unit utils - Pathname operations - make-absolute-pathname::
* Unit utils - Pathname operations - pathname-directory::
* Unit utils - Pathname operations - pathname-file::
* Unit utils - Pathname operations - pathname-extension::
* Unit utils - Pathname operations - pathname-replace-directory::
* Unit utils - Pathname operations - pathname-replace-file::
* Unit utils - Pathname operations - pathname-replace-extension::
* Unit utils - Pathname operations - pathname-strip-directory::
* Unit utils - Pathname operations - pathname-strip-extension::
* Unit utils - Pathname operations - directory-null?::
@end menu
@node Unit utils - Pathname operations - absolute-pathname?, Unit utils - Pathname operations - decompose-pathname, , Unit utils - Pathname operations
@subsection absolute-pathname?
@verbatim
[procedure] (absolute-pathname? PATHNAME)
@end verbatim
Returns @code{#t} if the string @code{PATHNAME} names an absolute pathname, and returns @code{#f} otherwise.
@node Unit utils - Pathname operations - decompose-pathname, Unit utils - Pathname operations - make-pathname, Unit utils - Pathname operations - absolute-pathname?, Unit utils - Pathname operations
@subsection decompose-pathname
@verbatim
[procedure] (decompose-pathname PATHNAME)
@end verbatim
Returns three values: the directory-, filename- and extension-components of the file named by the string @code{PATHNAME}. For any component that is not contained in @code{PATHNAME}, @code{#f} is returned.
@node Unit utils - Pathname operations - make-pathname, Unit utils - Pathname operations - make-absolute-pathname, Unit utils - Pathname operations - decompose-pathname, Unit utils - Pathname operations
@subsection make-pathname
@node Unit utils - Pathname operations - make-absolute-pathname, Unit utils - Pathname operations - pathname-directory, Unit utils - Pathname operations - make-pathname, Unit utils - Pathname operations
@subsection make-absolute-pathname
@verbatim
[procedure] (make-pathname DIRECTORY FILENAME [EXTENSION [SEPARATOR]])
[procedure] (make-absolute-pathname DIRECTORY FILENAME [EXTENSION [SEPARATOR]])
@end verbatim
Returns a string that names the file with the components @code{DIRECTORY, FILENAME} and (optionally) @code{EXTENSION} with @code{SEPARATOR} being the directory separation indicator (usually @code{/} on UNIX systems and @code{\} on Windows, defaulting to whatever platform this is running on). @code{DIRECTORY} can be @code{#f} (meaning no directory component), a string or a list of strings. @code{FILENAME} and @code{EXTENSION} should be strings or @code{#f}. @code{make-absolute-pathname} returns always an absolute pathname.
@node Unit utils - Pathname operations - pathname-directory, Unit utils - Pathname operations - pathname-file, Unit utils - Pathname operations - make-absolute-pathname, Unit utils - Pathname operations
@subsection pathname-directory
@verbatim
[procedure] (pathname-directory PATHNAME)
@end verbatim
@node Unit utils - Pathname operations - pathname-file, Unit utils - Pathname operations - pathname-extension, Unit utils - Pathname operations - pathname-directory, Unit utils - Pathname operations
@subsection pathname-file
@verbatim
[procedure] (pathname-file PATHNAME)
@end verbatim
@node Unit utils - Pathname operations - pathname-extension, Unit utils - Pathname operations - pathname-replace-directory, Unit utils - Pathname operations - pathname-file, Unit utils - Pathname operations
@subsection pathname-extension
@verbatim
[procedure] (pathname-extension PATHNAME)
@end verbatim
Accessors for the components of @code{PATHNAME}. If the pathname does not contain the accessed component, then @code{#f} is returned.
@node Unit utils - Pathname operations - pathname-replace-directory, Unit utils - Pathname operations - pathname-replace-file, Unit utils - Pathname operations - pathname-extension, Unit utils - Pathname operations
@subsection pathname-replace-directory
@verbatim
[procedure] (pathname-replace-directory PATHNAME DIRECTORY)
@end verbatim
@node Unit utils - Pathname operations - pathname-replace-file, Unit utils - Pathname operations - pathname-replace-extension, Unit utils - Pathname operations - pathname-replace-directory, Unit utils - Pathname operations
@subsection pathname-replace-file
@verbatim
[procedure] (pathname-replace-file PATHNAME FILENAME)
@end verbatim
@node Unit utils - Pathname operations - pathname-replace-extension, Unit utils - Pathname operations - pathname-strip-directory, Unit utils - Pathname operations - pathname-replace-file, Unit utils - Pathname operations
@subsection pathname-replace-extension
@verbatim
[procedure] (pathname-replace-extension PATHNAME EXTENSION)
@end verbatim
Return a new pathname with the specified component of @code{PATHNAME} replaced by a new value.
@node Unit utils - Pathname operations - pathname-strip-directory, Unit utils - Pathname operations - pathname-strip-extension, Unit utils - Pathname operations - pathname-replace-extension, Unit utils - Pathname operations
@subsection pathname-strip-directory
@verbatim
[procedure] (pathname-strip-directory PATHNAME)
@end verbatim
@node Unit utils - Pathname operations - pathname-strip-extension, Unit utils - Pathname operations - directory-null?, Unit utils - Pathname operations - pathname-strip-directory, Unit utils - Pathname operations
@subsection pathname-strip-extension
@verbatim
[procedure] (pathname-strip-extension PATHNAME)
@end verbatim
Return a new pathname with the specified component of @code{PATHNAME} stripped.
@node Unit utils - Pathname operations - directory-null?, , Unit utils - Pathname operations - pathname-strip-extension, Unit utils - Pathname operations
@subsection directory-null?
@verbatim
[procedure] (directory-null? DIRECTORY)
@end verbatim
Does the @code{DIRECTORY} consist only of path separators and the period?
@code{DIRECTORY} may be a string or a list of strings.
@node Unit utils - Temporary files, Unit utils - Deleting a file without signalling an error, Unit utils - Pathname operations, Unit utils
@section Temporary files
@menu
* Unit utils - Temporary files - create-temporary-file::
@end menu
@node Unit utils - Temporary files - create-temporary-file, , , Unit utils - Temporary files
@subsection create-temporary-file
@verbatim
[procedure] (create-temporary-file [EXTENSION])
@end verbatim
Creates an empty temporary file and returns its pathname. If @code{EXTENSION} is not given, then @code{.tmp} is used. If the environment variable @code{TMPDIR, TEMP} or @code{TMP} is set, then the pathname names a file in that directory.
@node Unit utils - Deleting a file without signalling an error, Unit utils - Iterating over input lines and files, Unit utils - Temporary files, Unit utils
@section Deleting a file without signalling an error
@menu
* Unit utils - Deleting a file without signalling an error - delete-file*::
@end menu
@node Unit utils - Deleting a file without signalling an error - delete-file*, , , Unit utils - Deleting a file without signalling an error
@subsection delete-file*
@verbatim
[procedure] (delete-file* FILENAME)
@end verbatim
If the file @code{FILENAME} exists, it is deleted and @code{#t} is returned. If the file does not exist, nothing happens and @code{#f} is returned.
@node Unit utils - Iterating over input lines and files, Unit utils - Executing shell commands with formatstring and error checking, Unit utils - Deleting a file without signalling an error, Unit utils
@section Iterating over input lines and files
@menu
* Unit utils - Iterating over input lines and files - for-each-line::
* Unit utils - Iterating over input lines and files - for-each-argv-line::
* Unit utils - Iterating over input lines and files - port-for-each::
* Unit utils - Iterating over input lines and files - port-map::
* Unit utils - Iterating over input lines and files - port-fold::
@end menu
@node Unit utils - Iterating over input lines and files - for-each-line, Unit utils - Iterating over input lines and files - for-each-argv-line, , Unit utils - Iterating over input lines and files
@subsection for-each-line
@verbatim
[procedure] (for-each-line PROCEDURE [PORT])
@end verbatim
Calls @code{PROCEDURE} for each line read from @code{PORT} (which defaults to the value of @code{(current-input-port)}. The argument passed to @code{PORCEDURE} is a string with the contents of the line, excluding any line-terminators. When all input has been read from the port, @code{for-each-line} returns some unspecified value.
@node Unit utils - Iterating over input lines and files - for-each-argv-line, Unit utils - Iterating over input lines and files - port-for-each, Unit utils - Iterating over input lines and files - for-each-line, Unit utils - Iterating over input lines and files
@subsection for-each-argv-line
@verbatim
[procedure] (for-each-argv-line PROCEDURE)
@end verbatim
Opens each file listed on the command line in order, passing one line at a time into @code{PROCEDURE}. The filename @code{-} is interpreted as @code{(current-input-port)}. If no arguments are given on the command line it again uses the value of @code{(current-input-port)}. During execution of @code{PROCEDURE}, the current input port will be correctly bound to the current input source.
This code will act as a simple Unix cat(1) command: