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