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