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