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