* alist.c, eval.c, net_db.c, posix.c, print.c, snarf.h, struct.c,
[bpt/guile.git] / libguile / posix.c
1 /* Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
43 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
44
45 \f
46
47 #include <stdio.h>
48 #include "_scm.h"
49 #include "fports.h"
50 #include "scmsigs.h"
51 #include "feature.h"
52
53 #include "validate.h"
54 #include "posix.h"
55 \f
56
57 #ifdef HAVE_STRING_H
58 #include <string.h>
59 #endif
60 #ifdef TIME_WITH_SYS_TIME
61 # include <sys/time.h>
62 # include <time.h>
63 #else
64 # if HAVE_SYS_TIME_H
65 # include <sys/time.h>
66 # else
67 # include <time.h>
68 # endif
69 #endif
70
71 #ifdef HAVE_UNISTD_H
72 #include <unistd.h>
73 #else
74 #ifndef ttyname
75 extern char *ttyname();
76 #endif
77 #endif
78
79 #ifdef LIBC_H_WITH_UNISTD_H
80 #include <libc.h>
81 #endif
82
83 #include <sys/types.h>
84 #include <sys/stat.h>
85 #include <fcntl.h>
86
87 #include <pwd.h>
88
89 #if HAVE_SYS_WAIT_H
90 # include <sys/wait.h>
91 #endif
92 #ifndef WEXITSTATUS
93 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
94 #endif
95 #ifndef WIFEXITED
96 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
97 #endif
98
99 #include <signal.h>
100
101 extern FILE *popen ();
102 extern char ** environ;
103
104 #include <grp.h>
105 #include <sys/utsname.h>
106
107 #if HAVE_DIRENT_H
108 # include <dirent.h>
109 # define NAMLEN(dirent) strlen((dirent)->d_name)
110 #else
111 # define dirent direct
112 # define NAMLEN(dirent) (dirent)->d_namlen
113 # if HAVE_SYS_NDIR_H
114 # include <sys/ndir.h>
115 # endif
116 # if HAVE_SYS_DIR_H
117 # include <sys/dir.h>
118 # endif
119 # if HAVE_NDIR_H
120 # include <ndir.h>
121 # endif
122 #endif
123
124 #ifdef HAVE_SETLOCALE
125 #include <locale.h>
126 #endif
127
128 /* Some Unix systems don't define these. CPP hair is dangerous, but
129 this seems safe enough... */
130 #ifndef R_OK
131 #define R_OK 4
132 #endif
133
134 #ifndef W_OK
135 #define W_OK 2
136 #endif
137
138 #ifndef X_OK
139 #define X_OK 1
140 #endif
141
142 #ifndef F_OK
143 #define F_OK 0
144 #endif
145
146 /* On NextStep, <utime.h> doesn't define struct utime, unless we
147 #define _POSIX_SOURCE before #including it. I think this is less
148 of a kludge than defining struct utimbuf ourselves. */
149 #ifdef UTIMBUF_NEEDS_POSIX
150 #define _POSIX_SOURCE
151 #endif
152
153 #ifdef HAVE_SYS_UTIME_H
154 #include <sys/utime.h>
155 #endif
156
157 #ifdef HAVE_UTIME_H
158 #include <utime.h>
159 #endif
160
161 /* Please don't add any more #includes or #defines here. The hack
162 above means that _POSIX_SOURCE may be #defined, which will
163 encourage header files to do strange things. */
164
165 \f
166 SCM_SYMBOL (sym_read_pipe, "read pipe");
167 SCM_SYMBOL (sym_write_pipe, "write pipe");
168
169 SCM_DEFINE (scm_pipe, "pipe", 0, 0, 0,
170 (),
171 "Returns a newly created pipe: a pair of ports which are linked\n"
172 "together on the local machine. The CAR is the input port and\n"
173 "the CDR is the output port. Data written (and flushed) to the\n"
174 "output port can be read from the input port.\n"
175 "Pipes are commonly used for communication with a newly\n"
176 "forked child process. The need to flush the output port\n"
177 "can be avoided by making it unbuffered using @code{setvbuf}.\n\n"
178 "Writes occur atomically provided the size of the data in\n"
179 "bytes is not greater than the value of @code{PIPE_BUF}\n"
180 "Note that the output port is likely to block if too much data\n"
181 "(typically equal to @code{PIPE_BUF}) has been written but not\n"
182 "yet read from the input port\n"
183 )
184 #define FUNC_NAME s_scm_pipe
185 {
186 int fd[2], rv;
187 SCM p_rd, p_wt;
188
189 rv = pipe (fd);
190 if (rv)
191 SCM_SYSERROR;
192
193 p_rd = scm_fdes_to_port (fd[0], "r", sym_read_pipe);
194 p_wt = scm_fdes_to_port (fd[1], "w", sym_write_pipe);
195 return scm_cons (p_rd, p_wt);
196 }
197 #undef FUNC_NAME
198
199
200 #ifdef HAVE_GETGROUPS
201 SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
202 (),
203 "Returns a vector of integers representing the current supplimentary group IDs.")
204 #define FUNC_NAME s_scm_getgroups
205 {
206 SCM grps, ans;
207 int ngroups = getgroups (0, NULL);
208 if (!ngroups)
209 SCM_SYSERROR;
210 SCM_NEWCELL(grps);
211 SCM_DEFER_INTS;
212 {
213 GETGROUPS_T *groups;
214 int val;
215
216 groups = SCM_MUST_MALLOC_TYPE_NUM(GETGROUPS_T,ngroups);
217 val = getgroups(ngroups, groups);
218 if (val < 0)
219 {
220 int en = errno;
221 scm_must_free((char *)groups);
222 errno = en;
223 SCM_SYSERROR;
224 }
225 SCM_SETCHARS(grps, groups); /* set up grps as a GC protect */
226 SCM_SETLENGTH(grps, 0L + ngroups * sizeof(GETGROUPS_T), scm_tc7_string);
227 ans = scm_make_vector (SCM_MAKINUM(ngroups), SCM_UNDEFINED);
228 while (--ngroups >= 0) SCM_VELTS(ans)[ngroups] = SCM_MAKINUM(groups[ngroups]);
229 SCM_SETCHARS(grps, groups); /* to make sure grps stays around. */
230 SCM_ALLOW_INTS;
231 return ans;
232 }
233 }
234 #undef FUNC_NAME
235 #endif
236
237
238 SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
239 (SCM user),
240 "Look up an entry in the user database. @var{obj} can be an integer,\n"
241 "a string, or omitted, giving the behaviour of getpwuid, getpwnam\n"
242 "or getpwent respectively.")
243 #define FUNC_NAME s_scm_getpwuid
244 {
245 SCM result;
246 struct passwd *entry;
247 SCM *ve;
248
249 result = scm_make_vector (SCM_MAKINUM (7), SCM_UNSPECIFIED);
250 ve = SCM_VELTS (result);
251 if (SCM_UNBNDP (user) || SCM_FALSEP (user))
252 {
253 SCM_SYSCALL (entry = getpwent ());
254 if (! entry)
255 {
256 return SCM_BOOL_F;
257 }
258 }
259 else if (SCM_INUMP (user))
260 {
261 entry = getpwuid (SCM_INUM (user));
262 }
263 else
264 {
265 SCM_VALIDATE_ROSTRING (1,user);
266 if (SCM_SUBSTRP (user))
267 user = scm_makfromstr (SCM_ROCHARS (user), SCM_ROLENGTH (user), 0);
268 entry = getpwnam (SCM_ROCHARS (user));
269 }
270 if (!entry)
271 SCM_MISC_ERROR ("entry not found", SCM_EOL);
272
273 ve[0] = scm_makfrom0str (entry->pw_name);
274 ve[1] = scm_makfrom0str (entry->pw_passwd);
275 ve[2] = scm_ulong2num ((unsigned long) entry->pw_uid);
276 ve[3] = scm_ulong2num ((unsigned long) entry->pw_gid);
277 ve[4] = scm_makfrom0str (entry->pw_gecos);
278 if (!entry->pw_dir)
279 ve[5] = scm_makfrom0str ("");
280 else
281 ve[5] = scm_makfrom0str (entry->pw_dir);
282 if (!entry->pw_shell)
283 ve[6] = scm_makfrom0str ("");
284 else
285 ve[6] = scm_makfrom0str (entry->pw_shell);
286 return result;
287 }
288 #undef FUNC_NAME
289
290
291 #ifdef HAVE_SETPWENT
292 SCM_DEFINE (scm_setpwent, "setpw", 0, 1, 0,
293 (SCM arg),
294 "If called with a true argument, initialize or reset the password data\n"
295 "stream. Otherwise, close the stream. The @code{setpwent} and\n"
296 "@code{endpwent} procedures are implemented on top of this.")
297 #define FUNC_NAME s_scm_setpwent
298 {
299 if (SCM_UNBNDP (arg) || SCM_FALSEP (arg))
300 endpwent ();
301 else
302 setpwent ();
303 return SCM_UNSPECIFIED;
304 }
305 #undef FUNC_NAME
306 #endif
307
308
309
310 /* Combines getgrgid and getgrnam. */
311 SCM_DEFINE (scm_getgrgid, "getgr", 0, 1, 0,
312 (SCM name),
313 "Look up an entry in the group database. @var{obj} can be an integer,\n"
314 "a string, or omitted, giving the behaviour of getgrgid, getgrnam\n"
315 "or getgrent respectively.")
316 #define FUNC_NAME s_scm_getgrgid
317 {
318 SCM result;
319 struct group *entry;
320 SCM *ve;
321 result = scm_make_vector (SCM_MAKINUM (4), SCM_UNSPECIFIED);
322 ve = SCM_VELTS (result);
323 if (SCM_UNBNDP (name) || (name == SCM_BOOL_F))
324 {
325 SCM_SYSCALL (entry = getgrent ());
326 if (! entry)
327 {
328 return SCM_BOOL_F;
329 }
330 }
331 else if (SCM_INUMP (name))
332 SCM_SYSCALL (entry = getgrgid (SCM_INUM (name)));
333 else
334 {
335 SCM_VALIDATE_ROSTRING (1,name);
336 SCM_COERCE_SUBSTR (name);
337 SCM_SYSCALL (entry = getgrnam (SCM_ROCHARS (name)));
338 }
339 if (!entry)
340 SCM_SYSERROR;
341
342 ve[0] = scm_makfrom0str (entry->gr_name);
343 ve[1] = scm_makfrom0str (entry->gr_passwd);
344 ve[2] = scm_ulong2num ((unsigned long) entry->gr_gid);
345 ve[3] = scm_makfromstrs (-1, entry->gr_mem);
346 return result;
347 }
348 #undef FUNC_NAME
349
350
351
352 SCM_DEFINE (scm_setgrent, "setgr", 0, 1, 0,
353 (SCM arg),
354 "If called with a true argument, initialize or reset the group data\n"
355 "stream. Otherwise, close the stream. The @code{setgrent} and\n"
356 "@code{endgrent} procedures are implemented on top of this.")
357 #define FUNC_NAME s_scm_setgrent
358 {
359 if (SCM_UNBNDP (arg) || SCM_FALSEP (arg))
360 endgrent ();
361 else
362 setgrent ();
363 return SCM_UNSPECIFIED;
364 }
365 #undef FUNC_NAME
366
367
368
369 SCM_DEFINE (scm_kill, "kill", 2, 0, 0,
370 (SCM pid, SCM sig),
371 "Sends a signal to the specified process or group of processes.\n\n"
372 "@var{pid} specifies the processes to which the signal is sent:\n\n"
373 "@table @r\n"
374 "@item @var{pid} greater than 0\n"
375 "The process whose identifier is @var{pid}.\n"
376 "@item @var{pid} equal to 0\n"
377 "All processes in the current process group.\n"
378 "@item @var{pid} less than -1\n"
379 "The process group whose identifier is -@var{pid}\n"
380 "@item @var{pid} equal to -1\n"
381 "If the process is privileged, all processes except for some special\n"
382 "system processes. Otherwise, all processes with the current effective\n"
383 "user ID.\n"
384 "@end table\n\n"
385 "@var{sig} should be specified using a variable corresponding to\n"
386 "the Unix symbolic name, e.g.,\n\n"
387 "@defvar SIGHUP\n"
388 "Hang-up signal.\n"
389 "@end defvar\n\n"
390 "@defvar SIGINT\n"
391 "Interrupt signal.\n"
392 "@end defvar")
393 #define FUNC_NAME s_scm_kill
394 {
395 SCM_VALIDATE_INUM (1,pid);
396 SCM_VALIDATE_INUM (2,sig);
397 /* Signal values are interned in scm_init_posix(). */
398 if (kill ((int) SCM_INUM (pid), (int) SCM_INUM (sig)) != 0)
399 SCM_SYSERROR;
400 return SCM_UNSPECIFIED;
401 }
402 #undef FUNC_NAME
403
404 #ifdef HAVE_WAITPID
405 SCM_DEFINE (scm_waitpid, "waitpid", 1, 1, 0,
406 (SCM pid, SCM options),
407 "This procedure collects status information from a child process which\n"
408 "has terminated or (optionally) stopped. Normally it will\n"
409 "suspend the calling process until this can be done. If more than one\n"
410 "child process is eligible then one will be chosen by the operating system.\n\n"
411 "The value of @var{pid} determines the behaviour:\n\n"
412 "@table @r\n"
413 "@item @var{pid} greater than 0\n"
414 "Request status information from the specified child process.\n"
415 "@item @var{pid} equal to -1 or WAIT_ANY\n"
416 "Request status information for any child process.\n"
417 "@item @var{pid} equal to 0 or WAIT_MYPGRP\n"
418 "Request status information for any child process in the current process\n"
419 "group.\n"
420 "@item @var{pid} less than -1\n"
421 "Request status information for any child process whose process group ID\n"
422 "is -@var{PID}.\n"
423 "@end table\n\n"
424 "The @var{options} argument, if supplied, should be the bitwise OR of the\n"
425 "values of zero or more of the following variables:\n\n"
426 "@defvar WNOHANG\n"
427 "Return immediately even if there are no child processes to be collected.\n"
428 "@end defvar\n\n"
429 "@defvar WUNTRACED\n"
430 "Report status information for stopped processes as well as terminated\n"
431 "processes.\n"
432 "@end defvar\n\n"
433 "The return value is a pair containing:\n\n"
434 "@enumerate\n"
435 "@item\n"
436 "The process ID of the child process, or 0 if @code{WNOHANG} was\n"
437 "specified and no process was collected.\n"
438 "@item\n"
439 "The integer status value.\n"
440 "@end enumerate")
441 #define FUNC_NAME s_scm_waitpid
442 {
443 int i;
444 int status;
445 int ioptions;
446 SCM_VALIDATE_INUM (1,pid);
447 if (SCM_UNBNDP (options))
448 ioptions = 0;
449 else
450 {
451 SCM_VALIDATE_INUM (2,options);
452 /* Flags are interned in scm_init_posix. */
453 ioptions = SCM_INUM (options);
454 }
455 SCM_SYSCALL (i = waitpid (SCM_INUM (pid), &status, ioptions));
456 if (i == -1)
457 SCM_SYSERROR;
458 return scm_cons (SCM_MAKINUM (0L + i), SCM_MAKINUM (0L + status));
459 }
460 #undef FUNC_NAME
461 #endif /* HAVE_WAITPID */
462
463 SCM_DEFINE (scm_status_exit_val, "status:exit-val", 1, 0, 0,
464 (SCM status),
465 "Returns the exit status value, as would be\n"
466 "set if a process ended normally through a\n"
467 "call to @code{exit} or @code{_exit}, if any, otherwise @code{#f}.")
468 #define FUNC_NAME s_scm_status_exit_val
469 {
470 int lstatus;
471
472 SCM_VALIDATE_INUM (1,status);
473
474 /* On Ultrix, the WIF... macros assume their argument is an lvalue;
475 go figure. SCM_INUM does not yield an lvalue. */
476 lstatus = SCM_INUM (status);
477 if (WIFEXITED (lstatus))
478 return (SCM_MAKINUM (WEXITSTATUS (lstatus)));
479 else
480 return SCM_BOOL_F;
481 }
482 #undef FUNC_NAME
483
484 SCM_DEFINE (scm_status_term_sig, "status:term-sig", 1, 0, 0,
485 (SCM status),
486 "Returns the signal number which terminated the\n"
487 "process, if any, otherwise @code{#f}.")
488 #define FUNC_NAME s_scm_status_term_sig
489 {
490 int lstatus;
491
492 SCM_VALIDATE_INUM (1,status);
493
494 lstatus = SCM_INUM (status);
495 if (WIFSIGNALED (lstatus))
496 return SCM_MAKINUM (WTERMSIG (lstatus));
497 else
498 return SCM_BOOL_F;
499 }
500 #undef FUNC_NAME
501
502 SCM_DEFINE (scm_status_stop_sig, "status:stop-sig", 1, 0, 0,
503 (SCM status),
504 "Returns the signal number which stopped the\n"
505 "process, if any, otherwise @code{#f}.")
506 #define FUNC_NAME s_scm_status_stop_sig
507 {
508 int lstatus;
509
510 SCM_VALIDATE_INUM (1,status);
511
512 lstatus = SCM_INUM (status);
513 if (WIFSTOPPED (lstatus))
514 return SCM_MAKINUM (WSTOPSIG (lstatus));
515 else
516 return SCM_BOOL_F;
517 }
518 #undef FUNC_NAME
519
520 SCM_DEFINE (scm_getppid, "getppid", 0, 0, 0,
521 (),
522 "Returns an integer representing the process ID of the parent process.")
523 #define FUNC_NAME s_scm_getppid
524 {
525 return SCM_MAKINUM (0L + getppid ());
526 }
527 #undef FUNC_NAME
528
529
530
531 SCM_DEFINE (scm_getuid, "getuid", 0, 0, 0,
532 (),
533 "Returns an integer representing the current real user ID.")
534 #define FUNC_NAME s_scm_getuid
535 {
536 return SCM_MAKINUM (0L + getuid ());
537 }
538 #undef FUNC_NAME
539
540
541
542 SCM_DEFINE (scm_getgid, "getgid", 0, 0, 0,
543 (),
544 "Returns an integer representing the current real group ID.")
545 #define FUNC_NAME s_scm_getgid
546 {
547 return SCM_MAKINUM (0L + getgid ());
548 }
549 #undef FUNC_NAME
550
551
552
553 SCM_DEFINE (scm_geteuid, "geteuid", 0, 0, 0,
554 (),
555 "Returns an integer representing the current effective user ID.\n"
556 "If the system does not support effective IDs, then the real ID\n"
557 "is returned. @code{(feature? 'EIDs)} reports whether the system\n"
558 "supports effective IDs.")
559 #define FUNC_NAME s_scm_geteuid
560 {
561 #ifdef HAVE_GETEUID
562 return SCM_MAKINUM (0L + geteuid ());
563 #else
564 return SCM_MAKINUM (0L + getuid ());
565 #endif
566 }
567 #undef FUNC_NAME
568
569
570
571 SCM_DEFINE (scm_getegid, "getegid", 0, 0, 0,
572 (),
573 "Returns an integer representing the current effective group ID.\n"
574 "If the system does not support effective IDs, then the real ID\n"
575 "is returned. @code{(feature? 'EIDs)} reports whether the system\n"
576 "supports effective IDs.")
577 #define FUNC_NAME s_scm_getegid
578 {
579 #ifdef HAVE_GETEUID
580 return SCM_MAKINUM (0L + getegid ());
581 #else
582 return SCM_MAKINUM (0L + getgid ());
583 #endif
584 }
585 #undef FUNC_NAME
586
587
588 SCM_DEFINE (scm_setuid, "setuid", 1, 0, 0,
589 (SCM id),
590 "Sets both the real and effective user IDs to the integer @var{id}, provided\n"
591 "the process has appropriate privileges.\n"
592 "The return value is unspecified.")
593 #define FUNC_NAME s_scm_setuid
594 {
595 SCM_VALIDATE_INUM (1,id);
596 if (setuid (SCM_INUM (id)) != 0)
597 SCM_SYSERROR;
598 return SCM_UNSPECIFIED;
599 }
600 #undef FUNC_NAME
601
602 SCM_DEFINE (scm_setgid, "setgid", 1, 0, 0,
603 (SCM id),
604 "Sets both the real and effective group IDs to the integer @var{id}, provided\n"
605 "the process has appropriate privileges.\n"
606 "The return value is unspecified.")
607 #define FUNC_NAME s_scm_setgid
608 {
609 SCM_VALIDATE_INUM (1,id);
610 if (setgid (SCM_INUM (id)) != 0)
611 SCM_SYSERROR;
612 return SCM_UNSPECIFIED;
613 }
614 #undef FUNC_NAME
615
616 SCM_DEFINE (scm_seteuid, "seteuid", 1, 0, 0,
617 (SCM id),
618 "Sets the effective user ID to the integer @var{id}, provided the process\n"
619 "has appropriate privileges. If effective IDs are not supported, the\n"
620 "real ID is set instead -- @code{(feature? 'EIDs)} reports whether the\n"
621 "system supports effective IDs.\n"
622 "The return value is unspecified.")
623 #define FUNC_NAME s_scm_seteuid
624 {
625 int rv;
626
627 SCM_VALIDATE_INUM (1,id);
628 #ifdef HAVE_SETEUID
629 rv = seteuid (SCM_INUM (id));
630 #else
631 rv = setuid (SCM_INUM (id));
632 #endif
633 if (rv != 0)
634 SCM_SYSERROR;
635 return SCM_UNSPECIFIED;
636 }
637 #undef FUNC_NAME
638
639 #ifdef HAVE_SETEGID
640 SCM_DEFINE (scm_setegid, "setegid", 1, 0, 0,
641 (SCM id),
642 "Sets the effective group ID to the integer @var{id}, provided the process\n"
643 "has appropriate privileges. If effective IDs are not supported, the\n"
644 "real ID is set instead -- @code{(feature? 'EIDs)} reports whether the\n"
645 "system supports effective IDs.\n"
646 "The return value is unspecified.")
647 #define FUNC_NAME s_scm_setegid
648 {
649 int rv;
650
651 SCM_VALIDATE_INUM (1,id);
652 #ifdef HAVE_SETEUID
653 rv = setegid (SCM_INUM (id));
654 #else
655 rv = setgid (SCM_INUM (id));
656 #endif
657 if (rv != 0)
658 SCM_SYSERROR;
659 return SCM_UNSPECIFIED;
660
661 }
662 #undef FUNC_NAME
663 #endif
664
665 SCM_DEFINE (scm_getpgrp, "getpgrp", 0, 0, 0,
666 (),
667 "Returns an integer representing the current process group ID.\n"
668 "This is the POSIX definition, not BSD.")
669 #define FUNC_NAME s_scm_getpgrp
670 {
671 int (*fn)();
672 fn = (int (*) ()) getpgrp;
673 return SCM_MAKINUM (fn (0));
674 }
675 #undef FUNC_NAME
676
677 #ifdef HAVE_SETPGID
678 SCM_DEFINE (scm_setpgid, "setpgid", 2, 0, 0,
679 (SCM pid, SCM pgid),
680 "Move the process @var{pid} into the process group @var{pgid}. @var{pid} or\n"
681 "@var{pgid} must be integers: they can be zero to indicate the ID of the\n"
682 "current process.\n"
683 "Fails on systems that do not support job control.\n"
684 "The return value is unspecified.")
685 #define FUNC_NAME s_scm_setpgid
686 {
687 SCM_VALIDATE_INUM (1,pid);
688 SCM_VALIDATE_INUM (2,pgid);
689 /* FIXME(?): may be known as setpgrp. */
690 if (setpgid (SCM_INUM (pid), SCM_INUM (pgid)) != 0)
691 SCM_SYSERROR;
692 return SCM_UNSPECIFIED;
693 }
694 #undef FUNC_NAME
695 #endif /* HAVE_SETPGID */
696
697 #ifdef HAVE_SETSID
698 SCM_DEFINE (scm_setsid, "setsid", 0, 0, 0,
699 (),
700 "Creates a new session. The current process becomes the session leader\n"
701 "and is put in a new process group. The process will be detached\n"
702 "from its controlling terminal if it has one.\n"
703 "The return value is an integer representing the new process group ID.")
704 #define FUNC_NAME s_scm_setsid
705 {
706 pid_t sid = setsid ();
707 if (sid == -1)
708 SCM_SYSERROR;
709 return SCM_UNSPECIFIED;
710 }
711 #undef FUNC_NAME
712 #endif /* HAVE_SETSID */
713
714 SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
715 (SCM port),
716 "Returns a string with the name of the serial terminal device underlying\n"
717 "@var{port}.")
718 #define FUNC_NAME s_scm_ttyname
719 {
720 char *ans;
721 int fd;
722
723 port = SCM_COERCE_OUTPORT (port);
724 SCM_VALIDATE_OPPORT (1,port);
725 if (scm_tc16_fport != SCM_TYP16 (port))
726 return SCM_BOOL_F;
727 fd = SCM_FPORT_FDES (port);
728 SCM_SYSCALL (ans = ttyname (fd));
729 if (!ans)
730 SCM_SYSERROR;
731 /* ans could be overwritten by another call to ttyname */
732 return (scm_makfrom0str (ans));
733 }
734 #undef FUNC_NAME
735
736 #ifdef HAVE_CTERMID
737 SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
738 (),
739 "Returns a string containing the file name of the controlling terminal\n"
740 "for the current process.")
741 #define FUNC_NAME s_scm_ctermid
742 {
743 char *result = ctermid (NULL);
744 if (*result == '\0')
745 SCM_SYSERROR;
746 return scm_makfrom0str (result);
747 }
748 #undef FUNC_NAME
749 #endif /* HAVE_CTERMID */
750
751 #ifdef HAVE_TCGETPGRP
752 SCM_DEFINE (scm_tcgetpgrp, "tcgetpgrp", 1, 0, 0,
753 (SCM port),
754 "Returns the process group ID of the foreground\n"
755 "process group associated with the terminal open on the file descriptor\n"
756 "underlying @var{port}.\n\n"
757 "If there is no foreground process group, the return value is a\n"
758 "number greater than 1 that does not match the process group ID\n"
759 "of any existing process group. This can happen if all of the\n"
760 "processes in the job that was formerly the foreground job have\n"
761 "terminated, and no other job has yet been moved into the\n"
762 "foreground.")
763 #define FUNC_NAME s_scm_tcgetpgrp
764 {
765 int fd;
766 pid_t pgid;
767
768 port = SCM_COERCE_OUTPORT (port);
769
770 SCM_VALIDATE_OPFPORT (1,port);
771 fd = SCM_FPORT_FDES (port);
772 if ((pgid = tcgetpgrp (fd)) == -1)
773 SCM_SYSERROR;
774 return SCM_MAKINUM (pgid);
775 }
776 #undef FUNC_NAME
777 #endif /* HAVE_TCGETPGRP */
778
779 #ifdef HAVE_TCSETPGRP
780 SCM_DEFINE (scm_tcsetpgrp, "tcsetpgrp", 2, 0, 0,
781 (SCM port, SCM pgid),
782 "Set the foreground process group ID for the terminal used by the file\n"
783 "descriptor underlying @var{port} to the integer @var{pgid}.\n"
784 "The calling process\n"
785 "must be a member of the same session as @var{pgid} and must have the same\n"
786 "controlling terminal. The return value is unspecified.")
787 #define FUNC_NAME s_scm_tcsetpgrp
788 {
789 int fd;
790
791 port = SCM_COERCE_OUTPORT (port);
792
793 SCM_VALIDATE_OPFPORT (1,port);
794 SCM_VALIDATE_INUM (2,pgid);
795 fd = SCM_FPORT_FDES (port);
796 if (tcsetpgrp (fd, SCM_INUM (pgid)) == -1)
797 SCM_SYSERROR;
798 return SCM_UNSPECIFIED;
799 }
800 #undef FUNC_NAME
801 #endif /* HAVE_TCSETPGRP */
802
803 /* Copy exec args from an SCM vector into a new C array. */
804
805 static char **
806 scm_convert_exec_args (SCM args, int pos, const char *subr)
807 {
808 char **execargv;
809 int num_args;
810 int i;
811
812 SCM_ASSERT (SCM_NULLP (args)
813 || (SCM_CONSP (args)),
814 args, pos, subr);
815 num_args = scm_ilength (args);
816 execargv = (char **)
817 scm_must_malloc ((num_args + 1) * sizeof (char *), subr);
818 for (i = 0; SCM_NNULLP (args); args = SCM_CDR (args), ++i)
819 {
820 scm_sizet len;
821 char *dst;
822 char *src;
823 SCM_ASSERT (SCM_ROSTRINGP (SCM_CAR (args)),
824 SCM_CAR (args), SCM_ARGn, subr);
825 len = 1 + SCM_ROLENGTH (SCM_CAR (args));
826 dst = (char *) scm_must_malloc ((long) len, subr);
827 src = SCM_ROCHARS (SCM_CAR (args));
828 while (len--)
829 dst[len] = src[len];
830 execargv[i] = dst;
831 }
832 execargv[i] = 0;
833 return execargv;
834 }
835
836 SCM_DEFINE (scm_execl, "execl", 1, 0, 1,
837 (SCM filename, SCM args),
838 "Executes the file named by @var{path} as a new process image.\n"
839 "The remaining arguments are supplied to the process; from a C program\n"
840 "they are accessable as the @code{argv} argument to @code{main}.\n"
841 "Conventionally the first @var{arg} is the same as @var{path}.\n"
842 "All arguments must be strings. \n\n"
843 "If @var{arg} is missing, @var{path} is executed with a null\n"
844 "argument list, which may have system-dependent side-effects.\n\n"
845 "This procedure is currently implemented using the @code{execv} system\n"
846 "call, but we call it @code{execl} because of its Scheme calling interface.")
847 #define FUNC_NAME s_scm_execl
848 {
849 char **execargv;
850 SCM_VALIDATE_ROSTRING (1,filename);
851 SCM_COERCE_SUBSTR (filename);
852 execargv = scm_convert_exec_args (args, SCM_ARG2, FUNC_NAME);
853 execv (SCM_ROCHARS (filename), execargv);
854 SCM_SYSERROR;
855 /* not reached. */
856 return SCM_BOOL_F;
857 }
858 #undef FUNC_NAME
859
860 SCM_DEFINE (scm_execlp, "execlp", 1, 0, 1,
861 (SCM filename, SCM args),
862 "Similar to @code{execl}, however if\n"
863 "@var{filename} does not contain a slash\n"
864 "then the file to execute will be located by searching the\n"
865 "directories listed in the @code{PATH} environment variable.\n\n"
866 "This procedure is currently implemented using the @code{execlv} system\n"
867 "call, but we call it @code{execlp} because of its Scheme calling interface.")
868 #define FUNC_NAME s_scm_execlp
869 {
870 char **execargv;
871 SCM_VALIDATE_ROSTRING (1,filename);
872 SCM_COERCE_SUBSTR (filename);
873 execargv = scm_convert_exec_args (args, SCM_ARG2, FUNC_NAME);
874 execvp (SCM_ROCHARS (filename), execargv);
875 SCM_SYSERROR;
876 /* not reached. */
877 return SCM_BOOL_F;
878 }
879 #undef FUNC_NAME
880
881 static char **
882 environ_list_to_c (SCM envlist, int arg, const char *proc)
883 {
884 int num_strings;
885 char **result;
886 int i = 0;
887
888 SCM_ASSERT (SCM_NULLP (envlist) || SCM_CONSP (envlist),
889 envlist, arg, proc);
890 num_strings = scm_ilength (envlist);
891 result = (char **) malloc ((num_strings + 1) * sizeof (char *));
892 if (result == NULL)
893 scm_memory_error (proc);
894 while (SCM_NNULLP (envlist))
895 {
896 int len;
897 char *src;
898
899 SCM_ASSERT (SCM_ROSTRINGP (SCM_CAR (envlist)),
900 envlist, arg, proc);
901 len = 1 + SCM_ROLENGTH (SCM_CAR (envlist));
902 result[i] = malloc ((long) len);
903 if (result[i] == NULL)
904 scm_memory_error (proc);
905 src = SCM_ROCHARS (SCM_CAR (envlist));
906 while (len--)
907 result[i][len] = src[len];
908 envlist = SCM_CDR (envlist);
909 i++;
910 }
911 result[i] = 0;
912 return result;
913 }
914
915 SCM_DEFINE (scm_execle, "execle", 2, 0, 1,
916 (SCM filename, SCM env, SCM args),
917 "Similar to @code{execl}, but the environment of the new process is\n"
918 "specified by @var{env}, which must be a list of strings as returned by the\n"
919 "@code{environ} procedure.\n\n"
920 "This procedure is currently implemented using the @code{execve} system\n"
921 "call, but we call it @code{execle} because of its Scheme calling interface.")
922 #define FUNC_NAME s_scm_execle
923 {
924 char **execargv;
925 char **exec_env;
926
927 SCM_VALIDATE_ROSTRING (1,filename);
928 SCM_COERCE_SUBSTR (filename);
929
930 execargv = scm_convert_exec_args (args, SCM_ARG1, FUNC_NAME);
931 exec_env = environ_list_to_c (env, SCM_ARG2, FUNC_NAME);
932 execve (SCM_ROCHARS (filename), execargv, exec_env);
933 SCM_SYSERROR;
934 /* not reached. */
935 return SCM_BOOL_F;
936 }
937 #undef FUNC_NAME
938
939 SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
940 (),
941 "Creates a new \"child\" process by duplicating the current \"parent\" process.\n"
942 "In the child the return value is 0. In the parent the return value is\n"
943 "the integer process ID of the child.\n\n"
944 "This procedure has been renamed from @code{fork} to avoid a naming conflict\n"
945 "with the scsh fork.")
946 #define FUNC_NAME s_scm_fork
947 {
948 int pid;
949 pid = fork ();
950 if (pid == -1)
951 SCM_SYSERROR;
952 return SCM_MAKINUM (0L+pid);
953 }
954 #undef FUNC_NAME
955
956 #ifdef HAVE_UNAME
957 SCM_DEFINE (scm_uname, "uname", 0, 0, 0,
958 (),
959 "Returns an object with some information about the computer system the\n"
960 "program is running on.")
961 #define FUNC_NAME s_scm_uname
962 {
963 struct utsname buf;
964 SCM ans = scm_make_vector (SCM_MAKINUM(5), SCM_UNSPECIFIED);
965 SCM *ve = SCM_VELTS (ans);
966 if (uname (&buf) < 0)
967 SCM_SYSERROR;
968 ve[0] = scm_makfrom0str (buf.sysname);
969 ve[1] = scm_makfrom0str (buf.nodename);
970 ve[2] = scm_makfrom0str (buf.release);
971 ve[3] = scm_makfrom0str (buf.version);
972 ve[4] = scm_makfrom0str (buf.machine);
973 /*
974 a linux special?
975 ve[5] = scm_makfrom0str (buf.domainname);
976 */
977 return ans;
978 }
979 #undef FUNC_NAME
980 #endif /* HAVE_UNAME */
981
982 SCM_DEFINE (scm_environ, "environ", 0, 1, 0,
983 (SCM env),
984 "If @var{env} is omitted, returns the current environment as a list of strings.\n"
985 "Otherwise it sets the current environment, which is also the\n"
986 "default environment for child processes, to the supplied list of strings.\n"
987 "Each member of @var{env} should be of the form\n"
988 "@code{NAME=VALUE} and values of @code{NAME} should not be duplicated.\n"
989 "If @var{env} is supplied then the return value is unspecified.")
990 #define FUNC_NAME s_scm_environ
991 {
992 if (SCM_UNBNDP (env))
993 return scm_makfromstrs (-1, environ);
994 else
995 {
996 char **new_environ;
997
998 new_environ = environ_list_to_c (env, SCM_ARG1, FUNC_NAME);
999 /* Free the old environment, except when called for the first
1000 * time.
1001 */
1002 {
1003 char **ep;
1004 static int first = 1;
1005 if (!first)
1006 {
1007 for (ep = environ; *ep != NULL; ep++)
1008 free (*ep);
1009 free ((char *) environ);
1010 }
1011 first = 0;
1012 }
1013 environ = new_environ;
1014 return SCM_UNSPECIFIED;
1015 }
1016 }
1017 #undef FUNC_NAME
1018
1019 #ifdef L_tmpnam
1020
1021 SCM_DEFINE (scm_tmpnam, "tmpnam", 0, 0, 0,
1022 (),
1023 "Create a new file in the file system with a unique name. The return\n"
1024 "value is the name of the new file. This function is implemented with\n"
1025 "the @code{tmpnam} function in the system libraries.")
1026 #define FUNC_NAME s_scm_tmpnam
1027 {
1028 char name[L_tmpnam];
1029 SCM_SYSCALL (tmpnam (name););
1030 return scm_makfrom0str (name);
1031 }
1032 #undef FUNC_NAME
1033
1034 #endif
1035
1036 SCM_DEFINE (scm_utime, "utime", 1, 2, 0,
1037 (SCM pathname, SCM actime, SCM modtime),
1038 "@code{utime} sets the access and modification times for\n"
1039 "the file named by @var{path}. If @var{actime} or @var{modtime}\n"
1040 "is not supplied, then the current time is used.\n"
1041 "@var{actime} and @var{modtime}\n"
1042 "must be integer time values as returned by the @code{current-time}\n"
1043 "procedure.\n\n"
1044 "E.g.,\n\n"
1045 "@smalllisp\n"
1046 "(utime \"foo\" (- (current-time) 3600))\n"
1047 "@end smalllisp\n\n"
1048 "will set the access time to one hour in the past and the modification\n"
1049 "time to the current time.")
1050 #define FUNC_NAME s_scm_utime
1051 {
1052 int rv;
1053 struct utimbuf utm_tmp;
1054
1055 SCM_VALIDATE_ROSTRING (1,pathname);
1056 SCM_COERCE_SUBSTR (pathname);
1057 if (SCM_UNBNDP (actime))
1058 SCM_SYSCALL (time (&utm_tmp.actime));
1059 else
1060 utm_tmp.actime = SCM_NUM2ULONG (2,actime);
1061
1062 if (SCM_UNBNDP (modtime))
1063 SCM_SYSCALL (time (&utm_tmp.modtime));
1064 else
1065 utm_tmp.modtime = SCM_NUM2ULONG (3,modtime);
1066
1067 SCM_SYSCALL (rv = utime (SCM_ROCHARS (pathname), &utm_tmp));
1068 if (rv != 0)
1069 SCM_SYSERROR;
1070 return SCM_UNSPECIFIED;
1071 }
1072 #undef FUNC_NAME
1073
1074 SCM_DEFINE (scm_access, "access?", 2, 0, 0,
1075 (SCM path, SCM how),
1076 "Returns @code{#t} if @var{path} corresponds to an existing\n"
1077 "file and the current process\n"
1078 "has the type of access specified by @var{how}, otherwise \n"
1079 "@code{#f}.\n"
1080 "@var{how} should be specified\n"
1081 "using the values of the variables listed below. Multiple values can\n"
1082 "be combined using a bitwise or, in which case @code{#t} will only\n"
1083 "be returned if all accesses are granted.\n\n"
1084 "Permissions are checked using the real id of the current process,\n"
1085 "not the effective id, although it's the effective id which determines\n"
1086 "whether the access would actually be granted.\n\n"
1087 "@defvar R_OK\n"
1088 "test for read permission.\n"
1089 "@end defvar\n"
1090 "@defvar W_OK\n"
1091 "test for write permission.\n"
1092 "@end defvar\n"
1093 "@defvar X_OK\n"
1094 "test for execute permission.\n"
1095 "@end defvar\n"
1096 "@defvar F_OK\n"
1097 "test for existence of the file.\n"
1098 "@end defvar")
1099 #define FUNC_NAME s_scm_access
1100 {
1101 int rv;
1102
1103 SCM_VALIDATE_ROSTRING (1,path);
1104 if (SCM_SUBSTRP (path))
1105 path = scm_makfromstr (SCM_ROCHARS (path), SCM_ROLENGTH (path), 0);
1106 SCM_VALIDATE_INUM (2,how);
1107 rv = access (SCM_ROCHARS (path), SCM_INUM (how));
1108 return SCM_NEGATE_BOOL(rv);
1109 }
1110 #undef FUNC_NAME
1111
1112 SCM_DEFINE (scm_getpid, "getpid", 0, 0, 0,
1113 (),
1114 "Returns an integer representing the current process ID.")
1115 #define FUNC_NAME s_scm_getpid
1116 {
1117 return SCM_MAKINUM ((unsigned long) getpid ());
1118 }
1119 #undef FUNC_NAME
1120
1121 SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
1122 (SCM str),
1123 "Modifies the environment of the current process, which is\n"
1124 "also the default environment inherited by child processes.\n\n"
1125 "If @var{string} is of the form @code{NAME=VALUE} then it will be written\n"
1126 "directly into the environment, replacing any existing environment string\n"
1127 "with\n"
1128 "name matching @code{NAME}. If @var{string} does not contain an equal\n"
1129 "sign, then any existing string with name matching @var{string} will\n"
1130 "be removed.\n\n"
1131 "The return value is unspecified.")
1132 #define FUNC_NAME s_scm_putenv
1133 {
1134 int rv;
1135 char *ptr;
1136
1137 SCM_VALIDATE_ROSTRING (1,str);
1138 /* must make a new copy to be left in the environment, safe from gc. */
1139 ptr = malloc (SCM_LENGTH (str) + 1);
1140 if (ptr == NULL)
1141 SCM_MEMORY_ERROR;
1142 strncpy (ptr, SCM_ROCHARS (str), SCM_LENGTH (str));
1143 ptr[SCM_LENGTH(str)] = 0;
1144 rv = putenv (ptr);
1145 if (rv < 0)
1146 SCM_SYSERROR;
1147 return SCM_UNSPECIFIED;
1148 }
1149 #undef FUNC_NAME
1150
1151 #ifdef HAVE_SETLOCALE
1152 SCM_DEFINE (scm_setlocale, "setlocale", 1, 1, 0,
1153 (SCM category, SCM locale),
1154 "If @var{locale} is omitted, returns the current value of the specified\n"
1155 "locale category \n"
1156 "as a system-dependent string.\n"
1157 "@var{category} should be specified using the values @code{LC_COLLATE},\n"
1158 "@code{LC_ALL} etc.\n\n"
1159 "Otherwise the specified locale category is set to\n"
1160 "the string @var{locale}\n"
1161 "and the new value is returned as a system-dependent string. If @var{locale}\n"
1162 "is an empty string, the locale will be set using envirionment variables.")
1163 #define FUNC_NAME s_scm_setlocale
1164 {
1165 char *clocale;
1166 char *rv;
1167
1168 SCM_VALIDATE_INUM (1,category);
1169 if (SCM_UNBNDP (locale))
1170 {
1171 clocale = NULL;
1172 }
1173 else
1174 {
1175 SCM_VALIDATE_ROSTRING (2,locale);
1176 SCM_COERCE_SUBSTR (locale);
1177 clocale = SCM_ROCHARS (locale);
1178 }
1179
1180 rv = setlocale (SCM_INUM (category), clocale);
1181 if (rv == NULL)
1182 SCM_SYSERROR;
1183 return scm_makfrom0str (rv);
1184 }
1185 #undef FUNC_NAME
1186 #endif /* HAVE_SETLOCALE */
1187
1188 #ifdef HAVE_MKNOD
1189 SCM_DEFINE (scm_mknod, "mknod", 4, 0, 0,
1190 (SCM path, SCM type, SCM perms, SCM dev),
1191 "Creates a new special file, such as a file corresponding to a device.\n"
1192 "@var{path} specifies the name of the file. @var{type} should\n"
1193 "be one of the following symbols:\n"
1194 "regular, directory, symlink, block-special, char-special,\n"
1195 "fifo, or socket. @var{perms} (an integer) specifies the file permissions.\n"
1196 "@var{dev} (an integer) specifies which device the special file refers\n"
1197 "to. Its exact interpretation depends on the kind of special file\n"
1198 "being created.\n\n"
1199 "E.g.,\n"
1200 "@example\n"
1201 "(mknod \"/dev/fd0\" 'block-special #o660 (+ (* 2 256) 2))"
1202 "@end example\n"
1203 "The return value is unspecified.")
1204 #define FUNC_NAME s_scm_mknod
1205 {
1206 int val;
1207 char *p;
1208 int ctype = 0;
1209
1210 SCM_VALIDATE_ROSTRING (1,path);
1211 SCM_VALIDATE_SYMBOL (2,type);
1212 SCM_VALIDATE_INUM (3,perms);
1213 SCM_VALIDATE_INUM (4,dev);
1214 SCM_COERCE_SUBSTR (path);
1215
1216 p = SCM_CHARS (type);
1217 if (strcmp (p, "regular") == 0)
1218 ctype = S_IFREG;
1219 else if (strcmp (p, "directory") == 0)
1220 ctype = S_IFDIR;
1221 else if (strcmp (p, "symlink") == 0)
1222 ctype = S_IFLNK;
1223 else if (strcmp (p, "block-special") == 0)
1224 ctype = S_IFBLK;
1225 else if (strcmp (p, "char-special") == 0)
1226 ctype = S_IFCHR;
1227 else if (strcmp (p, "fifo") == 0)
1228 ctype = S_IFIFO;
1229 else if (strcmp (p, "socket") == 0)
1230 ctype = S_IFSOCK;
1231 else
1232 SCM_OUT_OF_RANGE (2,type);
1233
1234 SCM_SYSCALL (val = mknod(SCM_ROCHARS(path), ctype | SCM_INUM (perms),
1235 SCM_INUM (dev)));
1236 if (val != 0)
1237 SCM_SYSERROR;
1238 return SCM_UNSPECIFIED;
1239 }
1240 #undef FUNC_NAME
1241 #endif /* HAVE_MKNOD */
1242
1243 #ifdef HAVE_NICE
1244 SCM_DEFINE (scm_nice, "nice", 1, 0, 0,
1245 (SCM incr),
1246 "Increment the priority of the current process by @var{incr}. A higher\n"
1247 "priority value means that the process runs less often.\n"
1248 "The return value is unspecified.")
1249 #define FUNC_NAME s_scm_nice
1250 {
1251 SCM_VALIDATE_INUM (1,incr);
1252 if (nice(SCM_INUM(incr)) != 0)
1253 SCM_SYSERROR;
1254 return SCM_UNSPECIFIED;
1255 }
1256 #undef FUNC_NAME
1257 #endif /* HAVE_NICE */
1258
1259 #ifdef HAVE_SYNC
1260 SCM_DEFINE (scm_sync, "sync", 0, 0, 0,
1261 (),
1262 "Flush the operating system disk buffers.\n"
1263 "The return value is unspecified.")
1264 #define FUNC_NAME s_scm_sync
1265 {
1266 sync();
1267 return SCM_UNSPECIFIED;
1268 }
1269 #undef FUNC_NAME
1270 #endif /* HAVE_SYNC */
1271
1272 void
1273 scm_init_posix ()
1274 {
1275 scm_add_feature ("posix");
1276 #ifdef HAVE_GETEUID
1277 scm_add_feature ("EIDs");
1278 #endif
1279 #ifdef WAIT_ANY
1280 scm_sysintern ("WAIT_ANY", SCM_MAKINUM (WAIT_ANY));
1281 #endif
1282 #ifdef WAIT_MYPGRP
1283 scm_sysintern ("WAIT_MYPGRP", SCM_MAKINUM (WAIT_MYPGRP));
1284 #endif
1285 #ifdef WNOHANG
1286 scm_sysintern ("WNOHANG", SCM_MAKINUM (WNOHANG));
1287 #endif
1288 #ifdef WUNTRACED
1289 scm_sysintern ("WUNTRACED", SCM_MAKINUM (WUNTRACED));
1290 #endif
1291
1292 /* access() symbols. */
1293 scm_sysintern ("R_OK", SCM_MAKINUM (R_OK));
1294 scm_sysintern ("W_OK", SCM_MAKINUM (W_OK));
1295 scm_sysintern ("X_OK", SCM_MAKINUM (X_OK));
1296 scm_sysintern ("F_OK", SCM_MAKINUM (F_OK));
1297
1298 #ifdef LC_COLLATE
1299 scm_sysintern ("LC_COLLATE", SCM_MAKINUM (LC_COLLATE));
1300 #endif
1301 #ifdef LC_CTYPE
1302 scm_sysintern ("LC_CTYPE", SCM_MAKINUM (LC_CTYPE));
1303 #endif
1304 #ifdef LC_MONETARY
1305 scm_sysintern ("LC_MONETARY", SCM_MAKINUM (LC_MONETARY));
1306 #endif
1307 #ifdef LC_NUMERIC
1308 scm_sysintern ("LC_NUMERIC", SCM_MAKINUM (LC_NUMERIC));
1309 #endif
1310 #ifdef LC_TIME
1311 scm_sysintern ("LC_TIME", SCM_MAKINUM (LC_TIME));
1312 #endif
1313 #ifdef LC_MESSAGES
1314 scm_sysintern ("LC_MESSAGES", SCM_MAKINUM (LC_MESSAGES));
1315 #endif
1316 #ifdef LC_ALL
1317 scm_sysintern ("LC_ALL", SCM_MAKINUM (LC_ALL));
1318 #endif
1319 #ifdef PIPE_BUF
1320 scm_sysintern ("PIPE_BUF", scm_long2num (PIPE_BUF));
1321 #endif
1322
1323 #include "cpp_sig_symbols.c"
1324 #include "posix.x"
1325 }