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