(File System): In access?, reword a bit, clarify real
[bpt/guile.git] / doc / ref / posix.texi
CommitLineData
a0e07ba4 1@node POSIX
7403e409 2@chapter @acronym{POSIX} System Calls and Networking
a0e07ba4
NJ
3
4@menu
5* Conventions:: Conventions employed by the POSIX interface.
6* Ports and File Descriptors:: Scheme ``ports'' and Unix file descriptors
7 have different representations.
8* File System:: stat, chown, chmod, etc.
9* User Information:: Retrieving a user's GECOS (/etc/passwd) entry.
10* Time:: gettimeofday, localtime, strftime, etc.
11* Runtime Environment:: Accessing and modifying Guile's environment.
12* Processes:: getuid, getpid, etc.
13* Signals:: sigaction, kill, pause, alarm, setitimer, etc.
14* Terminals and Ptys:: ttyname, tcsetpgrp, etc.
15* Pipes:: Communicating data between processes.
16* Networking:: gethostbyaddr, getnetent, socket, bind, listen.
17* System Identification:: Obtaining information about the system.
18* Locales:: setlocale, etc.
5f378d17 19* Encryption::
a0e07ba4
NJ
20@end menu
21
22@node Conventions
7403e409 23@section @acronym{POSIX} Interface Conventions
a0e07ba4
NJ
24
25These interfaces provide access to operating system facilities.
26They provide a simple wrapping around the underlying C interfaces
27to make usage from Scheme more convenient. They are also used
7403e409 28to implement the Guile port of scsh (@pxref{The Scheme shell (scsh)}).
a0e07ba4
NJ
29
30Generally there is a single procedure for each corresponding Unix
31facility. There are some exceptions, such as procedures implemented for
32speed and convenience in Scheme with no primitive Unix equivalent,
7403e409 33e.g.@: @code{copy-file}.
a0e07ba4
NJ
34
35The interfaces are intended as far as possible to be portable across
36different versions of Unix. In some cases procedures which can't be
37implemented on particular systems may become no-ops, or perform limited
38actions. In other cases they may throw errors.
39
40General naming conventions are as follows:
41
42@itemize @bullet
43@item
44The Scheme name is often identical to the name of the underlying Unix
45facility.
46@item
47Underscores in Unix procedure names are converted to hyphens.
48@item
85a9b4ed 49Procedures which destructively modify Scheme data have exclamation
a0e07ba4
NJ
50marks appended, e.g., @code{recv!}.
51@item
52Predicates (returning only @code{#t} or @code{#f}) have question marks
53appended, e.g., @code{access?}.
54@item
55Some names are changed to avoid conflict with dissimilar interfaces
56defined by scsh, e.g., @code{primitive-fork}.
57@item
58Unix preprocessor names such as @code{EPERM} or @code{R_OK} are converted
59to Scheme variables of the same name (underscores are not replaced
60with hyphens).
61@end itemize
62
63Unexpected conditions are generally handled by raising exceptions.
64There are a few procedures which return a special value if they don't
65succeed, e.g., @code{getenv} returns @code{#f} if it the requested
66string is not found in the environment. These cases are noted in
67the documentation.
68
7403e409 69For ways to deal with exceptions, see @ref{Exceptions}.
a0e07ba4 70
7403e409 71Errors which the C library would report by returning a null pointer or
a0e07ba4
NJ
72through some other means are reported by raising a @code{system-error}
73exception. The value of the Unix @code{errno} variable is available
74in the data passed by the exception.
75
76It can be extracted with the function @code{system-error-errno}:
77
78@example
79(catch
80 'system-error
81 (lambda ()
82 (mkdir "/this-ought-to-fail-if-I'm-not-root"))
83 (lambda stuff
84 (let ((errno (system-error-errno stuff)))
85 (cond
86 ((= errno EACCES)
87 (display "You're not allowed to do that."))
88 ((= errno EEXIST)
89 (display "Already exists."))
90 (#t
91 (display (strerror errno))))
92 (newline))))
93@end example
94
95@node Ports and File Descriptors
96@section Ports and File Descriptors
97
98Conventions generally follow those of scsh, @ref{The Scheme shell (scsh)}.
99
100File ports are implemented using low-level operating system I/O
7403e409
NJ
101facilities, with optional buffering to improve efficiency; see
102@ref{File Ports}.
a0e07ba4
NJ
103
104Note that some procedures (e.g., @code{recv!}) will accept ports as
105arguments, but will actually operate directly on the file descriptor
106underlying the port. Any port buffering is ignored, including the
107buffer which implements @code{peek-char} and @code{unread-char}.
108
109The @code{force-output} and @code{drain-input} procedures can be used
110to clear the buffers.
111
112Each open file port has an associated operating system file descriptor.
113File descriptors are generally not useful in Scheme programs; however
114they may be needed when interfacing with foreign code and the Unix
115environment.
116
117A file descriptor can be extracted from a port and a new port can be
118created from a file descriptor. However a file descriptor is just an
85a9b4ed 119integer and the garbage collector doesn't recognize it as a reference
a0e07ba4
NJ
120to the port. If all other references to the port were dropped, then
121it's likely that the garbage collector would free the port, with the
122side-effect of closing the file descriptor prematurely.
123
124To assist the programmer in avoiding this problem, each port has an
7403e409 125associated @dfn{revealed count} which can be used to keep track of how many
a0e07ba4
NJ
126times the underlying file descriptor has been stored in other places.
127If a port's revealed count is greater than zero, the file descriptor
85a9b4ed 128will not be closed when the port is garbage collected. A programmer
a0e07ba4
NJ
129can therefore ensure that the revealed count will be greater than
130zero if the file descriptor is needed elsewhere.
131
7403e409 132For the simple case where a file descriptor is ``imported'' once to become
a0e07ba4
NJ
133a port, it does not matter if the file descriptor is closed when the
134port is garbage collected. There is no need to maintain a revealed
7403e409 135count. Likewise when ``exporting'' a file descriptor to the external
a0e07ba4
NJ
136environment, setting the revealed count is not required provided the
137port is kept open (i.e., is pointed to by a live Scheme binding) while
138the file descriptor is in use.
139
7403e409
NJ
140To correspond with traditional Unix behaviour, three file descriptors
141(0, 1, and 2) are automatically imported when a program starts up and
142assigned to the initial values of the current/standard input, output,
143and error ports, respectively. The revealed count for each is
144initially set to one, so that dropping references to one of these
145ports will not result in its garbage collection: it could be retrieved
146with @code{fdopen} or @code{fdes->ports}.
a0e07ba4 147
8f85c0c6
NJ
148@deffn {Scheme Procedure} port-revealed port
149@deffnx {C Function} scm_port_revealed (port)
a0e07ba4
NJ
150Return the revealed count for @var{port}.
151@end deffn
152
8f85c0c6
NJ
153@deffn {Scheme Procedure} set-port-revealed! port rcount
154@deffnx {C Function} scm_set_port_revealed_x (port, rcount)
7403e409 155Sets the revealed count for a @var{port} to @var{rcount}.
a0e07ba4
NJ
156The return value is unspecified.
157@end deffn
158
8f85c0c6
NJ
159@deffn {Scheme Procedure} fileno port
160@deffnx {C Function} scm_fileno (port)
a0e07ba4
NJ
161Return the integer file descriptor underlying @var{port}. Does
162not change its revealed count.
163@end deffn
164
8f85c0c6 165@deffn {Scheme Procedure} port->fdes port
a0e07ba4
NJ
166Returns the integer file descriptor underlying @var{port}. As a
167side effect the revealed count of @var{port} is incremented.
168@end deffn
169
8f85c0c6
NJ
170@deffn {Scheme Procedure} fdopen fdes modes
171@deffnx {C Function} scm_fdopen (fdes, modes)
7403e409
NJ
172Return a new port based on the file descriptor @var{fdes}. Modes are
173given by the string @var{modes}. The revealed count of the port is
174initialized to zero. The @var{modes} string is the same as that
175accepted by @code{open-file} (@pxref{File Ports, open-file}).
a0e07ba4
NJ
176@end deffn
177
8f85c0c6
NJ
178@deffn {Scheme Procedure} fdes->ports fd
179@deffnx {C Function} scm_fdes_to_ports (fd)
a0e07ba4
NJ
180Return a list of existing ports which have @var{fdes} as an
181underlying file descriptor, without changing their revealed
182counts.
183@end deffn
184
8f85c0c6 185@deffn {Scheme Procedure} fdes->inport fdes
a0e07ba4
NJ
186Returns an existing input port which has @var{fdes} as its underlying file
187descriptor, if one exists, and increments its revealed count.
188Otherwise, returns a new input port with a revealed count of 1.
189@end deffn
190
8f85c0c6 191@deffn {Scheme Procedure} fdes->outport fdes
a0e07ba4
NJ
192Returns an existing output port which has @var{fdes} as its underlying file
193descriptor, if one exists, and increments its revealed count.
194Otherwise, returns a new output port with a revealed count of 1.
195@end deffn
196
8f85c0c6
NJ
197@deffn {Scheme Procedure} primitive-move->fdes port fd
198@deffnx {C Function} scm_primitive_move_to_fdes (port, fd)
a0e07ba4
NJ
199Moves the underlying file descriptor for @var{port} to the integer
200value @var{fdes} without changing the revealed count of @var{port}.
201Any other ports already using this descriptor will be automatically
202shifted to new descriptors and their revealed counts reset to zero.
203The return value is @code{#f} if the file descriptor already had the
204required value or @code{#t} if it was moved.
205@end deffn
206
8f85c0c6 207@deffn {Scheme Procedure} move->fdes port fdes
a0e07ba4
NJ
208Moves the underlying file descriptor for @var{port} to the integer
209value @var{fdes} and sets its revealed count to one. Any other ports
210already using this descriptor will be automatically
211shifted to new descriptors and their revealed counts reset to zero.
212The return value is unspecified.
213@end deffn
214
8f85c0c6 215@deffn {Scheme Procedure} release-port-handle port
a0e07ba4
NJ
216Decrements the revealed count for a port.
217@end deffn
218
8f85c0c6
NJ
219@deffn {Scheme Procedure} fsync object
220@deffnx {C Function} scm_fsync (object)
a0e07ba4
NJ
221Copies any unwritten data for the specified output file descriptor to disk.
222If @var{port/fd} is a port, its buffer is flushed before the underlying
223file descriptor is fsync'd.
224The return value is unspecified.
225@end deffn
226
8f85c0c6
NJ
227@deffn {Scheme Procedure} open path flags [mode]
228@deffnx {C Function} scm_open (path, flags, mode)
a0e07ba4
NJ
229Open the file named by @var{path} for reading and/or writing.
230@var{flags} is an integer specifying how the file should be opened.
7403e409
NJ
231@var{mode} is an integer specifying the permission bits of the file,
232if it needs to be created, before the umask (@pxref{Processes}) is
233applied. The default is 666 (Unix itself has no default).
a0e07ba4
NJ
234
235@var{flags} can be constructed by combining variables using @code{logior}.
236Basic flags are:
237
238@defvar O_RDONLY
239Open the file read-only.
240@end defvar
241@defvar O_WRONLY
242Open the file write-only.
243@end defvar
244@defvar O_RDWR
245Open the file read/write.
246@end defvar
247@defvar O_APPEND
248Append to the file instead of truncating.
249@end defvar
250@defvar O_CREAT
251Create the file if it does not already exist.
252@end defvar
253
7403e409 254@xref{File Status Flags,,,libc,The GNU C Library Reference Manual},
a0e07ba4
NJ
255for additional flags.
256@end deffn
257
8f85c0c6
NJ
258@deffn {Scheme Procedure} open-fdes path flags [mode]
259@deffnx {C Function} scm_open_fdes (path, flags, mode)
a0e07ba4
NJ
260Similar to @code{open} but return a file descriptor instead of
261a port.
262@end deffn
263
8f85c0c6
NJ
264@deffn {Scheme Procedure} close fd_or_port
265@deffnx {C Function} scm_close (fd_or_port)
7403e409 266Similar to @code{close-port} (@pxref{Closing, close-port}),
8f85c0c6
NJ
267but also works on file descriptors. A side
268effect of closing a file descriptor is that any ports using that file
269descriptor are moved to a different file descriptor and have
270their revealed counts set to zero.
a0e07ba4
NJ
271@end deffn
272
8f85c0c6
NJ
273@deffn {Scheme Procedure} close-fdes fd
274@deffnx {C Function} scm_close_fdes (fd)
7403e409
NJ
275A simple wrapper for the @code{close} system call. Close file
276descriptor @var{fd}, which must be an integer. Unlike @code{close},
277the file descriptor will be closed even if a port is using it. The
278return value is unspecified.
a0e07ba4
NJ
279@end deffn
280
8f85c0c6 281@deffn {Scheme Procedure} unread-char char [port]
c16da59f 282@deffnx {C Function} scm_unread_char (char, port)
7403e409
NJ
283Place @var{char} in @var{port} so that it will be read by the next
284read operation on that port. If called multiple times, the unread
285characters will be read again in ``last-in, first-out'' order (i.e.@:
286a stack). If @var{port} is not supplied, the current input port is
287used.
a0e07ba4
NJ
288@end deffn
289
8f85c0c6 290@deffn {Scheme Procedure} unread-string str port
a0e07ba4
NJ
291Place the string @var{str} in @var{port} so that its characters will be
292read in subsequent read operations. If called multiple times, the
293unread characters will be read again in last-in first-out order. If
294@var{port} is not supplied, the current-input-port is used.
295@end deffn
296
8f85c0c6
NJ
297@deffn {Scheme Procedure} pipe
298@deffnx {C Function} scm_pipe ()
a0e07ba4 299Return a newly created pipe: a pair of ports which are linked
7403e409
NJ
300together on the local machine. The @acronym{CAR} is the input
301port and the @acronym{CDR} is the output port. Data written (and
a0e07ba4
NJ
302flushed) to the output port can be read from the input port.
303Pipes are commonly used for communication with a newly forked
304child process. The need to flush the output port can be
305avoided by making it unbuffered using @code{setvbuf}.
306
c6ba64cd
KR
307@defvar PIPE_BUF
308A write of up to @code{PIPE_BUF} many bytes to a pipe is atomic,
309meaning when done it goes into the pipe instantaneously and as a
310contiguous block (@pxref{Pipe Atomicity,, Atomicity of Pipe I/O, libc,
311The GNU C Library Reference Manual}).
312@end defvar
313
314Note that the output port is likely to block if too much data has been
315written but not yet read from the input port. Typically the capacity
316is @code{PIPE_BUF} bytes.
a0e07ba4
NJ
317@end deffn
318
319The next group of procedures perform a @code{dup2}
320system call, if @var{newfd} (an
321integer) is supplied, otherwise a @code{dup}. The file descriptor to be
322duplicated can be supplied as an integer or contained in a port. The
323type of value returned varies depending on which procedure is used.
324
325All procedures also have the side effect when performing @code{dup2} that any
326ports using @var{newfd} are moved to a different file descriptor and have
327their revealed counts set to zero.
328
8f85c0c6
NJ
329@deffn {Scheme Procedure} dup->fdes fd_or_port [fd]
330@deffnx {C Function} scm_dup_to_fdes (fd_or_port, fd)
a0e07ba4
NJ
331Return a new integer file descriptor referring to the open file
332designated by @var{fd_or_port}, which must be either an open
333file port or a file descriptor.
334@end deffn
335
8f85c0c6 336@deffn {Scheme Procedure} dup->inport port/fd [newfd]
a0e07ba4
NJ
337Returns a new input port using the new file descriptor.
338@end deffn
339
8f85c0c6 340@deffn {Scheme Procedure} dup->outport port/fd [newfd]
a0e07ba4
NJ
341Returns a new output port using the new file descriptor.
342@end deffn
343
8f85c0c6 344@deffn {Scheme Procedure} dup port/fd [newfd]
a0e07ba4
NJ
345Returns a new port if @var{port/fd} is a port, with the same mode as the
346supplied port, otherwise returns an integer file descriptor.
347@end deffn
348
8f85c0c6 349@deffn {Scheme Procedure} dup->port port/fd mode [newfd]
a0e07ba4
NJ
350Returns a new port using the new file descriptor. @var{mode} supplies a
351mode string for the port (@pxref{File Ports, open-file}).
352@end deffn
353
8f85c0c6 354@deffn {Scheme Procedure} duplicate-port port modes
a0e07ba4
NJ
355Returns a new port which is opened on a duplicate of the file
356descriptor underlying @var{port}, with mode string @var{modes}
357as for @ref{File Ports, open-file}. The two ports
358will share a file position and file status flags.
359
360Unexpected behaviour can result if both ports are subsequently used
361and the original and/or duplicate ports are buffered.
362The mode string can include @code{0} to obtain an unbuffered duplicate
363port.
364
365This procedure is equivalent to @code{(dup->port @var{port} @var{modes})}.
366@end deffn
367
8f85c0c6
NJ
368@deffn {Scheme Procedure} redirect-port old new
369@deffnx {C Function} scm_redirect_port (old, new)
a0e07ba4
NJ
370This procedure takes two ports and duplicates the underlying file
371descriptor from @var{old-port} into @var{new-port}. The
372current file descriptor in @var{new-port} will be closed.
373After the redirection the two ports will share a file position
374and file status flags.
375
376The return value is unspecified.
377
378Unexpected behaviour can result if both ports are subsequently used
379and the original and/or duplicate ports are buffered.
380
381This procedure does not have any side effects on other ports or
382revealed counts.
383@end deffn
384
8f85c0c6
NJ
385@deffn {Scheme Procedure} dup2 oldfd newfd
386@deffnx {C Function} scm_dup2 (oldfd, newfd)
a0e07ba4
NJ
387A simple wrapper for the @code{dup2} system call.
388Copies the file descriptor @var{oldfd} to descriptor
389number @var{newfd}, replacing the previous meaning
390of @var{newfd}. Both @var{oldfd} and @var{newfd} must
391be integers.
7403e409 392Unlike for @code{dup->fdes} or @code{primitive-move->fdes}, no attempt
a0e07ba4
NJ
393is made to move away ports which are using @var{newfd}.
394The return value is unspecified.
395@end deffn
396
8f85c0c6 397@deffn {Scheme Procedure} port-mode port
a0e07ba4
NJ
398Return the port modes associated with the open port @var{port}.
399These will not necessarily be identical to the modes used when
7403e409 400the port was opened, since modes such as ``append'' which are
a0e07ba4
NJ
401used only during port creation are not retained.
402@end deffn
403
8f85c0c6 404@deffn {Scheme Procedure} port-for-each proc
c2e15516
MV
405@deffnx {C Function} scm_port_for_each (SCM proc)
406@deffnx {C Function} scm_c_port_for_each (void (*proc)(void *, SCM), void *data)
a0e07ba4 407Apply @var{proc} to each port in the Guile port table
7403e409 408(FIXME: what is the Guile port table?)
a0e07ba4 409in turn. The return value is unspecified. More specifically,
7403e409
NJ
410@var{proc} is applied exactly once to every port that exists in the
411system at the time @code{port-for-each} is invoked. Changes to the
412port table while @code{port-for-each} is running have no effect as far
413as @code{port-for-each} is concerned.
c2e15516
MV
414
415The C function @code{scm_port_for_each} takes a Scheme procedure
416encoded as a @code{SCM} value, while @code{scm_c_port_for_each} takes
417a pointer to a C function and passes along a arbitrary @var{data}
418cookie.
a0e07ba4
NJ
419@end deffn
420
8f85c0c6
NJ
421@deffn {Scheme Procedure} setvbuf port mode [size]
422@deffnx {C Function} scm_setvbuf (port, mode, size)
a0e07ba4 423Set the buffering mode for @var{port}. @var{mode} can be:
2ce02471
NJ
424
425@defvar _IONBF
a0e07ba4 426non-buffered
2ce02471
NJ
427@end defvar
428@defvar _IOLBF
a0e07ba4 429line buffered
2ce02471
NJ
430@end defvar
431@defvar _IOFBF
a0e07ba4
NJ
432block buffered, using a newly allocated buffer of @var{size} bytes.
433If @var{size} is omitted, a default size will be used.
2ce02471 434@end defvar
a0e07ba4
NJ
435@end deffn
436
8f85c0c6
NJ
437@deffn {Scheme Procedure} fcntl object cmd [value]
438@deffnx {C Function} scm_fcntl (object, cmd, value)
a0e07ba4
NJ
439Apply @var{command} to the specified file descriptor or the underlying
440file descriptor of the specified port. @var{value} is an optional
441integer argument.
442
443Values for @var{command} are:
444
2ce02471 445@defvar F_DUPFD
a0e07ba4 446Duplicate a file descriptor
2ce02471
NJ
447@end defvar
448@defvar F_GETFD
a0e07ba4 449Get flags associated with the file descriptor.
2ce02471
NJ
450@end defvar
451@defvar F_SETFD
a0e07ba4 452Set flags associated with the file descriptor to @var{value}.
2ce02471
NJ
453@end defvar
454@defvar F_GETFL
a0e07ba4 455Get flags associated with the open file.
2ce02471
NJ
456@end defvar
457@defvar F_SETFL
a0e07ba4 458Set flags associated with the open file to @var{value}
2ce02471
NJ
459@end defvar
460@defvar F_GETOWN
a0e07ba4 461Get the process ID of a socket's owner, for @code{SIGIO} signals.
2ce02471
NJ
462@end defvar
463@defvar F_SETOWN
a0e07ba4 464Set the process that owns a socket to @var{value}, for @code{SIGIO} signals.
2ce02471
NJ
465@end defvar
466@defvar FD_CLOEXEC
7403e409 467The value used to indicate the ``close on exec'' flag with @code{F_GETFL} or
a0e07ba4 468@code{F_SETFL}.
2ce02471 469@end defvar
a0e07ba4
NJ
470@end deffn
471
8f85c0c6
NJ
472@deffn {Scheme Procedure} flock file operation
473@deffnx {C Function} scm_flock (file, operation)
a0e07ba4
NJ
474Apply or remove an advisory lock on an open file.
475@var{operation} specifies the action to be done:
2ce02471
NJ
476
477@defvar LOCK_SH
a0e07ba4
NJ
478Shared lock. More than one process may hold a shared lock
479for a given file at a given time.
2ce02471
NJ
480@end defvar
481@defvar LOCK_EX
a0e07ba4
NJ
482Exclusive lock. Only one process may hold an exclusive lock
483for a given file at a given time.
2ce02471
NJ
484@end defvar
485@defvar LOCK_UN
a0e07ba4 486Unlock the file.
2ce02471
NJ
487@end defvar
488@defvar LOCK_NB
a0e07ba4
NJ
489Don't block when locking. May be specified by bitwise OR'ing
490it to one of the other operations.
2ce02471
NJ
491@end defvar
492
a0e07ba4 493The return value is not specified. @var{file} may be an open
85a9b4ed 494file descriptor or an open file descriptor port.
a0e07ba4
NJ
495@end deffn
496
8f85c0c6
NJ
497@deffn {Scheme Procedure} select reads writes excepts [secs [usecs]]
498@deffnx {C Function} scm_select (reads, writes, excepts, secs, usecs)
a0e07ba4 499This procedure has a variety of uses: waiting for the ability
85a9b4ed 500to provide input, accept output, or the existence of
a0e07ba4
NJ
501exceptional conditions on a collection of ports or file
502descriptors, or waiting for a timeout to occur.
503It also returns if interrupted by a signal.
504
505@var{reads}, @var{writes} and @var{excepts} can be lists or
506vectors, with each member a port or a file descriptor.
507The value returned is a list of three corresponding
508lists or vectors containing only the members which meet the
509specified requirement. The ability of port buffers to
510provide input or accept output is taken into account.
511Ordering of the input lists or vectors is not preserved.
512
513The optional arguments @var{secs} and @var{usecs} specify the
514timeout. Either @var{secs} can be specified alone, as
515either an integer or a real number, or both @var{secs} and
516@var{usecs} can be specified as integers, in which case
517@var{usecs} is an additional timeout expressed in
518microseconds. If @var{secs} is omitted or is @code{#f} then
519select will wait for as long as it takes for one of the other
520conditions to be satisfied.
521
522The scsh version of @code{select} differs as follows:
523Only vectors are accepted for the first three arguments.
524The @var{usecs} argument is not supported.
525Multiple values are returned instead of a list.
526Duplicates in the input vectors appear only once in output.
527An additional @code{select!} interface is provided.
528@end deffn
529
530@node File System
531@section File System
532
533These procedures allow querying and setting file system attributes
534(such as owner,
535permissions, sizes and types of files); deleting, copying, renaming and
536linking files; creating and removing directories and querying their
537contents; syncing the file system and creating special files.
538
8f85c0c6
NJ
539@deffn {Scheme Procedure} access? path how
540@deffnx {C Function} scm_access (path, how)
ad1c1f18
KR
541Test accessibility of a file under the real UID and GID of the calling
542process. The return is @code{#t} if @var{path} exists and the
543permissions requested by @var{how} are all allowed, or @code{#f} if
544not.
a0e07ba4 545
ad1c1f18
KR
546@var{how} is an integer which is one of the following values, or a
547bitwise-OR (@code{logior}) of multiple values.
a0e07ba4
NJ
548
549@defvar R_OK
ad1c1f18 550Test for read permission.
a0e07ba4
NJ
551@end defvar
552@defvar W_OK
ad1c1f18 553Test for write permission.
a0e07ba4
NJ
554@end defvar
555@defvar X_OK
ad1c1f18 556Test for execute permission.
a0e07ba4
NJ
557@end defvar
558@defvar F_OK
ad1c1f18
KR
559Test for existence of the file. This is implied by each of the other
560tests, so there's no need to combine it with them.
a0e07ba4 561@end defvar
ad1c1f18
KR
562
563It's important to note that @code{access?} does not simply indicate
564what will happen on attempting to read or write a file. In normal
565circumstances it does, but in a set-UID or set-GID program it doesn't
566because @code{access?} tests the real ID, whereas an open or execute
567attempt uses the effective ID.
568
569A program which will never run set-UID/GID can ignore the difference
570between real and effective IDs, but for maximum generality, especially
571in library functions, it's generally best not to use @code{access?} to
572predict the result of an open or execute, instead simply attempt that
573and catch any exception.
574
575The main use for @code{access?} is to let a set-UID/GID program
576determine what the invoking user would have been allowed to do,
577without the greater (or perhaps lesser) privileges afforded by the
578effective ID. For more on this, see @ref{Testing File Access,,, libc,
579The GNU C Library Reference Manual}.
a0e07ba4
NJ
580@end deffn
581
582@findex fstat
8f85c0c6
NJ
583@deffn {Scheme Procedure} stat object
584@deffnx {C Function} scm_stat (object)
a0e07ba4
NJ
585Return an object containing various information about the file
586determined by @var{obj}. @var{obj} can be a string containing
587a file name or a port or integer file descriptor which is open
588on a file (in which case @code{fstat} is used as the underlying
589system call).
590
591The object returned by @code{stat} can be passed as a single
592parameter to the following procedures, all of which return
593integers:
594
2ce02471 595@deffn {Scheme Procedure} stat:dev st
5c3917e7 596The device number containing the file.
2ce02471
NJ
597@end deffn
598@deffn {Scheme Procedure} stat:ino st
a0e07ba4
NJ
599The file serial number, which distinguishes this file from all
600other files on the same device.
2ce02471
NJ
601@end deffn
602@deffn {Scheme Procedure} stat:mode st
5c3917e7
KR
603The mode of the file. This is an integer which incorporates file type
604information and file permission bits. See also @code{stat:type} and
a0e07ba4 605@code{stat:perms} below.
2ce02471
NJ
606@end deffn
607@deffn {Scheme Procedure} stat:nlink st
a0e07ba4 608The number of hard links to the file.
2ce02471
NJ
609@end deffn
610@deffn {Scheme Procedure} stat:uid st
a0e07ba4 611The user ID of the file's owner.
2ce02471
NJ
612@end deffn
613@deffn {Scheme Procedure} stat:gid st
a0e07ba4 614The group ID of the file.
2ce02471
NJ
615@end deffn
616@deffn {Scheme Procedure} stat:rdev st
f5f7888d
KR
617Device ID; this entry is defined only for character or block special
618files. On some systems this field is not available at all, in which
619case @code{stat:rdev} returns @code{#f}.
2ce02471
NJ
620@end deffn
621@deffn {Scheme Procedure} stat:size st
a0e07ba4 622The size of a regular file in bytes.
2ce02471
NJ
623@end deffn
624@deffn {Scheme Procedure} stat:atime st
a0e07ba4 625The last access time for the file.
2ce02471
NJ
626@end deffn
627@deffn {Scheme Procedure} stat:mtime st
a0e07ba4 628The last modification time for the file.
2ce02471
NJ
629@end deffn
630@deffn {Scheme Procedure} stat:ctime st
a0e07ba4 631The last modification time for the attributes of the file.
2ce02471
NJ
632@end deffn
633@deffn {Scheme Procedure} stat:blksize st
f5f7888d
KR
634The optimal block size for reading or writing the file, in bytes. On
635some systems this field is not available, in which case
636@code{stat:blksize} returns a sensible suggested block size.
2ce02471
NJ
637@end deffn
638@deffn {Scheme Procedure} stat:blocks st
f5f7888d
KR
639The amount of disk space that the file occupies measured in units of
640512 byte blocks. On some systems this field is not available, in
641which case @code{stat:blocks} returns @code{#f}.
2ce02471 642@end deffn
a0e07ba4
NJ
643
644In addition, the following procedures return the information
5c3917e7 645from @code{stat:mode} in a more convenient form:
a0e07ba4 646
2ce02471 647@deffn {Scheme Procedure} stat:type st
a0e07ba4 648A symbol representing the type of file. Possible values are
7403e409
NJ
649@samp{regular}, @samp{directory}, @samp{symlink},
650@samp{block-special}, @samp{char-special}, @samp{fifo}, @samp{socket},
651and @samp{unknown}.
2ce02471
NJ
652@end deffn
653@deffn {Scheme Procedure} stat:perms st
a0e07ba4 654An integer representing the access permission bits.
2ce02471 655@end deffn
a0e07ba4
NJ
656@end deffn
657
8f85c0c6
NJ
658@deffn {Scheme Procedure} lstat str
659@deffnx {C Function} scm_lstat (str)
a0e07ba4
NJ
660Similar to @code{stat}, but does not follow symbolic links, i.e.,
661it will return information about a symbolic link itself, not the
662file it points to. @var{path} must be a string.
663@end deffn
664
8f85c0c6
NJ
665@deffn {Scheme Procedure} readlink path
666@deffnx {C Function} scm_readlink (path)
a0e07ba4
NJ
667Return the value of the symbolic link named by @var{path} (a
668string), i.e., the file that the link points to.
669@end deffn
670
671@findex fchown
672@findex lchown
8f85c0c6
NJ
673@deffn {Scheme Procedure} chown object owner group
674@deffnx {C Function} scm_chown (object, owner, group)
7403e409
NJ
675Change the ownership and group of the file referred to by @var{object}
676to the integer values @var{owner} and @var{group}. @var{object} can
677be a string containing a file name or, if the platform supports
678@code{fchown} (@pxref{File Owner,,,libc,The GNU C Library Reference
679Manual}), a port or integer file descriptor which is open on the file.
680The return value is unspecified.
a0e07ba4
NJ
681
682If @var{object} is a symbolic link, either the
683ownership of the link or the ownership of the referenced file will be
684changed depending on the operating system (lchown is
685unsupported at present). If @var{owner} or @var{group} is specified
686as @code{-1}, then that ID is not changed.
687@end deffn
688
689@findex fchmod
8f85c0c6
NJ
690@deffn {Scheme Procedure} chmod object mode
691@deffnx {C Function} scm_chmod (object, mode)
a0e07ba4
NJ
692Changes the permissions of the file referred to by @var{obj}.
693@var{obj} can be a string containing a file name or a port or integer file
694descriptor which is open on a file (in which case @code{fchmod} is used
695as the underlying system call).
696@var{mode} specifies
697the new permissions as a decimal number, e.g., @code{(chmod "foo" #o755)}.
698The return value is unspecified.
699@end deffn
700
8f85c0c6
NJ
701@deffn {Scheme Procedure} utime pathname [actime [modtime]]
702@deffnx {C Function} scm_utime (pathname, actime, modtime)
a0e07ba4
NJ
703@code{utime} sets the access and modification times for the
704file named by @var{path}. If @var{actime} or @var{modtime} is
705not supplied, then the current time is used. @var{actime} and
706@var{modtime} must be integer time values as returned by the
707@code{current-time} procedure.
708@lisp
709(utime "foo" (- (current-time) 3600))
710@end lisp
711will set the access time to one hour in the past and the
712modification time to the current time.
713@end deffn
714
715@findex unlink
8f85c0c6
NJ
716@deffn {Scheme Procedure} delete-file str
717@deffnx {C Function} scm_delete_file (str)
7403e409
NJ
718Deletes (or ``unlinks'') the file whose path is specified by
719@var{str}.
a0e07ba4
NJ
720@end deffn
721
8f85c0c6
NJ
722@deffn {Scheme Procedure} copy-file oldfile newfile
723@deffnx {C Function} scm_copy_file (oldfile, newfile)
7403e409 724Copy the file specified by @var{oldfile} to @var{newfile}.
a0e07ba4
NJ
725The return value is unspecified.
726@end deffn
727
728@findex rename
8f85c0c6
NJ
729@deffn {Scheme Procedure} rename-file oldname newname
730@deffnx {C Function} scm_rename (oldname, newname)
a0e07ba4
NJ
731Renames the file specified by @var{oldname} to @var{newname}.
732The return value is unspecified.
733@end deffn
734
8f85c0c6
NJ
735@deffn {Scheme Procedure} link oldpath newpath
736@deffnx {C Function} scm_link (oldpath, newpath)
a0e07ba4
NJ
737Creates a new name @var{newpath} in the file system for the
738file named by @var{oldpath}. If @var{oldpath} is a symbolic
739link, the link may or may not be followed depending on the
740system.
741@end deffn
742
8f85c0c6
NJ
743@deffn {Scheme Procedure} symlink oldpath newpath
744@deffnx {C Function} scm_symlink (oldpath, newpath)
7403e409
NJ
745Create a symbolic link named @var{newpath} with the value (i.e., pointing to)
746@var{oldpath}. The return value is unspecified.
a0e07ba4
NJ
747@end deffn
748
8f85c0c6
NJ
749@deffn {Scheme Procedure} mkdir path [mode]
750@deffnx {C Function} scm_mkdir (path, mode)
a0e07ba4
NJ
751Create a new directory named by @var{path}. If @var{mode} is omitted
752then the permissions of the directory file are set using the current
7403e409
NJ
753umask (@pxref{Processes}). Otherwise they are set to the decimal
754value specified with @var{mode}. The return value is unspecified.
a0e07ba4
NJ
755@end deffn
756
8f85c0c6
NJ
757@deffn {Scheme Procedure} rmdir path
758@deffnx {C Function} scm_rmdir (path)
a0e07ba4
NJ
759Remove the existing directory named by @var{path}. The directory must
760be empty for this to succeed. The return value is unspecified.
761@end deffn
762
8f85c0c6
NJ
763@deffn {Scheme Procedure} opendir dirname
764@deffnx {C Function} scm_opendir (dirname)
7403e409 765Open the directory specified by @var{dirname} and return a directory
a0e07ba4
NJ
766stream.
767@end deffn
768
7403e409
NJ
769@deffn {Scheme Procedure} directory-stream? object
770@deffnx {C Function} scm_directory_stream_p (object)
a0e07ba4
NJ
771Return a boolean indicating whether @var{object} is a directory
772stream as returned by @code{opendir}.
773@end deffn
774
7403e409
NJ
775@deffn {Scheme Procedure} readdir stream
776@deffnx {C Function} scm_readdir (stream)
a0e07ba4
NJ
777Return (as a string) the next directory entry from the directory stream
778@var{stream}. If there is no remaining entry to be read then the
779end of file object is returned.
780@end deffn
781
7403e409
NJ
782@deffn {Scheme Procedure} rewinddir stream
783@deffnx {C Function} scm_rewinddir (stream)
a0e07ba4
NJ
784Reset the directory port @var{stream} so that the next call to
785@code{readdir} will return the first directory entry.
786@end deffn
787
7403e409
NJ
788@deffn {Scheme Procedure} closedir stream
789@deffnx {C Function} scm_closedir (stream)
a0e07ba4
NJ
790Close the directory stream @var{stream}.
791The return value is unspecified.
792@end deffn
793
bcf009c3
NJ
794Here is an example showing how to display all the entries in a
795directory:
796
797@lisp
798(define dir (opendir "/usr/lib"))
799(do ((entry (readdir dir) (readdir dir)))
800 ((eof-object? entry))
801 (display entry)(newline))
802(closedir dir)
803@end lisp
804
8f85c0c6
NJ
805@deffn {Scheme Procedure} sync
806@deffnx {C Function} scm_sync ()
a0e07ba4
NJ
807Flush the operating system disk buffers.
808The return value is unspecified.
809@end deffn
810
8f85c0c6
NJ
811@deffn {Scheme Procedure} mknod path type perms dev
812@deffnx {C Function} scm_mknod (path, type, perms, dev)
a0e07ba4 813Creates a new special file, such as a file corresponding to a device.
7403e409
NJ
814@var{path} specifies the name of the file. @var{type} should be one
815of the following symbols: @samp{regular}, @samp{directory},
816@samp{symlink}, @samp{block-special}, @samp{char-special},
817@samp{fifo}, or @samp{socket}. @var{perms} (an integer) specifies the
818file permissions. @var{dev} (an integer) specifies which device the
819special file refers to. Its exact interpretation depends on the kind
820of special file being created.
a0e07ba4
NJ
821
822E.g.,
823@lisp
824(mknod "/dev/fd0" 'block-special #o660 (+ (* 2 256) 2))
825@end lisp
826
827The return value is unspecified.
828@end deffn
829
8f85c0c6
NJ
830@deffn {Scheme Procedure} tmpnam
831@deffnx {C Function} scm_tmpnam ()
a0e07ba4
NJ
832Return a name in the file system that does not match any
833existing file. However there is no guarantee that another
834process will not create the file after @code{tmpnam} is called.
835Care should be taken if opening the file, e.g., use the
836@code{O_EXCL} open flag or use @code{mkstemp!} instead.
837@end deffn
838
8f85c0c6
NJ
839@deffn {Scheme Procedure} mkstemp! tmpl
840@deffnx {C Function} scm_mkstemp (tmpl)
a0e07ba4
NJ
841Create a new unique file in the file system and returns a new
842buffered port open for reading and writing to the file.
843@var{tmpl} is a string specifying where the file should be
7403e409 844created: it must end with @samp{XXXXXX} and will be changed in
a0e07ba4
NJ
845place to return the name of the temporary file.
846@end deffn
847
8f85c0c6
NJ
848@deffn {Scheme Procedure} dirname filename
849@deffnx {C Function} scm_dirname (filename)
a0e07ba4
NJ
850Return the directory name component of the file name
851@var{filename}. If @var{filename} does not contain a directory
852component, @code{.} is returned.
853@end deffn
854
8f85c0c6
NJ
855@deffn {Scheme Procedure} basename filename [suffix]
856@deffnx {C Function} scm_basename (filename, suffix)
a0e07ba4
NJ
857Return the base name of the file name @var{filename}. The
858base name is the file name without any directory components.
85a9b4ed 859If @var{suffix} is provided, and is equal to the end of
a0e07ba4 860@var{basename}, it is removed also.
bcf009c3
NJ
861
862@lisp
863(basename "/tmp/test.xml" ".xml")
864@result{} "test"
865@end lisp
a0e07ba4
NJ
866@end deffn
867
868
869@node User Information
870@section User Information
871
872The facilities in this section provide an interface to the user and
873group database.
874They should be used with care since they are not reentrant.
875
876The following functions accept an object representing user information
877and return a selected component:
878
2ce02471 879@deffn {Scheme Procedure} passwd:name pw
a0e07ba4 880The name of the userid.
2ce02471
NJ
881@end deffn
882@deffn {Scheme Procedure} passwd:passwd pw
a0e07ba4 883The encrypted passwd.
2ce02471
NJ
884@end deffn
885@deffn {Scheme Procedure} passwd:uid pw
a0e07ba4 886The user id number.
2ce02471
NJ
887@end deffn
888@deffn {Scheme Procedure} passwd:gid pw
a0e07ba4 889The group id number.
2ce02471
NJ
890@end deffn
891@deffn {Scheme Procedure} passwd:gecos pw
a0e07ba4 892The full name.
2ce02471
NJ
893@end deffn
894@deffn {Scheme Procedure} passwd:dir pw
a0e07ba4 895The home directory.
2ce02471
NJ
896@end deffn
897@deffn {Scheme Procedure} passwd:shell pw
a0e07ba4 898The login shell.
2ce02471
NJ
899@end deffn
900@sp 1
a0e07ba4 901
8f85c0c6 902@deffn {Scheme Procedure} getpwuid uid
a0e07ba4
NJ
903Look up an integer userid in the user database.
904@end deffn
905
8f85c0c6 906@deffn {Scheme Procedure} getpwnam name
a0e07ba4
NJ
907Look up a user name string in the user database.
908@end deffn
909
8f85c0c6 910@deffn {Scheme Procedure} setpwent
a0e07ba4
NJ
911Initializes a stream used by @code{getpwent} to read from the user database.
912The next use of @code{getpwent} will return the first entry. The
913return value is unspecified.
914@end deffn
915
8f85c0c6 916@deffn {Scheme Procedure} getpwent
a0e07ba4
NJ
917Return the next entry in the user database, using the stream set by
918@code{setpwent}.
919@end deffn
920
8f85c0c6 921@deffn {Scheme Procedure} endpwent
a0e07ba4
NJ
922Closes the stream used by @code{getpwent}. The return value is unspecified.
923@end deffn
924
8f85c0c6
NJ
925@deffn {Scheme Procedure} setpw [arg]
926@deffnx {C Function} scm_setpwent (arg)
a0e07ba4
NJ
927If called with a true argument, initialize or reset the password data
928stream. Otherwise, close the stream. The @code{setpwent} and
929@code{endpwent} procedures are implemented on top of this.
930@end deffn
931
8f85c0c6
NJ
932@deffn {Scheme Procedure} getpw [user]
933@deffnx {C Function} scm_getpwuid (user)
a0e07ba4
NJ
934Look up an entry in the user database. @var{obj} can be an integer,
935a string, or omitted, giving the behaviour of getpwuid, getpwnam
936or getpwent respectively.
937@end deffn
938
939The following functions accept an object representing group information
940and return a selected component:
941
2ce02471 942@deffn {Scheme Procedure} group:name gr
a0e07ba4 943The group name.
2ce02471
NJ
944@end deffn
945@deffn {Scheme Procedure} group:passwd gr
a0e07ba4 946The encrypted group password.
2ce02471
NJ
947@end deffn
948@deffn {Scheme Procedure} group:gid gr
a0e07ba4 949The group id number.
2ce02471
NJ
950@end deffn
951@deffn {Scheme Procedure} group:mem gr
85a9b4ed 952A list of userids which have this group as a supplementary group.
2ce02471
NJ
953@end deffn
954@sp 1
a0e07ba4 955
8f85c0c6 956@deffn {Scheme Procedure} getgrgid gid
85a9b4ed 957Look up an integer group id in the group database.
a0e07ba4
NJ
958@end deffn
959
8f85c0c6 960@deffn {Scheme Procedure} getgrnam name
a0e07ba4
NJ
961Look up a group name in the group database.
962@end deffn
963
8f85c0c6 964@deffn {Scheme Procedure} setgrent
a0e07ba4
NJ
965Initializes a stream used by @code{getgrent} to read from the group database.
966The next use of @code{getgrent} will return the first entry.
967The return value is unspecified.
968@end deffn
969
8f85c0c6 970@deffn {Scheme Procedure} getgrent
a0e07ba4
NJ
971Return the next entry in the group database, using the stream set by
972@code{setgrent}.
973@end deffn
974
8f85c0c6 975@deffn {Scheme Procedure} endgrent
a0e07ba4
NJ
976Closes the stream used by @code{getgrent}.
977The return value is unspecified.
978@end deffn
979
8f85c0c6
NJ
980@deffn {Scheme Procedure} setgr [arg]
981@deffnx {C Function} scm_setgrent (arg)
a0e07ba4
NJ
982If called with a true argument, initialize or reset the group data
983stream. Otherwise, close the stream. The @code{setgrent} and
984@code{endgrent} procedures are implemented on top of this.
985@end deffn
986
8f85c0c6
NJ
987@deffn {Scheme Procedure} getgr [name]
988@deffnx {C Function} scm_getgrgid (name)
a0e07ba4
NJ
989Look up an entry in the group database. @var{obj} can be an integer,
990a string, or omitted, giving the behaviour of getgrgid, getgrnam
991or getgrent respectively.
992@end deffn
993
994In addition to the accessor procedures for the user database, the
995following shortcut procedures are also available.
996
8f85c0c6
NJ
997@deffn {Scheme Procedure} cuserid
998@deffnx {C Function} scm_cuserid ()
a0e07ba4
NJ
999Return a string containing a user name associated with the
1000effective user id of the process. Return @code{#f} if this
1001information cannot be obtained.
1002@end deffn
1003
8f85c0c6
NJ
1004@deffn {Scheme Procedure} getlogin
1005@deffnx {C Function} scm_getlogin ()
a0e07ba4
NJ
1006Return a string containing the name of the user logged in on
1007the controlling terminal of the process, or @code{#f} if this
1008information cannot be obtained.
1009@end deffn
1010
1011
1012@node Time
1013@section Time
1014
8f85c0c6
NJ
1015@deffn {Scheme Procedure} current-time
1016@deffnx {C Function} scm_current_time ()
7403e409 1017Return the number of seconds since 1970-01-01 00:00:00 @acronym{UTC},
a0e07ba4
NJ
1018excluding leap seconds.
1019@end deffn
1020
8f85c0c6
NJ
1021@deffn {Scheme Procedure} gettimeofday
1022@deffnx {C Function} scm_gettimeofday ()
a0e07ba4 1023Return a pair containing the number of seconds and microseconds
7403e409 1024since 1970-01-01 00:00:00 @acronym{UTC}, excluding leap seconds. Note:
a0e07ba4
NJ
1025whether true microsecond resolution is available depends on the
1026operating system.
1027@end deffn
1028
1029The following procedures either accept an object representing a broken down
1030time and return a selected component, or accept an object representing
1031a broken down time and a value and set the component to the value.
1032The numbers in parentheses give the usual range.
1033
2ce02471
NJ
1034@deffn {Scheme Procedure} tm:sec tm
1035@deffnx {Scheme Procedure} set-tm:sec tm val
a0e07ba4 1036Seconds (0-59).
2ce02471
NJ
1037@end deffn
1038@deffn {Scheme Procedure} tm:min tm
1039@deffnx {Scheme Procedure} set-tm:min tm val
a0e07ba4 1040Minutes (0-59).
2ce02471
NJ
1041@end deffn
1042@deffn {Scheme Procedure} tm:hour tm
1043@deffnx {Scheme Procedure} set-tm:hour tm val
a0e07ba4 1044Hours (0-23).
2ce02471
NJ
1045@end deffn
1046@deffn {Scheme Procedure} tm:mday tm
1047@deffnx {Scheme Procedure} set-tm:mday tm val
a0e07ba4 1048Day of the month (1-31).
2ce02471
NJ
1049@end deffn
1050@deffn {Scheme Procedure} tm:mon tm
1051@deffnx {Scheme Procedure} set-tm:mon tm val
a0e07ba4 1052Month (0-11).
2ce02471
NJ
1053@end deffn
1054@deffn {Scheme Procedure} tm:year tm
1055@deffnx {Scheme Procedure} set-tm:year tm val
a0e07ba4 1056Year (70-), the year minus 1900.
2ce02471
NJ
1057@end deffn
1058@deffn {Scheme Procedure} tm:wday tm
1059@deffnx {Scheme Procedure} set-tm:wday tm val
a0e07ba4 1060Day of the week (0-6) with Sunday represented as 0.
2ce02471
NJ
1061@end deffn
1062@deffn {Scheme Procedure} tm:yday tm
1063@deffnx {Scheme Procedure} set-tm:yday tm val
a0e07ba4 1064Day of the year (0-364, 365 in leap years).
2ce02471
NJ
1065@end deffn
1066@deffn {Scheme Procedure} tm:isdst tm
1067@deffnx {Scheme Procedure} set-tm:isdst tm val
7403e409
NJ
1068Daylight saving indicator (0 for ``no'', greater than 0 for ``yes'', less than
10690 for ``unknown'').
2ce02471
NJ
1070@end deffn
1071@deffn {Scheme Procedure} tm:gmtoff tm
1072@deffnx {Scheme Procedure} set-tm:gmtoff tm val
7403e409 1073Time zone offset in seconds west of @acronym{UTC} (-46800 to 43200).
2ce02471
NJ
1074@end deffn
1075@deffn {Scheme Procedure} tm:zone tm
1076@deffnx {Scheme Procedure} set-tm:zone tm val
a0e07ba4 1077Time zone label (a string), not necessarily unique.
2ce02471
NJ
1078@end deffn
1079@sp 1
a0e07ba4 1080
8f85c0c6
NJ
1081@deffn {Scheme Procedure} localtime time [zone]
1082@deffnx {C Function} scm_localtime (time, zone)
a0e07ba4
NJ
1083Return an object representing the broken down components of
1084@var{time}, an integer like the one returned by
1085@code{current-time}. The time zone for the calculation is
1086optionally specified by @var{zone} (a string), otherwise the
7403e409 1087@env{TZ} environment variable or the system default is used.
a0e07ba4
NJ
1088@end deffn
1089
8f85c0c6
NJ
1090@deffn {Scheme Procedure} gmtime time
1091@deffnx {C Function} scm_gmtime (time)
a0e07ba4
NJ
1092Return an object representing the broken down components of
1093@var{time}, an integer like the one returned by
7403e409 1094@code{current-time}. The values are calculated for @acronym{UTC}.
a0e07ba4
NJ
1095@end deffn
1096
82512be0 1097@deffn {Scheme Procedure} mktime sbd-time [zone]
8f85c0c6 1098@deffnx {C Function} scm_mktime (sbd_time, zone)
7403e409
NJ
1099@var{sbd-time} is an object representing broken down time and
1100@code{zone} is an optional time zone specifier (otherwise the @env{TZ}
1101environment variable or the system default is used).
a0e07ba4 1102
7403e409
NJ
1103Returns a pair: the @acronym{CAR} is a corresponding integer time
1104value like that returned by @code{current-time}; the @acronym{CDR} is
1105a broken down time object, similar to @var{sbd-time} but with
1106normalized values; i.e.@: with corrected @code{tm:wday} and
1107@code{tm:yday} fields.
a0e07ba4
NJ
1108@end deffn
1109
8f85c0c6
NJ
1110@deffn {Scheme Procedure} tzset
1111@deffnx {C Function} scm_tzset ()
7403e409 1112Initialize the timezone from the @env{TZ} environment variable
a0e07ba4
NJ
1113or the system default. It's not usually necessary to call this procedure
1114since it's done automatically by other procedures that depend on the
1115timezone.
1116@end deffn
1117
8f85c0c6
NJ
1118@deffn {Scheme Procedure} strftime format stime
1119@deffnx {C Function} scm_strftime (format, stime)
a0e07ba4
NJ
1120Formats a time specification @var{time} using @var{template}. @var{time}
1121is an object with time components in the form returned by @code{localtime}
1122or @code{gmtime}. @var{template} is a string which can include formatting
7403e409 1123specifications introduced by a @samp{%} character. The formatting of
a0e07ba4
NJ
1124month and day names is dependent on the current locale. The value returned
1125is the formatted string.
7403e409 1126@xref{Formatting Date and Time, , , libc, The GNU C Library Reference Manual}.
bcf009c3
NJ
1127
1128@lisp
1129(strftime "%c" (localtime (current-time)))
1130@result{} "Mon Mar 11 20:17:43 2002"
1131@end lisp
a0e07ba4
NJ
1132@end deffn
1133
8f85c0c6
NJ
1134@deffn {Scheme Procedure} strptime format string
1135@deffnx {C Function} scm_strptime (format, string)
a0e07ba4
NJ
1136Performs the reverse action to @code{strftime}, parsing
1137@var{string} according to the specification supplied in
1138@var{template}. The interpretation of month and day names is
1139dependent on the current locale. The value returned is a pair.
7403e409 1140The @acronym{CAR} has an object with time components
a0e07ba4
NJ
1141in the form returned by @code{localtime} or @code{gmtime},
1142but the time zone components
1143are not usefully set.
7403e409 1144The @acronym{CDR} reports the number of characters from @var{string}
a0e07ba4
NJ
1145which were used for the conversion.
1146@end deffn
1147
1148@defvar internal-time-units-per-second
1149The value of this variable is the number of time units per second
1150reported by the following procedures.
1151@end defvar
1152
8f85c0c6
NJ
1153@deffn {Scheme Procedure} times
1154@deffnx {C Function} scm_times ()
a0e07ba4
NJ
1155Return an object with information about real and processor
1156time. The following procedures accept such an object as an
1157argument and return a selected component:
1158
2ce02471 1159@deffn {Scheme Procedure} tms:clock tms
a0e07ba4
NJ
1160The current real time, expressed as time units relative to an
1161arbitrary base.
2ce02471
NJ
1162@end deffn
1163@deffn {Scheme Procedure} tms:utime tms
a0e07ba4 1164The CPU time units used by the calling process.
2ce02471
NJ
1165@end deffn
1166@deffn {Scheme Procedure} tms:stime tms
a0e07ba4
NJ
1167The CPU time units used by the system on behalf of the calling
1168process.
2ce02471
NJ
1169@end deffn
1170@deffn {Scheme Procedure} tms:cutime tms
a0e07ba4
NJ
1171The CPU time units used by terminated child processes of the
1172calling process, whose status has been collected (e.g., using
1173@code{waitpid}).
2ce02471
NJ
1174@end deffn
1175@deffn {Scheme Procedure} tms:cstime tms
a0e07ba4
NJ
1176Similarly, the CPU times units used by the system on behalf of
1177terminated child processes.
2ce02471 1178@end deffn
a0e07ba4
NJ
1179@end deffn
1180
8f85c0c6
NJ
1181@deffn {Scheme Procedure} get-internal-real-time
1182@deffnx {C Function} scm_get_internal_real_time ()
a0e07ba4
NJ
1183Return the number of time units since the interpreter was
1184started.
1185@end deffn
1186
8f85c0c6
NJ
1187@deffn {Scheme Procedure} get-internal-run-time
1188@deffnx {C Function} scm_get_internal_run_time ()
a0e07ba4
NJ
1189Return the number of time units of processor time used by the
1190interpreter. Both @emph{system} and @emph{user} time are
1191included but subprocesses are not.
1192@end deffn
1193
1194@node Runtime Environment
1195@section Runtime Environment
1196
8f85c0c6
NJ
1197@deffn {Scheme Procedure} program-arguments
1198@deffnx {Scheme Procedure} command-line
1199@deffnx {C Function} scm_program_arguments ()
a0e07ba4
NJ
1200Return the list of command line arguments passed to Guile, as a list of
1201strings. The list includes the invoked program name, which is usually
1202@code{"guile"}, but excludes switches and parameters for command line
1203options like @code{-e} and @code{-l}.
1204@end deffn
1205
8f85c0c6
NJ
1206@deffn {Scheme Procedure} getenv nam
1207@deffnx {C Function} scm_getenv (nam)
a0e07ba4
NJ
1208Looks up the string @var{name} in the current environment. The return
1209value is @code{#f} unless a string of the form @code{NAME=VALUE} is
1210found, in which case the string @code{VALUE} is returned.
1211@end deffn
1212
8f85c0c6 1213@deffn {Scheme Procedure} setenv name value
a0e07ba4
NJ
1214Modifies the environment of the current process, which is
1215also the default environment inherited by child processes.
1216
1217If @var{value} is @code{#f}, then @var{name} is removed from the
1218environment. Otherwise, the string @var{name}=@var{value} is added
1219to the environment, replacing any existing string with name matching
1220@var{name}.
1221
1222The return value is unspecified.
1223@end deffn
1224
395b0a34
NJ
1225@deffn {Scheme Procedure} unsetenv name
1226Remove variable @var{name} from the environment. The
1227name can not contain a @samp{=} character.
1228@end deffn
1229
8f85c0c6
NJ
1230@deffn {Scheme Procedure} environ [env]
1231@deffnx {C Function} scm_environ (env)
a0e07ba4
NJ
1232If @var{env} is omitted, return the current environment (in the
1233Unix sense) as a list of strings. Otherwise set the current
1234environment, which is also the default environment for child
1235processes, to the supplied list of strings. Each member of
7403e409
NJ
1236@var{env} should be of the form @var{NAME}=@var{VALUE} and values of
1237@var{NAME} should not be duplicated. If @var{env} is supplied
a0e07ba4
NJ
1238then the return value is unspecified.
1239@end deffn
1240
8f85c0c6
NJ
1241@deffn {Scheme Procedure} putenv str
1242@deffnx {C Function} scm_putenv (str)
a0e07ba4
NJ
1243Modifies the environment of the current process, which is
1244also the default environment inherited by child processes.
1245
1246If @var{string} is of the form @code{NAME=VALUE} then it will be written
1247directly into the environment, replacing any existing environment string
1248with
1249name matching @code{NAME}. If @var{string} does not contain an equal
1250sign, then any existing string with name matching @var{string} will
1251be removed.
1252
1253The return value is unspecified.
1254@end deffn
1255
1256
1257@node Processes
1258@section Processes
1259
1260@findex cd
8f85c0c6
NJ
1261@deffn {Scheme Procedure} chdir str
1262@deffnx {C Function} scm_chdir (str)
a0e07ba4
NJ
1263Change the current working directory to @var{path}.
1264The return value is unspecified.
1265@end deffn
1266
1267@findex pwd
8f85c0c6
NJ
1268@deffn {Scheme Procedure} getcwd
1269@deffnx {C Function} scm_getcwd ()
a0e07ba4
NJ
1270Return the name of the current working directory.
1271@end deffn
1272
8f85c0c6
NJ
1273@deffn {Scheme Procedure} umask [mode]
1274@deffnx {C Function} scm_umask (mode)
7403e409
NJ
1275If @var{mode} is omitted, returns a decimal number representing the
1276current file creation mask. Otherwise the file creation mask is set
1277to @var{mode} and the previous value is returned. @xref{Setting
1278Permissions,,Assigning File Permissions,libc,The GNU C Library
1279Reference Manual}, for more on how to use umasks.
a0e07ba4 1280
7403e409 1281E.g., @code{(umask #o022)} sets the mask to octal 22/decimal 18.
a0e07ba4
NJ
1282@end deffn
1283
8f85c0c6
NJ
1284@deffn {Scheme Procedure} chroot path
1285@deffnx {C Function} scm_chroot (path)
a0e07ba4
NJ
1286Change the root directory to that specified in @var{path}.
1287This directory will be used for path names beginning with
1288@file{/}. The root directory is inherited by all children
1289of the current process. Only the superuser may change the
1290root directory.
1291@end deffn
1292
8f85c0c6
NJ
1293@deffn {Scheme Procedure} getpid
1294@deffnx {C Function} scm_getpid ()
a0e07ba4
NJ
1295Return an integer representing the current process ID.
1296@end deffn
1297
8f85c0c6
NJ
1298@deffn {Scheme Procedure} getgroups
1299@deffnx {C Function} scm_getgroups ()
a0e07ba4 1300Return a vector of integers representing the current
85a9b4ed 1301supplementary group IDs.
a0e07ba4
NJ
1302@end deffn
1303
8f85c0c6
NJ
1304@deffn {Scheme Procedure} getppid
1305@deffnx {C Function} scm_getppid ()
a0e07ba4
NJ
1306Return an integer representing the process ID of the parent
1307process.
1308@end deffn
1309
8f85c0c6
NJ
1310@deffn {Scheme Procedure} getuid
1311@deffnx {C Function} scm_getuid ()
a0e07ba4
NJ
1312Return an integer representing the current real user ID.
1313@end deffn
1314
8f85c0c6
NJ
1315@deffn {Scheme Procedure} getgid
1316@deffnx {C Function} scm_getgid ()
a0e07ba4
NJ
1317Return an integer representing the current real group ID.
1318@end deffn
1319
8f85c0c6
NJ
1320@deffn {Scheme Procedure} geteuid
1321@deffnx {C Function} scm_geteuid ()
a0e07ba4
NJ
1322Return an integer representing the current effective user ID.
1323If the system does not support effective IDs, then the real ID
66add4eb 1324is returned. @code{(provided? 'EIDs)} reports whether the
a0e07ba4
NJ
1325system supports effective IDs.
1326@end deffn
1327
8f85c0c6
NJ
1328@deffn {Scheme Procedure} getegid
1329@deffnx {C Function} scm_getegid ()
a0e07ba4
NJ
1330Return an integer representing the current effective group ID.
1331If the system does not support effective IDs, then the real ID
66add4eb 1332is returned. @code{(provided? 'EIDs)} reports whether the
a0e07ba4
NJ
1333system supports effective IDs.
1334@end deffn
1335
8f85c0c6
NJ
1336@deffn {Scheme Procedure} setuid id
1337@deffnx {C Function} scm_setuid (id)
a0e07ba4
NJ
1338Sets both the real and effective user IDs to the integer @var{id}, provided
1339the process has appropriate privileges.
1340The return value is unspecified.
1341@end deffn
1342
8f85c0c6
NJ
1343@deffn {Scheme Procedure} setgid id
1344@deffnx {C Function} scm_setgid (id)
a0e07ba4
NJ
1345Sets both the real and effective group IDs to the integer @var{id}, provided
1346the process has appropriate privileges.
1347The return value is unspecified.
1348@end deffn
1349
8f85c0c6
NJ
1350@deffn {Scheme Procedure} seteuid id
1351@deffnx {C Function} scm_seteuid (id)
a0e07ba4
NJ
1352Sets the effective user ID to the integer @var{id}, provided the process
1353has appropriate privileges. If effective IDs are not supported, the
7403e409 1354real ID is set instead---@code{(provided? 'EIDs)} reports whether the
a0e07ba4
NJ
1355system supports effective IDs.
1356The return value is unspecified.
1357@end deffn
1358
8f85c0c6
NJ
1359@deffn {Scheme Procedure} setegid id
1360@deffnx {C Function} scm_setegid (id)
a0e07ba4
NJ
1361Sets the effective group ID to the integer @var{id}, provided the process
1362has appropriate privileges. If effective IDs are not supported, the
7403e409 1363real ID is set instead---@code{(provided? 'EIDs)} reports whether the
a0e07ba4
NJ
1364system supports effective IDs.
1365The return value is unspecified.
1366@end deffn
1367
8f85c0c6
NJ
1368@deffn {Scheme Procedure} getpgrp
1369@deffnx {C Function} scm_getpgrp ()
a0e07ba4 1370Return an integer representing the current process group ID.
7403e409 1371This is the @acronym{POSIX} definition, not @acronym{BSD}.
a0e07ba4
NJ
1372@end deffn
1373
8f85c0c6
NJ
1374@deffn {Scheme Procedure} setpgid pid pgid
1375@deffnx {C Function} scm_setpgid (pid, pgid)
a0e07ba4
NJ
1376Move the process @var{pid} into the process group @var{pgid}. @var{pid} or
1377@var{pgid} must be integers: they can be zero to indicate the ID of the
1378current process.
1379Fails on systems that do not support job control.
1380The return value is unspecified.
1381@end deffn
1382
8f85c0c6
NJ
1383@deffn {Scheme Procedure} setsid
1384@deffnx {C Function} scm_setsid ()
a0e07ba4
NJ
1385Creates a new session. The current process becomes the session leader
1386and is put in a new process group. The process will be detached
1387from its controlling terminal if it has one.
1388The return value is an integer representing the new process group ID.
1389@end deffn
1390
8f85c0c6
NJ
1391@deffn {Scheme Procedure} waitpid pid [options]
1392@deffnx {C Function} scm_waitpid (pid, options)
a0e07ba4
NJ
1393This procedure collects status information from a child process which
1394has terminated or (optionally) stopped. Normally it will
1395suspend the calling process until this can be done. If more than one
1396child process is eligible then one will be chosen by the operating system.
1397
1398The value of @var{pid} determines the behaviour:
1399
7403e409 1400@table @asis
a0e07ba4
NJ
1401@item @var{pid} greater than 0
1402Request status information from the specified child process.
7403e409 1403@item @var{pid} equal to -1 or @code{WAIT_ANY}
2ce02471 1404@vindex WAIT_ANY
a0e07ba4 1405Request status information for any child process.
7403e409 1406@item @var{pid} equal to 0 or @code{WAIT_MYPGRP}
2ce02471 1407@vindex WAIT_MYPGRP
a0e07ba4
NJ
1408Request status information for any child process in the current process
1409group.
1410@item @var{pid} less than -1
1411Request status information for any child process whose process group ID
7403e409 1412is @minus{}@var{pid}.
a0e07ba4
NJ
1413@end table
1414
1415The @var{options} argument, if supplied, should be the bitwise OR of the
1416values of zero or more of the following variables:
1417
1418@defvar WNOHANG
1419Return immediately even if there are no child processes to be collected.
1420@end defvar
1421
1422@defvar WUNTRACED
1423Report status information for stopped processes as well as terminated
1424processes.
1425@end defvar
1426
1427The return value is a pair containing:
1428
1429@enumerate
1430@item
1431The process ID of the child process, or 0 if @code{WNOHANG} was
1432specified and no process was collected.
1433@item
1434The integer status value.
1435@end enumerate
1436@end deffn
1437
1438The following three
1439functions can be used to decode the process status code returned
1440by @code{waitpid}.
1441
8f85c0c6
NJ
1442@deffn {Scheme Procedure} status:exit-val status
1443@deffnx {C Function} scm_status_exit_val (status)
a0e07ba4
NJ
1444Return the exit status value, as would be set if a process
1445ended normally through a call to @code{exit} or @code{_exit},
1446if any, otherwise @code{#f}.
1447@end deffn
1448
8f85c0c6
NJ
1449@deffn {Scheme Procedure} status:term-sig status
1450@deffnx {C Function} scm_status_term_sig (status)
a0e07ba4
NJ
1451Return the signal number which terminated the process, if any,
1452otherwise @code{#f}.
1453@end deffn
1454
8f85c0c6
NJ
1455@deffn {Scheme Procedure} status:stop-sig status
1456@deffnx {C Function} scm_status_stop_sig (status)
a0e07ba4
NJ
1457Return the signal number which stopped the process, if any,
1458otherwise @code{#f}.
1459@end deffn
1460
8f85c0c6
NJ
1461@deffn {Scheme Procedure} system [cmd]
1462@deffnx {C Function} scm_system (cmd)
7403e409
NJ
1463Execute @var{cmd} using the operating system's ``command
1464processor''. Under Unix this is usually the default shell
a0e07ba4
NJ
1465@code{sh}. The value returned is @var{cmd}'s exit status as
1466returned by @code{waitpid}, which can be interpreted using the
1467functions above.
1468
1469If @code{system} is called without arguments, return a boolean
1470indicating whether the command processor is available.
1471@end deffn
1472
8f85c0c6
NJ
1473@deffn {Scheme Procedure} primitive-exit [status]
1474@deffnx {C Function} scm_primitive_exit (status)
a0e07ba4
NJ
1475Terminate the current process without unwinding the Scheme stack.
1476This is would typically be useful after a fork. The exit status
1477is @var{status} if supplied, otherwise zero.
1478@end deffn
1479
8f85c0c6
NJ
1480@deffn {Scheme Procedure} execl filename . args
1481@deffnx {C Function} scm_execl (filename, args)
a0e07ba4
NJ
1482Executes the file named by @var{path} as a new process image.
1483The remaining arguments are supplied to the process; from a C program
85a9b4ed 1484they are accessible as the @code{argv} argument to @code{main}.
a0e07ba4
NJ
1485Conventionally the first @var{arg} is the same as @var{path}.
1486All arguments must be strings.
1487
1488If @var{arg} is missing, @var{path} is executed with a null
1489argument list, which may have system-dependent side-effects.
1490
1491This procedure is currently implemented using the @code{execv} system
1492call, but we call it @code{execl} because of its Scheme calling interface.
1493@end deffn
1494
8f85c0c6
NJ
1495@deffn {Scheme Procedure} execlp filename . args
1496@deffnx {C Function} scm_execlp (filename, args)
a0e07ba4
NJ
1497Similar to @code{execl}, however if
1498@var{filename} does not contain a slash
1499then the file to execute will be located by searching the
1500directories listed in the @code{PATH} environment variable.
1501
1502This procedure is currently implemented using the @code{execvp} system
1503call, but we call it @code{execlp} because of its Scheme calling interface.
1504@end deffn
1505
8f85c0c6
NJ
1506@deffn {Scheme Procedure} execle filename env . args
1507@deffnx {C Function} scm_execle (filename, env, args)
a0e07ba4
NJ
1508Similar to @code{execl}, but the environment of the new process is
1509specified by @var{env}, which must be a list of strings as returned by the
1510@code{environ} procedure.
1511
1512This procedure is currently implemented using the @code{execve} system
1513call, but we call it @code{execle} because of its Scheme calling interface.
1514@end deffn
1515
8f85c0c6
NJ
1516@deffn {Scheme Procedure} primitive-fork
1517@deffnx {C Function} scm_fork ()
7403e409 1518Creates a new ``child'' process by duplicating the current ``parent'' process.
a0e07ba4
NJ
1519In the child the return value is 0. In the parent the return value is
1520the integer process ID of the child.
1521
1522This procedure has been renamed from @code{fork} to avoid a naming conflict
1523with the scsh fork.
1524@end deffn
1525
8f85c0c6
NJ
1526@deffn {Scheme Procedure} nice incr
1527@deffnx {C Function} scm_nice (incr)
a0e07ba4
NJ
1528Increment the priority of the current process by @var{incr}. A higher
1529priority value means that the process runs less often.
1530The return value is unspecified.
1531@end deffn
1532
8f85c0c6
NJ
1533@deffn {Scheme Procedure} setpriority which who prio
1534@deffnx {C Function} scm_setpriority (which, who, prio)
2ce02471
NJ
1535@vindex PRIO_PROCESS
1536@vindex PRIO_PGRP
1537@vindex PRIO_USER
a0e07ba4
NJ
1538Set the scheduling priority of the process, process group
1539or user, as indicated by @var{which} and @var{who}. @var{which}
1540is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}
1541or @code{PRIO_USER}, and @var{who} is interpreted relative to
1542@var{which} (a process identifier for @code{PRIO_PROCESS},
004fe2c8 1543process group identifier for @code{PRIO_PGRP}, and a user
a0e07ba4
NJ
1544identifier for @code{PRIO_USER}. A zero value of @var{who}
1545denotes the current process, process group, or user.
7403e409
NJ
1546@var{prio} is a value in the range [@minus{}20,20]. The default
1547priority is 0; lower priorities (in numerical terms) cause more
1548favorable scheduling. Sets the priority of all of the specified
1549processes. Only the super-user may lower priorities. The return
1550value is not specified.
a0e07ba4
NJ
1551@end deffn
1552
8f85c0c6
NJ
1553@deffn {Scheme Procedure} getpriority which who
1554@deffnx {C Function} scm_getpriority (which, who)
2ce02471
NJ
1555@vindex PRIO_PROCESS
1556@vindex PRIO_PGRP
1557@vindex PRIO_USER
a0e07ba4
NJ
1558Return the scheduling priority of the process, process group
1559or user, as indicated by @var{which} and @var{who}. @var{which}
1560is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}
7403e409 1561or @code{PRIO_USER}, and @var{who} should be interpreted depending on
a0e07ba4
NJ
1562@var{which} (a process identifier for @code{PRIO_PROCESS},
1563process group identifier for @code{PRIO_PGRP}, and a user
7403e409 1564identifier for @code{PRIO_USER}). A zero value of @var{who}
a0e07ba4
NJ
1565denotes the current process, process group, or user. Return
1566the highest priority (lowest numerical value) of any of the
1567specified processes.
1568@end deffn
1569
1570
1571@node Signals
1572@section Signals
1573
1574Procedures to raise, handle and wait for signals.
1575
8f85c0c6
NJ
1576@deffn {Scheme Procedure} kill pid sig
1577@deffnx {C Function} scm_kill (pid, sig)
a0e07ba4
NJ
1578Sends a signal to the specified process or group of processes.
1579
1580@var{pid} specifies the processes to which the signal is sent:
1581
7403e409 1582@table @asis
a0e07ba4
NJ
1583@item @var{pid} greater than 0
1584The process whose identifier is @var{pid}.
1585@item @var{pid} equal to 0
1586All processes in the current process group.
1587@item @var{pid} less than -1
1588The process group whose identifier is -@var{pid}
1589@item @var{pid} equal to -1
1590If the process is privileged, all processes except for some special
1591system processes. Otherwise, all processes with the current effective
1592user ID.
1593@end table
1594
1595@var{sig} should be specified using a variable corresponding to
1596the Unix symbolic name, e.g.,
1597
1598@defvar SIGHUP
1599Hang-up signal.
1600@end defvar
1601
1602@defvar SIGINT
1603Interrupt signal.
1604@end defvar
7403e409
NJ
1605
1606A full list of signals on the GNU system may be found in @ref{Standard
1607Signals,,,libc,The GNU C Library Reference Manual}.
a0e07ba4
NJ
1608@end deffn
1609
8f85c0c6
NJ
1610@deffn {Scheme Procedure} raise sig
1611@deffnx {C Function} scm_raise (sig)
a0e07ba4 1612Sends a specified signal @var{sig} to the current process, where
7403e409 1613@var{sig} is as described for the @code{kill} procedure.
a0e07ba4
NJ
1614@end deffn
1615
b6506f45 1616@deffn {Scheme Procedure} sigaction signum [handler [flags [thread]]]
8f85c0c6 1617@deffnx {C Function} scm_sigaction (signum, handler, flags)
b6506f45 1618@deffnx {C Function} scm_sigaction_for_thread (signum, handler, flags, thread)
a0e07ba4
NJ
1619Install or report the signal handler for a specified signal.
1620
1621@var{signum} is the signal number, which can be specified using the value
1622of variables such as @code{SIGINT}.
1623
b6506f45 1624If @var{handler} is omitted, @code{sigaction} returns a pair: the
7403e409
NJ
1625@acronym{CAR} is the current signal hander, which will be either an
1626integer with the value @code{SIG_DFL} (default action) or
1627@code{SIG_IGN} (ignore), or the Scheme procedure which handles the
1628signal, or @code{#f} if a non-Scheme procedure handles the signal.
1629The @acronym{CDR} contains the current @code{sigaction} flags for the
1630handler.
a0e07ba4 1631
b6506f45 1632If @var{handler} is provided, it is installed as the new handler for
0a50eeaa
NJ
1633@var{signum}. @var{handler} can be a Scheme procedure taking one
1634argument, or the value of @code{SIG_DFL} (default action) or
a0e07ba4 1635@code{SIG_IGN} (ignore), or @code{#f} to restore whatever signal handler
b6506f45
MV
1636was installed before @code{sigaction} was first used. When a scheme
1637procedure has been specified, that procedure will run in the given
1638@var{thread}. When no thread has been given, the thread that made this
1639call to @code{sigaction} is used.
1640
1641Flags can optionally be specified for the new handler (@code{SA_RESTART}
1642will always be added if it's available and the system is using
1643restartable system calls.) The return value is a pair with information
1644about the old handler as described above.
a0e07ba4 1645
7403e409 1646This interface does not provide access to the ``signal blocking''
a0e07ba4
NJ
1647facility. Maybe this is not needed, since the thread support may
1648provide solutions to the problem of consistent access to data
1649structures.
1650@end deffn
1651
8f85c0c6
NJ
1652@deffn {Scheme Procedure} restore-signals
1653@deffnx {C Function} scm_restore_signals ()
a0e07ba4
NJ
1654Return all signal handlers to the values they had before any call to
1655@code{sigaction} was made. The return value is unspecified.
1656@end deffn
1657
8f85c0c6
NJ
1658@deffn {Scheme Procedure} alarm i
1659@deffnx {C Function} scm_alarm (i)
a0e07ba4
NJ
1660Set a timer to raise a @code{SIGALRM} signal after the specified
1661number of seconds (an integer). It's advisable to install a signal
1662handler for
1663@code{SIGALRM} beforehand, since the default action is to terminate
1664the process.
1665
1666The return value indicates the time remaining for the previous alarm,
1667if any. The new value replaces the previous alarm. If there was
1668no previous alarm, the return value is zero.
1669@end deffn
1670
8f85c0c6
NJ
1671@deffn {Scheme Procedure} pause
1672@deffnx {C Function} scm_pause ()
a0e07ba4
NJ
1673Pause the current process (thread?) until a signal arrives whose
1674action is to either terminate the current process or invoke a
1675handler procedure. The return value is unspecified.
1676@end deffn
1677
8f85c0c6
NJ
1678@deffn {Scheme Procedure} sleep i
1679@deffnx {C Function} scm_sleep (i)
a0e07ba4
NJ
1680Wait for the given number of seconds (an integer) or until a signal
1681arrives. The return value is zero if the time elapses or the number
1682of seconds remaining otherwise.
1683@end deffn
1684
8f85c0c6
NJ
1685@deffn {Scheme Procedure} usleep i
1686@deffnx {C Function} scm_usleep (i)
7403e409
NJ
1687Sleep for @var{i} microseconds. @code{usleep} is not available on
1688all platforms. [FIXME: so what happens when it isn't?]
a0e07ba4
NJ
1689@end deffn
1690
8f85c0c6
NJ
1691@deffn {Scheme Procedure} setitimer which_timer interval_seconds interval_microseconds value_seconds value_microseconds
1692@deffnx {C Function} scm_setitimer (which_timer, interval_seconds, interval_microseconds, value_seconds, value_microseconds)
a0e07ba4
NJ
1693Set the timer specified by @var{which_timer} according to the given
1694@var{interval_seconds}, @var{interval_microseconds},
9401323e
NJ
1695@var{value_seconds}, and @var{value_microseconds} values.
1696
1697Return information about the timer's previous setting.
9401323e
NJ
1698
1699The timers available are: @code{ITIMER_REAL}, @code{ITIMER_VIRTUAL},
1700and @code{ITIMER_PROF}.
1701
1702The return value will be a list of two cons pairs representing the
a0e07ba4 1703current state of the given timer. The first pair is the seconds and
9401323e
NJ
1704microseconds of the timer @code{it_interval}, and the second pair is
1705the seconds and microseconds of the timer @code{it_value}.
a0e07ba4
NJ
1706@end deffn
1707
8f85c0c6
NJ
1708@deffn {Scheme Procedure} getitimer which_timer
1709@deffnx {C Function} scm_getitimer (which_timer)
7403e409 1710Return information about the timer specified by @var{which_timer}.
9401323e
NJ
1711
1712The timers available are: @code{ITIMER_REAL}, @code{ITIMER_VIRTUAL},
1713and @code{ITIMER_PROF}.
1714
1715The return value will be a list of two cons pairs representing the
1716current state of the given timer. The first pair is the seconds and
1717microseconds of the timer @code{it_interval}, and the second pair is
1718the seconds and microseconds of the timer @code{it_value}.
a0e07ba4
NJ
1719@end deffn
1720
1721
1722@node Terminals and Ptys
1723@section Terminals and Ptys
1724
8f85c0c6
NJ
1725@deffn {Scheme Procedure} isatty? port
1726@deffnx {C Function} scm_isatty_p (port)
a0e07ba4
NJ
1727Return @code{#t} if @var{port} is using a serial non--file
1728device, otherwise @code{#f}.
1729@end deffn
1730
8f85c0c6
NJ
1731@deffn {Scheme Procedure} ttyname port
1732@deffnx {C Function} scm_ttyname (port)
a0e07ba4
NJ
1733Return a string with the name of the serial terminal device
1734underlying @var{port}.
1735@end deffn
1736
8f85c0c6
NJ
1737@deffn {Scheme Procedure} ctermid
1738@deffnx {C Function} scm_ctermid ()
a0e07ba4
NJ
1739Return a string containing the file name of the controlling
1740terminal for the current process.
1741@end deffn
1742
8f85c0c6
NJ
1743@deffn {Scheme Procedure} tcgetpgrp port
1744@deffnx {C Function} scm_tcgetpgrp (port)
a0e07ba4
NJ
1745Return the process group ID of the foreground process group
1746associated with the terminal open on the file descriptor
1747underlying @var{port}.
1748
1749If there is no foreground process group, the return value is a
1750number greater than 1 that does not match the process group ID
1751of any existing process group. This can happen if all of the
1752processes in the job that was formerly the foreground job have
1753terminated, and no other job has yet been moved into the
1754foreground.
1755@end deffn
1756
8f85c0c6
NJ
1757@deffn {Scheme Procedure} tcsetpgrp port pgid
1758@deffnx {C Function} scm_tcsetpgrp (port, pgid)
a0e07ba4
NJ
1759Set the foreground process group ID for the terminal used by the file
1760descriptor underlying @var{port} to the integer @var{pgid}.
1761The calling process
1762must be a member of the same session as @var{pgid} and must have the same
1763controlling terminal. The return value is unspecified.
1764@end deffn
1765
1766@node Pipes
1767@section Pipes
1768
1769The following procedures provide an interface to the @code{popen} and
7403e409 1770@code{pclose} system routines. The code is in a separate ``popen''
a0e07ba4
NJ
1771module:
1772
1773@smalllisp
1774(use-modules (ice-9 popen))
1775@end smalllisp
1776
1777@findex popen
8f85c0c6 1778@deffn {Scheme Procedure} open-pipe command modes
a0e07ba4
NJ
1779Executes the shell command @var{command} (a string) in a subprocess.
1780A pipe to the process is created and returned. @var{modes} specifies
1781whether an input or output pipe to the process is created: it should
1782be the value of @code{OPEN_READ} or @code{OPEN_WRITE}.
1783@end deffn
1784
8f85c0c6 1785@deffn {Scheme Procedure} open-input-pipe command
a0e07ba4 1786Equivalent to @code{open-pipe} with mode @code{OPEN_READ}.
bcf009c3
NJ
1787
1788@lisp
1789(read-line (open-input-pipe "date"))
1790@result{} "Mon Mar 11 20:10:44 GMT 2002"
1791
1792(waitpid WAIT_ANY)
1793@result{} (24160 . 0)
1794@end lisp
a0e07ba4
NJ
1795@end deffn
1796
8f85c0c6 1797@deffn {Scheme Procedure} open-output-pipe command
a0e07ba4
NJ
1798Equivalent to @code{open-pipe} with mode @code{OPEN_WRITE}.
1799@end deffn
1800
1801@findex pclose
8f85c0c6 1802@deffn {Scheme Procedure} close-pipe port
a0e07ba4
NJ
1803Closes the pipe created by @code{open-pipe}, then waits for the process
1804to terminate and returns its status value, @xref{Processes, waitpid}, for
1805information on how to interpret this value.
1806
1807@code{close-port} (@pxref{Closing, close-port}) can also be used to
1808close a pipe, but doesn't return the status.
1809@end deffn
1810
1811@node Networking
1812@section Networking
1813
1814@menu
1815* Network Address Conversion::
5f378d17
TTN
1816* Network Databases::
1817* Network Sockets and Communication::
bcf009c3 1818* Internet Socket Examples::
a0e07ba4
NJ
1819@end menu
1820
1821@node Network Address Conversion
1822@subsection Network Address Conversion
1823
1824This section describes procedures which convert internet addresses
1825between numeric and string formats.
1826
1827@subsubsection IPv4 Address Conversion
1828
957f9f62
KR
1829An IPv4 Internet address is a 4-byte value, represented in Guile as an
1830integer in network byte order (meaning the first byte is the most
1831significant in the number).
1832
1833@defvar INADDR_LOOPBACK
1834The address of the local host using the loopback device, ie.@:
1835@samp{127.0.0.1}.
1836@end defvar
1837
1838@defvar INADDR_BROADCAST
1839The broadcast address on the local network.
1840@end defvar
1841
1842@c INADDR_NONE is defined in the code, but serves no purpose.
1843@c inet_addr() returns it as an error indication, but that function
1844@c isn't provided, for the good reason that inet_aton() does the same
1845@c job and gives an unambiguous error indication. (INADDR_NONE is a
1846@c valid 4-byte value, in glibc it's the same as INADDR_BROADCAST.)
1847@c
1848@c @defvar INADDR_NONE
1849@c No address.
1850@c @end defvar
1851
8f85c0c6
NJ
1852@deffn {Scheme Procedure} inet-aton address
1853@deffnx {C Function} scm_inet_aton (address)
a0e07ba4
NJ
1854Convert an IPv4 Internet address from printable string
1855(dotted decimal notation) to an integer. E.g.,
1856
1857@lisp
1858(inet-aton "127.0.0.1") @result{} 2130706433
1859@end lisp
1860@end deffn
1861
8f85c0c6
NJ
1862@deffn {Scheme Procedure} inet-ntoa inetid
1863@deffnx {C Function} scm_inet_ntoa (inetid)
a0e07ba4
NJ
1864Convert an IPv4 Internet address to a printable
1865(dotted decimal notation) string. E.g.,
1866
1867@lisp
1868(inet-ntoa 2130706433) @result{} "127.0.0.1"
1869@end lisp
1870@end deffn
1871
8f85c0c6
NJ
1872@deffn {Scheme Procedure} inet-netof address
1873@deffnx {C Function} scm_inet_netof (address)
a0e07ba4
NJ
1874Return the network number part of the given IPv4
1875Internet address. E.g.,
1876
1877@lisp
1878(inet-netof 2130706433) @result{} 127
1879@end lisp
1880@end deffn
1881
8f85c0c6
NJ
1882@deffn {Scheme Procedure} inet-lnaof address
1883@deffnx {C Function} scm_lnaof (address)
a0e07ba4
NJ
1884Return the local-address-with-network part of the given
1885IPv4 Internet address, using the obsolete class A/B/C system.
1886E.g.,
1887
1888@lisp
1889(inet-lnaof 2130706433) @result{} 1
1890@end lisp
1891@end deffn
1892
8f85c0c6
NJ
1893@deffn {Scheme Procedure} inet-makeaddr net lna
1894@deffnx {C Function} scm_inet_makeaddr (net, lna)
a0e07ba4
NJ
1895Make an IPv4 Internet address by combining the network number
1896@var{net} with the local-address-within-network number
1897@var{lna}. E.g.,
1898
1899@lisp
1900(inet-makeaddr 127 1) @result{} 2130706433
1901@end lisp
1902@end deffn
1903
1904@subsubsection IPv6 Address Conversion
1905
8f85c0c6
NJ
1906@deffn {Scheme Procedure} inet-ntop family address
1907@deffnx {C Function} scm_inet_ntop (family, address)
a0e07ba4
NJ
1908Convert a network address into a printable string.
1909Note that unlike the C version of this function,
1910the input is an integer with normal host byte ordering.
1911@var{family} can be @code{AF_INET} or @code{AF_INET6}. E.g.,
1912
1913@lisp
1914(inet-ntop AF_INET 2130706433) @result{} "127.0.0.1"
1915(inet-ntop AF_INET6 (- (expt 2 128) 1)) @result{}
1916ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
1917@end lisp
1918@end deffn
1919
8f85c0c6
NJ
1920@deffn {Scheme Procedure} inet-pton family address
1921@deffnx {C Function} scm_inet_pton (family, address)
a0e07ba4
NJ
1922Convert a string containing a printable network address to
1923an integer address. Note that unlike the C version of this
1924function,
1925the result is an integer with normal host byte ordering.
1926@var{family} can be @code{AF_INET} or @code{AF_INET6}. E.g.,
1927
1928@lisp
1929(inet-pton AF_INET "127.0.0.1") @result{} 2130706433
1930(inet-pton AF_INET6 "::1") @result{} 1
1931@end lisp
1932@end deffn
1933
1934
1935@node Network Databases
1936@subsection Network Databases
1937
1938This section describes procedures which query various network databases.
1939Care should be taken when using the database routines since they are not
1940reentrant.
1941
1942@subsubsection The Host Database
1943
1944A @dfn{host object} is a structure that represents what is known about a
1945network host, and is the usual way of representing a system's network
1946identity inside software.
1947
1948The following functions accept a host object and return a selected
1949component:
1950
8f85c0c6 1951@deffn {Scheme Procedure} hostent:name host
7403e409 1952The ``official'' hostname for @var{host}.
a0e07ba4 1953@end deffn
8f85c0c6 1954@deffn {Scheme Procedure} hostent:aliases host
a0e07ba4
NJ
1955A list of aliases for @var{host}.
1956@end deffn
8f85c0c6 1957@deffn {Scheme Procedure} hostent:addrtype host
a0e07ba4
NJ
1958The host address type. For hosts with Internet addresses, this will
1959return @code{AF_INET}.
1960@end deffn
8f85c0c6 1961@deffn {Scheme Procedure} hostent:length host
a0e07ba4
NJ
1962The length of each address for @var{host}, in bytes.
1963@end deffn
8f85c0c6 1964@deffn {Scheme Procedure} hostent:addr-list host
a0e07ba4
NJ
1965The list of network addresses associated with @var{host}.
1966@end deffn
1967
1968The following procedures are used to search the host database:
1969
8f85c0c6
NJ
1970@deffn {Scheme Procedure} gethost [host]
1971@deffnx {Scheme Procedure} gethostbyname hostname
1972@deffnx {Scheme Procedure} gethostbyaddr address
1973@deffnx {C Function} scm_gethost (host)
a0e07ba4
NJ
1974Look up a host by name or address, returning a host object. The
1975@code{gethost} procedure will accept either a string name or an integer
1976address; if given no arguments, it behaves like @code{gethostent} (see
1977below). If a name or address is supplied but the address can not be
1978found, an error will be thrown to one of the keys:
1979@code{host-not-found}, @code{try-again}, @code{no-recovery} or
1980@code{no-data}, corresponding to the equivalent @code{h_error} values.
1981Unusual conditions may result in errors thrown to the
1982@code{system-error} or @code{misc_error} keys.
bcf009c3
NJ
1983
1984@lisp
1985(gethost "www.gnu.org")
1986@result{} #("www.gnu.org" () 2 4 (3353880842))
1987
1988(gethostbyname "www.emacs.org")
1989@result{} #("emacs.org" ("www.emacs.org") 2 4 (1073448978))
1990@end lisp
a0e07ba4
NJ
1991@end deffn
1992
1993The following procedures may be used to step through the host
1994database from beginning to end.
1995
8f85c0c6 1996@deffn {Scheme Procedure} sethostent [stayopen]
a0e07ba4
NJ
1997Initialize an internal stream from which host objects may be read. This
1998procedure must be called before any calls to @code{gethostent}, and may
1999also be called afterward to reset the host entry stream. If
2000@var{stayopen} is supplied and is not @code{#f}, the database is not
2001closed by subsequent @code{gethostbyname} or @code{gethostbyaddr} calls,
2002possibly giving an efficiency gain.
2003@end deffn
2004
8f85c0c6 2005@deffn {Scheme Procedure} gethostent
a0e07ba4
NJ
2006Return the next host object from the host database, or @code{#f} if
2007there are no more hosts to be found (or an error has been encountered).
2008This procedure may not be used before @code{sethostent} has been called.
2009@end deffn
2010
8f85c0c6 2011@deffn {Scheme Procedure} endhostent
a0e07ba4
NJ
2012Close the stream used by @code{gethostent}. The return value is unspecified.
2013@end deffn
2014
8f85c0c6
NJ
2015@deffn {Scheme Procedure} sethost [stayopen]
2016@deffnx {C Function} scm_sethost (stayopen)
a0e07ba4
NJ
2017If @var{stayopen} is omitted, this is equivalent to @code{endhostent}.
2018Otherwise it is equivalent to @code{sethostent stayopen}.
2019@end deffn
2020@subsubsection The Network Database
2021
2022The following functions accept an object representing a network
2023and return a selected component:
2024
8f85c0c6 2025@deffn {Scheme Procedure} netent:name net
7403e409 2026The ``official'' network name.
a0e07ba4 2027@end deffn
8f85c0c6 2028@deffn {Scheme Procedure} netent:aliases net
a0e07ba4
NJ
2029A list of aliases for the network.
2030@end deffn
8f85c0c6 2031@deffn {Scheme Procedure} netent:addrtype net
a0e07ba4
NJ
2032The type of the network number. Currently, this returns only
2033@code{AF_INET}.
2034@end deffn
8f85c0c6 2035@deffn {Scheme Procedure} netent:net net
a0e07ba4
NJ
2036The network number.
2037@end deffn
2038
2039The following procedures are used to search the network database:
2040
8f85c0c6
NJ
2041@deffn {Scheme Procedure} getnet [net]
2042@deffnx {Scheme Procedure} getnetbyname net-name
2043@deffnx {Scheme Procedure} getnetbyaddr net-number
2044@deffnx {C Function} scm_getnet (net)
a0e07ba4
NJ
2045Look up a network by name or net number in the network database. The
2046@var{net-name} argument must be a string, and the @var{net-number}
2047argument must be an integer. @code{getnet} will accept either type of
2048argument, behaving like @code{getnetent} (see below) if no arguments are
2049given.
2050@end deffn
2051
2052The following procedures may be used to step through the network
2053database from beginning to end.
2054
8f85c0c6 2055@deffn {Scheme Procedure} setnetent [stayopen]
a0e07ba4
NJ
2056Initialize an internal stream from which network objects may be read. This
2057procedure must be called before any calls to @code{getnetent}, and may
2058also be called afterward to reset the net entry stream. If
2059@var{stayopen} is supplied and is not @code{#f}, the database is not
2060closed by subsequent @code{getnetbyname} or @code{getnetbyaddr} calls,
2061possibly giving an efficiency gain.
2062@end deffn
2063
8f85c0c6 2064@deffn {Scheme Procedure} getnetent
a0e07ba4
NJ
2065Return the next entry from the network database.
2066@end deffn
2067
8f85c0c6 2068@deffn {Scheme Procedure} endnetent
a0e07ba4
NJ
2069Close the stream used by @code{getnetent}. The return value is unspecified.
2070@end deffn
2071
8f85c0c6
NJ
2072@deffn {Scheme Procedure} setnet [stayopen]
2073@deffnx {C Function} scm_setnet (stayopen)
a0e07ba4
NJ
2074If @var{stayopen} is omitted, this is equivalent to @code{endnetent}.
2075Otherwise it is equivalent to @code{setnetent stayopen}.
2076@end deffn
2077
2078@subsubsection The Protocol Database
2079
2080The following functions accept an object representing a protocol
2081and return a selected component:
2082
8f85c0c6 2083@deffn {Scheme Procedure} protoent:name protocol
7403e409 2084The ``official'' protocol name.
a0e07ba4 2085@end deffn
8f85c0c6 2086@deffn {Scheme Procedure} protoent:aliases protocol
a0e07ba4
NJ
2087A list of aliases for the protocol.
2088@end deffn
8f85c0c6 2089@deffn {Scheme Procedure} protoent:proto protocol
a0e07ba4
NJ
2090The protocol number.
2091@end deffn
2092
2093The following procedures are used to search the protocol database:
2094
8f85c0c6
NJ
2095@deffn {Scheme Procedure} getproto [protocol]
2096@deffnx {Scheme Procedure} getprotobyname name
2097@deffnx {Scheme Procedure} getprotobynumber number
2098@deffnx {C Function} scm_getproto (protocol)
a0e07ba4
NJ
2099Look up a network protocol by name or by number. @code{getprotobyname}
2100takes a string argument, and @code{getprotobynumber} takes an integer
2101argument. @code{getproto} will accept either type, behaving like
2102@code{getprotoent} (see below) if no arguments are supplied.
2103@end deffn
2104
2105The following procedures may be used to step through the protocol
2106database from beginning to end.
2107
8f85c0c6 2108@deffn {Scheme Procedure} setprotoent [stayopen]
a0e07ba4
NJ
2109Initialize an internal stream from which protocol objects may be read. This
2110procedure must be called before any calls to @code{getprotoent}, and may
2111also be called afterward to reset the protocol entry stream. If
2112@var{stayopen} is supplied and is not @code{#f}, the database is not
2113closed by subsequent @code{getprotobyname} or @code{getprotobynumber} calls,
2114possibly giving an efficiency gain.
2115@end deffn
2116
8f85c0c6 2117@deffn {Scheme Procedure} getprotoent
a0e07ba4
NJ
2118Return the next entry from the protocol database.
2119@end deffn
2120
8f85c0c6 2121@deffn {Scheme Procedure} endprotoent
a0e07ba4
NJ
2122Close the stream used by @code{getprotoent}. The return value is unspecified.
2123@end deffn
2124
8f85c0c6
NJ
2125@deffn {Scheme Procedure} setproto [stayopen]
2126@deffnx {C Function} scm_setproto (stayopen)
a0e07ba4
NJ
2127If @var{stayopen} is omitted, this is equivalent to @code{endprotoent}.
2128Otherwise it is equivalent to @code{setprotoent stayopen}.
2129@end deffn
2130
2131@subsubsection The Service Database
2132
2133The following functions accept an object representing a service
2134and return a selected component:
2135
8f85c0c6 2136@deffn {Scheme Procedure} servent:name serv
7403e409 2137The ``official'' name of the network service.
a0e07ba4 2138@end deffn
8f85c0c6 2139@deffn {Scheme Procedure} servent:aliases serv
a0e07ba4
NJ
2140A list of aliases for the network service.
2141@end deffn
8f85c0c6 2142@deffn {Scheme Procedure} servent:port serv
a0e07ba4
NJ
2143The Internet port used by the service.
2144@end deffn
8f85c0c6 2145@deffn {Scheme Procedure} servent:proto serv
a0e07ba4
NJ
2146The protocol used by the service. A service may be listed many times
2147in the database under different protocol names.
2148@end deffn
2149
2150The following procedures are used to search the service database:
2151
8f85c0c6
NJ
2152@deffn {Scheme Procedure} getserv [name [protocol]]
2153@deffnx {Scheme Procedure} getservbyname name protocol
2154@deffnx {Scheme Procedure} getservbyport port protocol
2155@deffnx {C Function} scm_getserv (name, protocol)
a0e07ba4
NJ
2156Look up a network service by name or by service number, and return a
2157network service object. The @var{protocol} argument specifies the name
2158of the desired protocol; if the protocol found in the network service
2159database does not match this name, a system error is signalled.
2160
2161The @code{getserv} procedure will take either a service name or number
2162as its first argument; if given no arguments, it behaves like
2163@code{getservent} (see below).
bcf009c3
NJ
2164
2165@lisp
2166(getserv "imap" "tcp")
2167@result{} #("imap2" ("imap") 143 "tcp")
2168
2169(getservbyport 88 "udp")
2170@result{} #("kerberos" ("kerberos5" "krb5") 88 "udp")
2171@end lisp
a0e07ba4
NJ
2172@end deffn
2173
2174The following procedures may be used to step through the service
2175database from beginning to end.
2176
8f85c0c6 2177@deffn {Scheme Procedure} setservent [stayopen]
a0e07ba4
NJ
2178Initialize an internal stream from which service objects may be read. This
2179procedure must be called before any calls to @code{getservent}, and may
2180also be called afterward to reset the service entry stream. If
2181@var{stayopen} is supplied and is not @code{#f}, the database is not
2182closed by subsequent @code{getservbyname} or @code{getservbyport} calls,
2183possibly giving an efficiency gain.
2184@end deffn
2185
8f85c0c6 2186@deffn {Scheme Procedure} getservent
a0e07ba4
NJ
2187Return the next entry from the services database.
2188@end deffn
2189
8f85c0c6 2190@deffn {Scheme Procedure} endservent
a0e07ba4
NJ
2191Close the stream used by @code{getservent}. The return value is unspecified.
2192@end deffn
2193
8f85c0c6
NJ
2194@deffn {Scheme Procedure} setserv [stayopen]
2195@deffnx {C Function} scm_setserv (stayopen)
a0e07ba4
NJ
2196If @var{stayopen} is omitted, this is equivalent to @code{endservent}.
2197Otherwise it is equivalent to @code{setservent stayopen}.
2198@end deffn
2199
2200@node Network Sockets and Communication
2201@subsection Network Sockets and Communication
2202
2203Socket ports can be created using @code{socket} and @code{socketpair}.
2204The ports are initially unbuffered, to make reading and writing to the
2205same port more reliable. A buffer can be added to the port using
7403e409 2206@code{setvbuf}; see @ref{Ports and File Descriptors}.
a0e07ba4 2207
9e996fb1
KR
2208Most systems have limits on how many files and sockets can be open, so
2209it's strongly recommended that socket ports be closed explicitly when
2210no longer required (@pxref{Ports}).
2211
7403e409
NJ
2212The convention used for ``host'' vs.@: ``network'' addresses is that
2213addresses are always held in host order at the Scheme level. The
2214procedures in this section automatically convert between host and
2215network order when required. The arguments and return values are thus
2216in host order.
a0e07ba4 2217
8f85c0c6
NJ
2218@deffn {Scheme Procedure} socket family style proto
2219@deffnx {C Function} scm_socket (family, style, proto)
a0e07ba4 2220Return a new socket port of the type specified by @var{family},
3dba2dd9
KR
2221@var{style} and @var{proto}. All three parameters are integers. The
2222possible values for @var{family} are as follows, where supported by
2223the system,
2224
2225@defvar PF_UNIX
2226@defvarx PF_INET
2227@defvarx PF_INET6
2228@end defvar
2229
2230The possible values for @var{style} are as follows, again where
2231supported by the system,
2232
2233@defvar SOCK_STREAM
2234@defvarx SOCK_DGRAM
2235@defvarx SOCK_RAW
2236@end defvar
a0e07ba4
NJ
2237
2238@var{proto} can be obtained from a protocol name using
3dba2dd9
KR
2239@code{getprotobyname} (@pxref{Network Databases}). A value of zero
2240means the default protocol, which is usually right.
a0e07ba4 2241
3dba2dd9
KR
2242A socket cannot by used for communication until it has been connected
2243somewhere, usually with either @code{connect} or @code{accept} below.
a0e07ba4
NJ
2244@end deffn
2245
8f85c0c6
NJ
2246@deffn {Scheme Procedure} socketpair family style proto
2247@deffnx {C Function} scm_socketpair (family, style, proto)
497cbe20
KR
2248Return a pair, the @code{car} and @code{cdr} of which are two unnamed
2249socket ports connected to each other. The connection is full-duplex,
2250so data can be transferred in either direction between the two.
2251
2252@var{family}, @var{style} and @var{proto} are as per @code{socket}
2253above. But many systems only support socket pairs in the
2254@code{PF_UNIX} family. Zero is likely to be the only meaningful value
2255for @var{proto}.
a0e07ba4
NJ
2256@end deffn
2257
8f85c0c6
NJ
2258@deffn {Scheme Procedure} getsockopt sock level optname
2259@deffnx {C Function} scm_getsockopt (sock, level, optname)
a0e07ba4
NJ
2260Return the value of a particular socket option for the socket
2261port @var{sock}. @var{level} is an integer code for type of
2262option being requested, e.g., @code{SOL_SOCKET} for
2263socket-level options. @var{optname} is an integer code for the
2264option required and should be specified using one of the
2265symbols @code{SO_DEBUG}, @code{SO_REUSEADDR} etc.
2266
2267The returned value is typically an integer but @code{SO_LINGER}
2268returns a pair of integers.
2269@end deffn
2270
8f85c0c6
NJ
2271@deffn {Scheme Procedure} setsockopt sock level optname value
2272@deffnx {C Function} scm_setsockopt (sock, level, optname, value)
a0e07ba4
NJ
2273Set the value of a particular socket option for the socket
2274port @var{sock}. @var{level} is an integer code for type of option
2275being set, e.g., @code{SOL_SOCKET} for socket-level options.
2276@var{optname} is an
2277integer code for the option to set and should be specified using one of
2278the symbols @code{SO_DEBUG}, @code{SO_REUSEADDR} etc.
2279@var{value} is the value to which the option should be set. For
2280most options this must be an integer, but for @code{SO_LINGER} it must
2281be a pair.
2282
2283The return value is unspecified.
2284@end deffn
2285
8f85c0c6
NJ
2286@deffn {Scheme Procedure} shutdown sock how
2287@deffnx {C Function} scm_shutdown (sock, how)
a0e07ba4 2288Sockets can be closed simply by using @code{close-port}. The
85a9b4ed 2289@code{shutdown} procedure allows reception or transmission on a
a0e07ba4
NJ
2290connection to be shut down individually, according to the parameter
2291@var{how}:
2292
2293@table @asis
2294@item 0
2295Stop receiving data for this socket. If further data arrives, reject it.
2296@item 1
2297Stop trying to transmit data from this socket. Discard any
2298data waiting to be sent. Stop looking for acknowledgement of
2299data already sent; don't retransmit it if it is lost.
2300@item 2
2301Stop both reception and transmission.
2302@end table
2303
2304The return value is unspecified.
2305@end deffn
2306
8f85c0c6
NJ
2307@deffn {Scheme Procedure} connect sock fam address . args
2308@deffnx {C Function} scm_connect (sock, fam, address, args)
a0e07ba4
NJ
2309Initiate a connection from a socket using a specified address
2310family to the address
2311specified by @var{address} and possibly @var{args}.
2312The format required for @var{address}
2313and @var{args} depends on the family of the socket.
2314
2315For a socket of family @code{AF_UNIX},
2316only @var{address} is specified and must be a string with the
2317filename where the socket is to be created.
2318
2319For a socket of family @code{AF_INET},
2320@var{address} must be an integer IPv4 host address and
2321@var{args} must be a single integer port number.
2322
2323For a socket of family @code{AF_INET6},
2324@var{address} must be an integer IPv6 host address and
2325@var{args} may be up to three integers:
2326port [flowinfo] [scope_id],
2327where flowinfo and scope_id default to zero.
2328
2329The return value is unspecified.
2330@end deffn
2331
8f85c0c6
NJ
2332@deffn {Scheme Procedure} bind sock fam address . args
2333@deffnx {C Function} scm_bind (sock, fam, address, args)
a0e07ba4
NJ
2334Assign an address to the socket port @var{sock}.
2335Generally this only needs to be done for server sockets,
2336so they know where to look for incoming connections. A socket
2337without an address will be assigned one automatically when it
2338starts communicating.
2339
2340The format of @var{address} and @var{args} depends
2341on the family of the socket.
2342
2343For a socket of family @code{AF_UNIX}, only @var{address}
2344is specified and must be a string with the filename where
2345the socket is to be created.
2346
2347For a socket of family @code{AF_INET}, @var{address}
2348must be an integer IPv4 address and @var{args}
2349must be a single integer port number.
2350
2351The values of the following variables can also be used for
2352@var{address}:
2353
2354@defvar INADDR_ANY
2355Allow connections from any address.
2356@end defvar
2357
2358@defvar INADDR_LOOPBACK
2359The address of the local host using the loopback device.
2360@end defvar
2361
2362@defvar INADDR_BROADCAST
2363The broadcast address on the local network.
2364@end defvar
2365
2366@defvar INADDR_NONE
2367No address.
2368@end defvar
2369
2370For a socket of family @code{AF_INET6}, @var{address}
2371must be an integer IPv6 address and @var{args}
2372may be up to three integers:
2373port [flowinfo] [scope_id],
2374where flowinfo and scope_id default to zero.
2375
2376The return value is unspecified.
2377@end deffn
2378
8f85c0c6
NJ
2379@deffn {Scheme Procedure} listen sock backlog
2380@deffnx {C Function} scm_listen (sock, backlog)
a0e07ba4
NJ
2381Enable @var{sock} to accept connection
2382requests. @var{backlog} is an integer specifying
2383the maximum length of the queue for pending connections.
2384If the queue fills, new clients will fail to connect until
2385the server calls @code{accept} to accept a connection from
2386the queue.
2387
2388The return value is unspecified.
2389@end deffn
2390
8f85c0c6
NJ
2391@deffn {Scheme Procedure} accept sock
2392@deffnx {C Function} scm_accept (sock)
a0e07ba4
NJ
2393Accept a connection on a bound, listening socket.
2394If there
2395are no pending connections in the queue, wait until
2396one is available unless the non-blocking option has been
2397set on the socket.
2398
2399The return value is a
7403e409 2400pair in which the @acronym{CAR} is a new socket port for the
a0e07ba4 2401connection and
7403e409 2402the @acronym{CDR} is an object with address information about the
a0e07ba4
NJ
2403client which initiated the connection.
2404
2405@var{sock} does not become part of the
2406connection and will continue to accept new requests.
2407@end deffn
2408
2409The following functions take a socket address object, as returned
2410by @code{accept} and other procedures, and return a selected component.
2411
2ce02471 2412@deffn {Scheme Procedure} sockaddr:fam sa
a0e07ba4
NJ
2413The socket family, typically equal to the value of @code{AF_UNIX} or
2414@code{AF_INET}.
2ce02471
NJ
2415@end deffn
2416@deffn {Scheme Procedure} sockaddr:path sa
a0e07ba4
NJ
2417If the socket family is @code{AF_UNIX}, returns the path of the
2418filename the socket is based on.
2ce02471
NJ
2419@end deffn
2420@deffn {Scheme Procedure} sockaddr:addr sa
a0e07ba4
NJ
2421If the socket family is @code{AF_INET}, returns the Internet host
2422address.
2ce02471
NJ
2423@end deffn
2424@deffn {Scheme Procedure} sockaddr:port sa
a0e07ba4
NJ
2425If the socket family is @code{AF_INET}, returns the Internet port
2426number.
2ce02471 2427@end deffn
a0e07ba4 2428
8f85c0c6
NJ
2429@deffn {Scheme Procedure} getsockname sock
2430@deffnx {C Function} scm_getsockname (sock)
a0e07ba4
NJ
2431Return the address of @var{sock}, in the same form as the
2432object returned by @code{accept}. On many systems the address
c16da59f 2433of a socket in the @code{AF_FILE} namespace cannot be read.
a0e07ba4
NJ
2434@end deffn
2435
8f85c0c6
NJ
2436@deffn {Scheme Procedure} getpeername sock
2437@deffnx {C Function} scm_getpeername (sock)
a0e07ba4
NJ
2438Return the address that @var{sock}
2439is connected to, in the same form as the object returned by
2440@code{accept}. On many systems the address of a socket in the
c16da59f 2441@code{AF_FILE} namespace cannot be read.
a0e07ba4
NJ
2442@end deffn
2443
8f85c0c6
NJ
2444@deffn {Scheme Procedure} recv! sock buf [flags]
2445@deffnx {C Function} scm_recv (sock, buf, flags)
a0e07ba4
NJ
2446Receive data from a socket port.
2447@var{sock} must already
2448be bound to the address from which data is to be received.
2449@var{buf} is a string into which
2450the data will be written. The size of @var{buf} limits
2451the amount of
2452data which can be received: in the case of packet
2453protocols, if a packet larger than this limit is encountered
2454then some data
2455will be irrevocably lost.
2456
2ce02471
NJ
2457@vindex MSG_OOB
2458@vindex MSG_PEEK
2459@vindex MSG_DONTROUTE
7403e409
NJ
2460The optional @var{flags} argument is a value or bitwise OR of
2461@code{MSG_OOB}, @code{MSG_PEEK}, @code{MSG_DONTROUTE} etc.
a0e07ba4
NJ
2462
2463The value returned is the number of bytes read from the
2464socket.
2465
2466Note that the data is read directly from the socket file
2467descriptor:
2468any unread buffered port data is ignored.
2469@end deffn
2470
8f85c0c6
NJ
2471@deffn {Scheme Procedure} send sock message [flags]
2472@deffnx {C Function} scm_send (sock, message, flags)
2ce02471
NJ
2473@vindex MSG_OOB
2474@vindex MSG_PEEK
2475@vindex MSG_DONTROUTE
a0e07ba4 2476Transmit the string @var{message} on a socket port @var{sock}.
7403e409
NJ
2477@var{sock} must already be bound to a destination address. The value
2478returned is the number of bytes transmitted---it's possible for this
2479to be less than the length of @var{message} if the socket is set to be
2480non-blocking. The optional @var{flags} argument is a value or bitwise
2481OR of @code{MSG_OOB}, @code{MSG_PEEK}, @code{MSG_DONTROUTE} etc.
a0e07ba4
NJ
2482
2483Note that the data is written directly to the socket
2484file descriptor:
2485any unflushed buffered port data is ignored.
2486@end deffn
2487
8f85c0c6
NJ
2488@deffn {Scheme Procedure} recvfrom! sock str [flags [start [end]]]
2489@deffnx {C Function} scm_recvfrom (sock, str, flags, start, end)
a0e07ba4
NJ
2490Return data from the socket port @var{sock} and also
2491information about where the data was received from.
2492@var{sock} must already be bound to the address from which
2493data is to be received. @code{str}, is a string into which the
2494data will be written. The size of @var{str} limits the amount
2495of data which can be received: in the case of packet protocols,
2496if a packet larger than this limit is encountered then some
2497data will be irrevocably lost.
2498
2ce02471
NJ
2499@vindex MSG_OOB
2500@vindex MSG_PEEK
2501@vindex MSG_DONTROUTE
a0e07ba4
NJ
2502The optional @var{flags} argument is a value or bitwise OR of
2503@code{MSG_OOB}, @code{MSG_PEEK}, @code{MSG_DONTROUTE} etc.
2504
7403e409
NJ
2505The value returned is a pair: the @acronym{CAR} is the number of
2506bytes read from the socket and the @acronym{CDR} an address object
a0e07ba4
NJ
2507in the same form as returned by @code{accept}. The address
2508will given as @code{#f} if not available, as is usually the
2509case for stream sockets.
2510
2511The @var{start} and @var{end} arguments specify a substring of
2512@var{str} to which the data should be written.
2513
2514Note that the data is read directly from the socket file
2515descriptor: any unread buffered port data is ignored.
2516@end deffn
2517
8f85c0c6
NJ
2518@deffn {Scheme Procedure} sendto sock message fam address . args_and_flags
2519@deffnx {C Function} scm_sendto (sock, message, fam, address, args_and_flags)
a0e07ba4
NJ
2520Transmit the string @var{message} on the socket port
2521@var{sock}. The
2522destination address is specified using the @var{fam},
2523@var{address} and
2524@var{args_and_flags} arguments, in a similar way to the
2525@code{connect} procedure. @var{args_and_flags} contains
2526the usual connection arguments optionally followed by
2527a flags argument, which is a value or
7403e409 2528bitwise OR of @code{MSG_OOB}, @code{MSG_PEEK}, @code{MSG_DONTROUTE} etc.
a0e07ba4
NJ
2529
2530The value returned is the number of bytes transmitted --
2531it's possible for
2532this to be less than the length of @var{message} if the
2533socket is
2534set to be non-blocking.
2535Note that the data is written directly to the socket
2536file descriptor:
2537any unflushed buffered port data is ignored.
2538@end deffn
2539
2540The following functions can be used to convert short and long integers
7403e409 2541between ``host'' and ``network'' order. Although the procedures above do
a0e07ba4
NJ
2542this automatically for addresses, the conversion will still need to
2543be done when sending or receiving encoded integer data from the network.
2544
8f85c0c6
NJ
2545@deffn {Scheme Procedure} htons value
2546@deffnx {C Function} scm_htons (value)
a0e07ba4
NJ
2547Convert a 16 bit quantity from host to network byte ordering.
2548@var{value} is packed into 2 bytes, which are then converted
2549and returned as a new integer.
2550@end deffn
2551
8f85c0c6
NJ
2552@deffn {Scheme Procedure} ntohs value
2553@deffnx {C Function} scm_ntohs (value)
a0e07ba4
NJ
2554Convert a 16 bit quantity from network to host byte ordering.
2555@var{value} is packed into 2 bytes, which are then converted
2556and returned as a new integer.
2557@end deffn
2558
8f85c0c6
NJ
2559@deffn {Scheme Procedure} htonl value
2560@deffnx {C Function} scm_htonl (value)
a0e07ba4
NJ
2561Convert a 32 bit quantity from host to network byte ordering.
2562@var{value} is packed into 4 bytes, which are then converted
2563and returned as a new integer.
2564@end deffn
2565
8f85c0c6
NJ
2566@deffn {Scheme Procedure} ntohl value
2567@deffnx {C Function} scm_ntohl (value)
a0e07ba4
NJ
2568Convert a 32 bit quantity from network to host byte ordering.
2569@var{value} is packed into 4 bytes, which are then converted
2570and returned as a new integer.
2571@end deffn
2572
2573These procedures are inconvenient to use at present, but consider:
2574
2575@example
2576(define write-network-long
2577 (lambda (value port)
2578 (let ((v (make-uniform-vector 1 1 0)))
2579 (uniform-vector-set! v 0 (htonl value))
2580 (uniform-vector-write v port))))
2581
2582(define read-network-long
2583 (lambda (port)
2584 (let ((v (make-uniform-vector 1 1 0)))
2585 (uniform-vector-read! v port)
2586 (ntohl (uniform-vector-ref v 0)))))
2587@end example
2588
bcf009c3
NJ
2589
2590@node Internet Socket Examples
2591@subsection Network Socket Examples
2592
2593The following sections give examples of how to use network sockets.
2594
2595@menu
2596* Internet Socket Client::
2597* Internet Socket Server::
2598@end menu
2599
2600
2601@node Internet Socket Client
2602@subsubsection Internet Socket Client Example
2603
2604@cindex socket client example
2605The following example demonstrates an Internet socket client.
2606It connects to the HTTP daemon running on the local machine and
2607returns the contents of the root index URL.
2608
2609@example
2610(let ((s (socket AF_INET SOCK_STREAM 0)))
2611 (connect s AF_INET (inet-aton "127.0.0.1") 80)
2612 (display "GET / HTTP/1.0\r\n\r\n" s)
2613
2614 (do ((line (read-line s) (read-line s)))
2615 ((eof-object? line))
2616 (display line)
2617 (newline)))
2618@end example
2619
2620
2621@node Internet Socket Server
2622@subsubsection Internet Socket Server Example
2623
2624@cindex socket server example
2625The following example shows a simple Internet server which listens on
2626port 2904 for incoming connections and sends a greeting back to the
2627client.
2628
2629@example
2630(let ((s (socket AF_INET SOCK_STREAM 0)))
2631 (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
7403e409
NJ
2632 ;; @r{Specific address?}
2633 ;; @r{(bind s AF_INET (inet-aton "127.0.0.1") 2904)}
bcf009c3
NJ
2634 (bind s AF_INET INADDR_ANY 2904)
2635 (listen s 5)
2636
2637 (simple-format #t "Listening for clients in pid: ~S" (getpid))
2638 (newline)
2639
2640 (while #t
2641 (let* ((client-connection (accept s))
2642 (client-details (cdr client-connection))
2643 (client (car client-connection)))
2644 (simple-format #t "Got new client connection: ~S"
2645 client-details)
2646 (newline)
2647 (simple-format #t "Client address: ~S"
2648 (gethostbyaddr
2649 (sockaddr:addr client-details)))
2650 (newline)
7403e409 2651 ;; @r{Send back the greeting to the client port}
bcf009c3
NJ
2652 (display "Hello client\r\n" client)
2653 (close client))))
2654@end example
2655
2656
a0e07ba4
NJ
2657@node System Identification
2658@section System Identification
2659
2660This section lists the various procedures Guile provides for accessing
2661information about the system it runs on.
2662
8f85c0c6
NJ
2663@deffn {Scheme Procedure} uname
2664@deffnx {C Function} scm_uname ()
a0e07ba4
NJ
2665Return an object with some information about the computer
2666system the program is running on.
a0e07ba4
NJ
2667
2668The following procedures accept an object as returned by @code{uname}
2669and return a selected component.
2670
2ce02471 2671@deffn {Scheme Procedure} utsname:sysname un
a0e07ba4 2672The name of the operating system.
2ce02471
NJ
2673@end deffn
2674@deffn {Scheme Procedure} utsname:nodename un
a0e07ba4 2675The network name of the computer.
2ce02471
NJ
2676@end deffn
2677@deffn {Scheme Procedure} utsname:release un
a0e07ba4 2678The current release level of the operating system implementation.
2ce02471
NJ
2679@end deffn
2680@deffn {Scheme Procedure} utsname:version un
a0e07ba4 2681The current version level within the release of the operating system.
2ce02471
NJ
2682@end deffn
2683@deffn {Scheme Procedure} utsname:machine un
a0e07ba4 2684A description of the hardware.
2ce02471
NJ
2685@end deffn
2686@end deffn
a0e07ba4 2687
8f85c0c6
NJ
2688@deffn {Scheme Procedure} gethostname
2689@deffnx {C Function} scm_gethostname ()
a0e07ba4
NJ
2690Return the host name of the current processor.
2691@end deffn
2692
8f85c0c6
NJ
2693@deffn {Scheme Procedure} sethostname name
2694@deffnx {C Function} scm_sethostname (name)
a0e07ba4
NJ
2695Set the host name of the current processor to @var{name}. May
2696only be used by the superuser. The return value is not
2697specified.
2698@end deffn
2699
2700@c FIXME::martin: Not in libguile!
8f85c0c6 2701@deffn {Scheme Procedure} software-type
a0e07ba4 2702Return a symbol describing the current platform's operating system.
7403e409
NJ
2703This may be one of @samp{AIX}, @samp{VMS}, @samp{UNIX},
2704@samp{COHERENT}, @samp{WINDOWS}, @samp{MS-DOS}, @samp{OS/2},
2705@samp{THINKC}, @samp{AMIGA}, @samp{ATARIST}, @samp{MACH}, or
2706@samp{ACORN}.
a0e07ba4 2707
7403e409 2708Note that most varieties of Unix are considered to be simply @samp{UNIX}.
a0e07ba4
NJ
2709That is because when a program depends on features that are not present
2710on every operating system, it is usually better to test for the presence
2711or absence of that specific feature. The return value of
2712@code{software-type} should only be used for this purpose when there is
2713no other easy or unambiguous way of detecting such features.
2714@end deffn
2715
2716@node Locales
2717@section Locales
2718
8f85c0c6
NJ
2719@deffn {Scheme Procedure} setlocale category [locale]
2720@deffnx {C Function} scm_setlocale (category, locale)
74f76d62
KR
2721Get or set the current locale, used for various internationalizations.
2722Locales are strings, such as @samp{sv_SE}.
2723
2724If @var{locale} is given then the locale for the given category is set
2725and the new value returned. If @var{locale} is not given then the
2726current value is returned. @var{category} should be one of the
2727following values
2728
2729@defvar LC_ALL
2730@defvarx LC_COLLATE
2731@defvarx LC_CTYPE
2732@defvarx LC_MESSAGES
2733@defvarx LC_MONETARY
2734@defvarx LC_NUMERIC
2735@defvarx LC_TIME
2736@end defvar
2737
2738A common usage is @samp{(setlocale LC_ALL "")}, which initializes all
2739categories based on standard environment variables (@code{LANG} etc).
2740For full details on categories and locale names @pxref{Locales,,
2741Locales and Internationalization, libc, The GNU C Library Reference
2742Manual}.
a0e07ba4
NJ
2743@end deffn
2744
2745@node Encryption
2746@section Encryption
2747
2748Please note that the procedures in this section are not suited for
2749strong encryption, they are only interfaces to the well-known and
2750common system library functions of the same name. They are just as good
2751(or bad) as the underlying functions, so you should refer to your system
2752documentation before using them.
2753
8f85c0c6
NJ
2754@deffn {Scheme Procedure} crypt key salt
2755@deffnx {C Function} scm_crypt (key, salt)
a0e07ba4 2756Encrypt @var{key} using @var{salt} as the salt value to the
9401323e 2757crypt(3) library call.
a0e07ba4
NJ
2758@end deffn
2759
5f378d17
TTN
2760Although @code{getpass} is not an encryption procedure per se, it
2761appears here because it is often used in combination with @code{crypt}:
a0e07ba4 2762
8f85c0c6
NJ
2763@deffn {Scheme Procedure} getpass prompt
2764@deffnx {C Function} scm_getpass (prompt)
a0e07ba4
NJ
2765Display @var{prompt} to the standard error output and read
2766a password from @file{/dev/tty}. If this file is not
2767accessible, it reads from standard input. The password may be
2768up to 127 characters in length. Additional characters and the
2769terminating newline character are discarded. While reading
2770the password, echoing and the generation of signals by special
2771characters is disabled.
2772@end deffn