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