* alist.c, arbiters.c, continuations.c, debug.c, debug.h, eval.c,
[bpt/guile.git] / libguile / posix.c
1 /* Copyright (C) 1995, 1996 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, 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
19 *
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
25 *
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
28 *
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
36 *
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
40 */
41 \f
42
43 #include <stdio.h>
44 #include "_scm.h"
45 #include "fports.h"
46 #include "genio.h"
47 #include "scmsigs.h"
48 #include "read.h"
49 #include "unif.h"
50 #include "feature.h"
51 #include "sequences.h"
52
53 #include "posix.h"
54 \f
55
56 #ifdef HAVE_STRING_H
57 #include <string.h>
58 #endif
59 #ifdef TIME_WITH_SYS_TIME
60 # include <sys/time.h>
61 # include <time.h>
62 #else
63 # if HAVE_SYS_TIME_H
64 # include <sys/time.h>
65 # else
66 # include <time.h>
67 # endif
68 #endif
69
70 #ifdef HAVE_UNISTD_H
71 #include <unistd.h>
72 #else
73 #ifndef ttyname
74 extern char *ttyname();
75 #endif
76 #endif
77
78 #ifdef HAVE_LIBC_H
79 #include <libc.h>
80 #endif
81
82 #ifdef HAVE_SYS_SELECT_H
83 #include <sys/select.h>
84 #endif
85
86 #include <sys/types.h>
87 #include <sys/stat.h>
88 #include <fcntl.h>
89
90 #include <pwd.h>
91
92 #if HAVE_SYS_WAIT_H
93 # include <sys/wait.h>
94 #endif
95 #ifndef WEXITSTATUS
96 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
97 #endif
98 #ifndef WIFEXITED
99 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
100 #endif
101
102 #include <signal.h>
103
104 #ifdef FD_SET
105
106 #define SELECT_TYPE fd_set
107 #define SELECT_SET_SIZE FD_SETSIZE
108
109 #else /* no FD_SET */
110
111 /* Define the macros to access a single-int bitmap of descriptors. */
112 #define SELECT_SET_SIZE 32
113 #define SELECT_TYPE int
114 #define FD_SET(n, p) (*(p) |= (1 << (n)))
115 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
116 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
117 #define FD_ZERO(p) (*(p) = 0)
118
119 #endif /* no FD_SET */
120
121 extern FILE *popen ();
122 extern char ** environ;
123
124 #include <grp.h>
125 #include <sys/utsname.h>
126
127 #if HAVE_DIRENT_H
128 # include <dirent.h>
129 # define NAMLEN(dirent) strlen((dirent)->d_name)
130 #else
131 # define dirent direct
132 # define NAMLEN(dirent) (dirent)->d_namlen
133 # if HAVE_SYS_NDIR_H
134 # include <sys/ndir.h>
135 # endif
136 # if HAVE_SYS_DIR_H
137 # include <sys/dir.h>
138 # endif
139 # if HAVE_NDIR_H
140 # include <ndir.h>
141 # endif
142 #endif
143
144 char *strptime ();
145
146 #ifdef HAVE_SETLOCALE
147 #include <locale.h>
148 #endif
149
150 /* Some Unix systems don't define these. CPP hair is dangerous, but
151 this seems safe enough... */
152 #ifndef R_OK
153 #define R_OK 4
154 #endif
155
156 #ifndef W_OK
157 #define W_OK 2
158 #endif
159
160 #ifndef X_OK
161 #define X_OK 1
162 #endif
163
164 #ifndef F_OK
165 #define F_OK 0
166 #endif
167
168 /* On NextStep, <utime.h> doesn't define struct utime, unless we
169 #define _POSIX_SOURCE before #including it. I think this is less
170 of a kludge than defining struct utimbuf ourselves. */
171 #ifdef UTIMBUF_NEEDS_POSIX
172 #define _POSIX_SOURCE
173 #endif
174
175 #ifdef HAVE_SYS_UTIME_H
176 #include <sys/utime.h>
177 #endif
178
179 #ifdef HAVE_UTIME_H
180 #include <utime.h>
181 #endif
182
183 /* Please don't add any more #includes or #defines here. The hack
184 above means that _POSIX_SOURCE may be #defined, which will
185 encourage header files to do strange things. */
186
187 \f
188
189
190 SCM_PROC (s_sys_pipe, "pipe", 0, 0, 0, scm_sys_pipe);
191
192 SCM
193 scm_sys_pipe ()
194 {
195 int fd[2], rv;
196 FILE *f_rd, *f_wt;
197 SCM p_rd, p_wt;
198 struct scm_port_table * ptr;
199 struct scm_port_table * ptw;
200
201 SCM_NEWCELL (p_rd);
202 SCM_NEWCELL (p_wt);
203 rv = pipe (fd);
204 if (rv)
205 scm_syserror (s_sys_pipe);
206 f_rd = fdopen (fd[0], "r");
207 if (!f_rd)
208 {
209 SCM_SYSCALL (close (fd[0]));
210 SCM_SYSCALL (close (fd[1]));
211 scm_syserror (s_sys_pipe);
212 }
213 f_wt = fdopen (fd[1], "w");
214 if (!f_wt)
215 {
216 int en;
217 en = errno;
218 fclose (f_rd);
219 SCM_SYSCALL (close (fd[1]));
220 errno = en;
221 scm_syserror (s_sys_pipe);
222 }
223 ptr = scm_add_to_port_table (p_rd);
224 ptw = scm_add_to_port_table (p_wt);
225 SCM_SETPTAB_ENTRY (p_rd, ptr);
226 SCM_SETPTAB_ENTRY (p_wt, ptw);
227 SCM_SETCAR (p_rd, scm_tc16_fport | scm_mode_bits ("r"));
228 SCM_SETCAR (p_wt, scm_tc16_fport | scm_mode_bits ("w"));
229 SCM_SETSTREAM (p_rd, (SCM)f_rd);
230 SCM_SETSTREAM (p_wt, (SCM)f_wt);
231
232 SCM_ALLOW_INTS;
233 return scm_cons (p_rd, p_wt);
234 }
235
236
237
238 SCM_PROC (s_sys_getgroups, "getgroups", 0, 0, 0, scm_sys_getgroups);
239
240 SCM
241 scm_sys_getgroups()
242 {
243 SCM grps, ans;
244 int ngroups = getgroups (0, NULL);
245 if (!ngroups)
246 scm_syserror (s_sys_getgroups);
247 SCM_NEWCELL(grps);
248 SCM_DEFER_INTS;
249 {
250 GETGROUPS_T *groups;
251 int val;
252
253 groups = (GETGROUPS_T *) scm_must_malloc(ngroups * sizeof(GETGROUPS_T),
254 s_sys_getgroups);
255 val = getgroups(ngroups, groups);
256 if (val < 0)
257 {
258 scm_must_free((char *)groups);
259 scm_syserror (s_sys_getgroups);
260 }
261 SCM_SETCHARS(grps, groups); /* set up grps as a GC protect */
262 SCM_SETLENGTH(grps, 0L + ngroups * sizeof(GETGROUPS_T), scm_tc7_string);
263 SCM_ALLOW_INTS;
264 ans = scm_make_vector(SCM_MAKINUM(ngroups), SCM_UNDEFINED, SCM_BOOL_F);
265 while (--ngroups >= 0) SCM_VELTS(ans)[ngroups] = SCM_MAKINUM(groups[ngroups]);
266 SCM_SETCHARS(grps, groups); /* to make sure grps stays around. */
267 return ans;
268 }
269 }
270
271
272
273 SCM_PROC (s_sys_getpwuid, "getpw", 0, 1, 0, scm_sys_getpwuid);
274
275 SCM
276 scm_sys_getpwuid (user)
277 SCM user;
278 {
279 SCM result;
280 struct passwd *entry;
281 SCM *ve;
282
283 result = scm_make_vector (SCM_MAKINUM (7), SCM_UNSPECIFIED, SCM_BOOL_F);
284 ve = SCM_VELTS (result);
285 if (SCM_UNBNDP (user) || SCM_FALSEP (user))
286 {
287 SCM_DEFER_INTS;
288 SCM_SYSCALL (entry = getpwent ());
289 }
290 else if (SCM_INUMP (user))
291 {
292 SCM_DEFER_INTS;
293 entry = getpwuid (SCM_INUM (user));
294 }
295 else
296 {
297 SCM_ASSERT (SCM_NIMP (user) && SCM_ROSTRINGP (user), user, SCM_ARG1, s_sys_getpwuid);
298 if (SCM_SUBSTRP (user))
299 user = scm_makfromstr (SCM_ROCHARS (user), SCM_ROLENGTH (user), 0);
300 SCM_DEFER_INTS;
301 entry = getpwnam (SCM_ROCHARS (user));
302 }
303 if (!entry)
304 scm_syserror (s_sys_getpwuid);
305
306 ve[0] = scm_makfrom0str (entry->pw_name);
307 ve[1] = scm_makfrom0str (entry->pw_passwd);
308 ve[2] = scm_ulong2num ((unsigned long) entry->pw_uid);
309 ve[3] = scm_ulong2num ((unsigned long) entry->pw_gid);
310 ve[4] = scm_makfrom0str (entry->pw_gecos);
311 if (!entry->pw_dir)
312 ve[5] = scm_makfrom0str ("");
313 else
314 ve[5] = scm_makfrom0str (entry->pw_dir);
315 if (!entry->pw_shell)
316 ve[6] = scm_makfrom0str ("");
317 else
318 ve[6] = scm_makfrom0str (entry->pw_shell);
319 SCM_ALLOW_INTS;
320 return result;
321 }
322
323
324
325 SCM_PROC (s_setpwent, "setpw", 0, 1, 0, scm_setpwent);
326
327 SCM
328 scm_setpwent (arg)
329 SCM arg;
330 {
331 if (SCM_UNBNDP (arg) || SCM_FALSEP (arg))
332 endpwent ();
333 else
334 setpwent ();
335 return SCM_UNSPECIFIED;
336 }
337
338
339
340 /* Combines getgrgid and getgrnam. */
341 SCM_PROC (s_sys_getgrgid, "getgr", 0, 1, 0, scm_sys_getgrgid);
342
343 SCM
344 scm_sys_getgrgid (name)
345 SCM name;
346 {
347 SCM result;
348 struct group *entry;
349 SCM *ve;
350 result = scm_make_vector (SCM_MAKINUM (4), SCM_UNSPECIFIED, SCM_BOOL_F);
351 ve = SCM_VELTS (result);
352 SCM_DEFER_INTS;
353 if (SCM_UNBNDP (name) || (name == SCM_BOOL_F))
354 SCM_SYSCALL (entry = getgrent ());
355 else if (SCM_INUMP (name))
356 SCM_SYSCALL (entry = getgrgid (SCM_INUM (name)));
357 else
358 {
359 SCM_ASSERT (SCM_NIMP (name) && SCM_STRINGP (name), name, SCM_ARG1, s_sys_getgrgid);
360 if (SCM_SUBSTRP (name))
361 name = scm_makfromstr (SCM_ROCHARS (name), SCM_ROLENGTH (name), 0);
362 SCM_SYSCALL (entry = getgrnam (SCM_CHARS (name)));
363 }
364 if (!entry)
365 scm_syserror (s_sys_getgrgid);
366
367 ve[0] = scm_makfrom0str (entry->gr_name);
368 ve[1] = scm_makfrom0str (entry->gr_passwd);
369 ve[2] = scm_ulong2num ((unsigned long) entry->gr_gid);
370 ve[3] = scm_makfromstrs (-1, entry->gr_mem);
371 SCM_ALLOW_INTS;
372 return result;
373 }
374
375
376
377 SCM_PROC (s_setgrent, "setgr", 0, 1, 0, scm_setgrent);
378
379 SCM
380 scm_setgrent (arg)
381 SCM arg;
382 {
383 if (SCM_UNBNDP (arg) || SCM_FALSEP (arg))
384 endgrent ();
385 else
386 setgrent ();
387 return SCM_UNSPECIFIED;
388 }
389
390
391
392 SCM_PROC (s_sys_kill, "kill", 2, 0, 0, scm_sys_kill);
393
394 SCM
395 scm_sys_kill (pid, sig)
396 SCM pid;
397 SCM sig;
398 {
399 SCM_ASSERT (SCM_INUMP (pid), pid, SCM_ARG1, s_sys_kill);
400 SCM_ASSERT (SCM_INUMP (sig), sig, SCM_ARG2, s_sys_kill);
401 /* Signal values are interned in scm_init_posix(). */
402 if (kill ((int) SCM_INUM (pid), (int) SCM_INUM (sig)) != 0)
403 scm_syserror (s_sys_kill);
404 return SCM_UNSPECIFIED;
405 }
406
407
408
409 SCM_PROC (s_sys_waitpid, "waitpid", 1, 1, 0, scm_sys_waitpid);
410
411 SCM
412 scm_sys_waitpid (pid, options)
413 SCM pid;
414 SCM options;
415 {
416 #ifdef HAVE_WAITPID
417 int i;
418 int status;
419 int ioptions;
420 SCM_ASSERT (SCM_INUMP (pid), pid, SCM_ARG1, s_sys_waitpid);
421 if (SCM_UNBNDP (options))
422 ioptions = 0;
423 else
424 {
425 SCM_ASSERT (SCM_INUMP (options), options, SCM_ARG2, s_sys_waitpid);
426 /* Flags are interned in scm_init_posix. */
427 ioptions = SCM_INUM (options);
428 }
429 SCM_SYSCALL (i = waitpid (SCM_INUM (pid), &status, ioptions));
430 if (i == -1)
431 scm_syserror (s_sys_waitpid);
432 return scm_cons (SCM_MAKINUM (0L + i), SCM_MAKINUM (0L + status));
433 #else
434 scm_sysmissing (s_sys_waitpid);
435 /* not reached. */
436 return SCM_BOOL_F;
437 #endif
438 }
439
440
441
442 SCM_PROC (s_getppid, "getppid", 0, 0, 0, scm_getppid);
443
444 SCM
445 scm_getppid ()
446 {
447 return SCM_MAKINUM (0L + getppid ());
448 }
449
450
451
452 SCM_PROC (s_getuid, "getuid", 0, 0, 0, scm_getuid);
453
454 SCM
455 scm_getuid ()
456 {
457 return SCM_MAKINUM (0L + getuid ());
458 }
459
460
461
462 SCM_PROC (s_getgid, "getgid", 0, 0, 0, scm_getgid);
463
464 SCM
465 scm_getgid ()
466 {
467 return SCM_MAKINUM (0L + getgid ());
468 }
469
470
471
472 SCM_PROC (s_geteuid, "geteuid", 0, 0, 0, scm_geteuid);
473
474 SCM
475 scm_geteuid ()
476 {
477 #ifdef HAVE_GETEUID
478 return SCM_MAKINUM (0L + geteuid ());
479 #else
480 return SCM_MAKINUM (0L + getuid ());
481 #endif
482 }
483
484
485
486 SCM_PROC (s_getegid, "getegid", 0, 0, 0, scm_getegid);
487
488 SCM
489 scm_getegid ()
490 {
491 #ifdef HAVE_GETEUID
492 return SCM_MAKINUM (0L + getegid ());
493 #else
494 return SCM_MAKINUM (0L + getgid ());
495 #endif
496 }
497
498
499 SCM_PROC (s_sys_setuid, "setuid", 1, 0, 0, scm_sys_setuid);
500
501 SCM
502 scm_sys_setuid (id)
503 SCM id;
504 {
505 SCM_ASSERT (SCM_INUMP (id), id, SCM_ARG1, s_sys_setuid);
506 if (setuid (SCM_INUM (id)) != 0)
507 scm_syserror (s_sys_setuid);
508 return SCM_UNSPECIFIED;
509 }
510
511 SCM_PROC (s_sys_setgid, "setgid", 1, 0, 0, scm_sys_setgid);
512
513 SCM
514 scm_sys_setgid (id)
515 SCM id;
516 {
517 SCM_ASSERT (SCM_INUMP (id), id, SCM_ARG1, s_sys_setgid);
518 if (setgid (SCM_INUM (id)) != 0)
519 scm_syserror (s_sys_setgid);
520 return SCM_UNSPECIFIED;
521 }
522
523 SCM_PROC (s_sys_seteuid, "seteuid", 1, 0, 0, scm_sys_seteuid);
524
525 SCM
526 scm_sys_seteuid (id)
527 SCM id;
528 {
529 int rv;
530
531 SCM_ASSERT (SCM_INUMP (id), id, SCM_ARG1, s_sys_seteuid);
532 #ifdef HAVE_SETEUID
533 rv = seteuid (SCM_INUM (id));
534 #else
535 rv = setuid (SCM_INUM (id));
536 #endif
537 if (rv != 0)
538 scm_syserror (s_sys_seteuid);
539 return SCM_UNSPECIFIED;
540 }
541
542 SCM_PROC (s_sys_setegid, "setegid", 1, 0, 0, scm_sys_setegid);
543
544 SCM
545 scm_sys_setegid (id)
546 SCM id;
547 {
548 int rv;
549
550 SCM_ASSERT (SCM_INUMP (id), id, SCM_ARG1, s_sys_setegid);
551 #ifdef HAVE_SETEUID
552 rv = setegid (SCM_INUM (id));
553 #else
554 rv = setgid (SCM_INUM (id));
555 #endif
556 if (rv != 0)
557 scm_syserror (s_sys_setegid);
558 return SCM_UNSPECIFIED;
559
560 }
561
562 SCM_PROC (s_getpgrp, "getpgrp", 0, 0, 0, scm_getpgrp);
563 SCM
564 scm_getpgrp ()
565 {
566 int (*fn)();
567 fn = (int (*) ()) getpgrp;
568 return SCM_MAKINUM (fn (0));
569 }
570
571 SCM_PROC (s_sys_setpgid, "setpgid", 2, 0, 0, scm_setpgid);
572 SCM
573 scm_setpgid (pid, pgid)
574 SCM pid, pgid;
575 {
576 #ifdef HAVE_SETPGID
577 SCM_ASSERT (SCM_INUMP (pid), pid, SCM_ARG1, s_sys_setpgid);
578 SCM_ASSERT (SCM_INUMP (pgid), pgid, SCM_ARG2, s_sys_setpgid);
579 /* FIXME(?): may be known as setpgrp. */
580 if (setpgid (SCM_INUM (pid), SCM_INUM (pgid)) != 0)
581 scm_syserror (s_sys_setpgid);
582 return SCM_UNSPECIFIED;
583 #else
584 scm_sysmissing (s_sys_setpgid);
585 /* not reached. */
586 return SCM_BOOL_F;
587 #endif
588 }
589
590 SCM_PROC (s_sys_setsid, "setsid", 0, 0, 0, scm_setsid);
591 SCM
592 scm_setsid ()
593 {
594 #ifdef HAVE_SETSID
595 pid_t sid = setsid ();
596 if (sid == -1)
597 scm_syserror (s_sys_setsid);
598 return SCM_UNSPECIFIED;
599 #else
600 scm_sysmissing (s_sys_setsid);
601 /* not reached. */
602 return SCM_BOOL_F;
603 #endif
604 }
605
606 SCM_PROC (s_ttyname, "ttyname", 1, 0, 0, scm_ttyname);
607
608 SCM
609 scm_ttyname (port)
610 SCM port;
611 {
612 char *ans;
613 int fd;
614 SCM_ASSERT (SCM_NIMP (port) && SCM_OPPORTP (port), port, SCM_ARG1, s_ttyname);
615 if (scm_tc16_fport != SCM_TYP16 (port))
616 return SCM_BOOL_F;
617 fd = fileno ((FILE *)SCM_STREAM (port));
618 if (fd == -1)
619 scm_syserror (s_ttyname);
620 SCM_SYSCALL (ans = ttyname (fd));
621 if (!ans)
622 scm_syserror (s_ttyname);
623 /* ans could be overwritten by another call to ttyname */
624 return (scm_makfrom0str (ans));
625 }
626
627
628 SCM_PROC (s_sys_ctermid, "ctermid", 0, 0, 0, scm_ctermid);
629 SCM
630 scm_ctermid ()
631 {
632 #ifdef HAVE_CTERMID
633 char *result = ctermid (NULL);
634 if (*result == '\0')
635 scm_syserror (s_sys_ctermid);
636 return scm_makfrom0str (result);
637 #else
638 scm_sysmissing (s_sys_ctermid);
639 /* not reached. */
640 return SCM_BOOL_F;
641 #endif
642 }
643
644 SCM_PROC (s_sys_tcgetpgrp, "tcgetpgrp", 1, 0, 0, scm_tcgetpgrp);
645 SCM
646 scm_tcgetpgrp (port)
647 SCM port;
648 {
649 #ifdef HAVE_TCGETPGRP
650 int fd;
651 pid_t pgid;
652 SCM_ASSERT (SCM_NIMP (port) && SCM_OPFPORTP (port), port, SCM_ARG1, s_sys_tcgetpgrp);
653 fd = fileno ((FILE *)SCM_STREAM (port));
654 if (fd == -1 || (pgid = tcgetpgrp (fd)) == -1)
655 scm_syserror (s_sys_tcgetpgrp);
656 return SCM_MAKINUM (pgid);
657 #else
658 scm_sysmissing (s_sys_tcgetpgrp);
659 /* not reached. */
660 return SCM_BOOL_F;
661 #endif
662 }
663
664 SCM_PROC (s_sys_tcsetpgrp, "tcsetpgrp", 2, 0, 0, scm_tcsetpgrp);
665 SCM
666 scm_tcsetpgrp (port, pgid)
667 SCM port, pgid;
668 {
669 #ifdef HAVE_TCSETPGRP
670 int fd;
671 SCM_ASSERT (SCM_NIMP (port) && SCM_OPFPORTP (port), port, SCM_ARG1, s_sys_tcsetpgrp);
672 SCM_ASSERT (SCM_INUMP (pgid), pgid, SCM_ARG2, s_sys_tcsetpgrp);
673 fd = fileno ((FILE *)SCM_STREAM (port));
674 if (fd == -1 || tcsetpgrp (fd, SCM_INUM (pgid)) == -1)
675 scm_syserror (s_sys_tcsetpgrp);
676 return SCM_UNSPECIFIED;
677 #else
678 scm_sysmissing (s_sys_tcsetpgrp);
679 /* not reached. */
680 return SCM_BOOL_F;
681 #endif
682 }
683
684 /* Copy exec args from an SCM vector into a new C array. */
685
686 static char ** scm_convert_exec_args SCM_P ((SCM args));
687
688 static char **
689 scm_convert_exec_args (args)
690 SCM args;
691 {
692 char **execargv;
693 int num_args;
694 int i;
695 SCM_DEFER_INTS;
696 num_args = scm_ilength (args);
697 execargv = (char **)
698 scm_must_malloc ((num_args + 1) * sizeof (char *), s_ttyname);
699 for (i = 0; SCM_NNULLP (args); args = SCM_CDR (args), ++i)
700 {
701 scm_sizet len;
702 char *dst;
703 char *src;
704 SCM_ASSERT (SCM_NIMP (SCM_CAR (args)) && SCM_ROSTRINGP (SCM_CAR (args)), SCM_CAR (args),
705 "wrong type in SCM_ARG", "exec arg");
706 len = 1 + SCM_ROLENGTH (SCM_CAR (args));
707 dst = (char *) scm_must_malloc ((long) len, s_ttyname);
708 src = SCM_ROCHARS (SCM_CAR (args));
709 while (len--)
710 dst[len] = src[len];
711 execargv[i] = dst;
712 }
713 execargv[i] = 0;
714 SCM_ALLOW_INTS;
715 return execargv;
716 }
717
718 SCM_PROC (s_sys_execl, "execl", 0, 0, 1, scm_sys_execl);
719
720 SCM
721 scm_sys_execl (args)
722 SCM args;
723 {
724 char **execargv;
725 SCM filename = SCM_CAR (args);
726 SCM_ASSERT (SCM_NIMP (filename) && SCM_ROSTRINGP (filename), filename, SCM_ARG1, s_sys_execl);
727 if (SCM_SUBSTRP (filename))
728 filename = scm_makfromstr (SCM_ROCHARS (filename), SCM_ROLENGTH (filename), 0);
729 args = SCM_CDR (args);
730 execargv = scm_convert_exec_args (args);
731 execv (SCM_ROCHARS (filename), execargv);
732 scm_syserror (s_sys_execl);
733 /* not reached. */
734 return SCM_BOOL_F;
735 }
736
737 SCM_PROC (s_sys_execlp, "execlp", 0, 0, 1, scm_sys_execlp);
738
739 SCM
740 scm_sys_execlp (args)
741 SCM args;
742 {
743 char **execargv;
744 SCM filename = SCM_CAR (args);
745 SCM_ASSERT (SCM_NIMP (filename) && SCM_ROSTRINGP (filename), filename, SCM_ARG1, s_sys_execlp);
746 if (SCM_SUBSTRP (filename))
747 filename = scm_makfromstr (SCM_ROCHARS (filename), SCM_ROLENGTH (filename), 0);
748 args = SCM_CDR (args);
749 execargv = scm_convert_exec_args (args);
750 execvp (SCM_ROCHARS (filename), execargv);
751 scm_syserror (s_sys_execlp);
752 /* not reached. */
753 return SCM_BOOL_F;
754 }
755
756 /* Flushing streams etc., is not done here. */
757 SCM_PROC (s_sys_fork, "fork", 0, 0, 0, scm_sys_fork);
758
759 SCM
760 scm_sys_fork()
761 {
762 int pid;
763 pid = fork ();
764 if (pid == -1)
765 scm_syserror (s_sys_fork);
766 return SCM_MAKINUM (0L+pid);
767 }
768
769
770 SCM_PROC (s_sys_uname, "uname", 0, 0, 0, scm_sys_uname);
771
772 SCM
773 scm_sys_uname ()
774 {
775 #ifdef HAVE_UNAME
776 struct utsname buf;
777 SCM ans = scm_make_vector(SCM_MAKINUM(5), SCM_UNSPECIFIED, SCM_BOOL_F);
778 SCM *ve = SCM_VELTS (ans);
779 if (uname (&buf))
780 return SCM_MAKINUM (errno);
781 ve[0] = scm_makfrom0str (buf.sysname);
782 ve[1] = scm_makfrom0str (buf.nodename);
783 ve[2] = scm_makfrom0str (buf.release);
784 ve[3] = scm_makfrom0str (buf.version);
785 ve[4] = scm_makfrom0str (buf.machine);
786 /*
787 a linux special?
788 ve[5] = scm_makfrom0str (buf.domainname);
789 */
790 return ans;
791 #else
792 scm_sysmissing (s_sys_uname);
793 /* not reached. */
794 return SCM_BOOL_F;
795 #endif
796 }
797
798 SCM_PROC (s_environ, "environ", 0, 1, 0, scm_environ);
799
800 SCM
801 scm_environ (env)
802 SCM env;
803 {
804 if (SCM_UNBNDP (env))
805 return scm_makfromstrs (-1, environ);
806 else
807 {
808 int num_strings;
809 char **new_environ;
810 int i = 0;
811 SCM_ASSERT (SCM_NULLP (env) || (SCM_NIMP (env) && SCM_CONSP (env)),
812 env, SCM_ARG1, s_environ);
813 num_strings = scm_ilength (env);
814 new_environ = (char **) scm_must_malloc ((num_strings + 1)
815 * sizeof (char *),
816 s_environ);
817 while (SCM_NNULLP (env))
818 {
819 int len;
820 char *src;
821 SCM_ASSERT (SCM_NIMP (SCM_CAR (env)) && SCM_ROSTRINGP (SCM_CAR (env)), env, SCM_ARG1,
822 s_environ);
823 len = 1 + SCM_ROLENGTH (SCM_CAR (env));
824 new_environ[i] = scm_must_malloc ((long) len, s_environ);
825 src = SCM_ROCHARS (SCM_CAR (env));
826 while (len--)
827 new_environ[i][len] = src[len];
828 env = SCM_CDR (env);
829 i++;
830 }
831 new_environ[i] = 0;
832 /* Free the old environment, except when called for the first
833 * time.
834 */
835 {
836 char **ep;
837 static int first = 1;
838 if (!first)
839 {
840 for (ep = environ; *ep != NULL; ep++)
841 scm_must_free (*ep);
842 scm_must_free ((char *) environ);
843 }
844 first = 0;
845 }
846 environ = new_environ;
847 return SCM_UNSPECIFIED;
848 }
849 }
850
851
852 SCM_PROC (s_open_pipe, "open-pipe", 2, 0, 0, scm_open_pipe);
853
854 SCM
855 scm_open_pipe (pipestr, modes)
856 SCM pipestr;
857 SCM modes;
858 {
859 FILE *f;
860 register SCM z;
861 struct scm_port_table * pt;
862
863 SCM_ASSERT (SCM_NIMP (pipestr) && SCM_ROSTRINGP (pipestr), pipestr, SCM_ARG1, s_open_pipe);
864 if (SCM_SUBSTRP (pipestr))
865 pipestr = scm_makfromstr (SCM_ROCHARS (pipestr), SCM_ROLENGTH (pipestr), 0);
866 SCM_ASSERT (SCM_NIMP (modes) && SCM_ROSTRINGP (modes), modes, SCM_ARG2, s_open_pipe);
867 if (SCM_SUBSTRP (modes))
868 modes = scm_makfromstr (SCM_ROCHARS (modes), SCM_ROLENGTH (modes), 0);
869 SCM_NEWCELL (z);
870 SCM_DEFER_INTS;
871 scm_ignore_signals ();
872 SCM_SYSCALL (f = popen (SCM_ROCHARS (pipestr), SCM_ROCHARS (modes)));
873 scm_unignore_signals ();
874 if (!f)
875 scm_syserror (s_open_pipe);
876 pt = scm_add_to_port_table (z);
877 SCM_SETPTAB_ENTRY (z, pt);
878 SCM_SETCAR (z, scm_tc16_pipe | SCM_OPN
879 | (strchr (SCM_ROCHARS (modes), 'r') ? SCM_RDNG : SCM_WRTNG));
880 SCM_SETSTREAM (z, (SCM)f);
881 SCM_ALLOW_INTS;
882 return z;
883 }
884
885
886 SCM_PROC (s_open_input_pipe, "open-input-pipe", 1, 0, 0, scm_open_input_pipe);
887
888 SCM
889 scm_open_input_pipe(pipestr)
890 SCM pipestr;
891 {
892 return scm_open_pipe(pipestr, scm_makfromstr("r", (sizeof "r")-1, 0));
893 }
894
895 SCM_PROC (s_open_output_pipe, "open-output-pipe", 1, 0, 0, scm_open_output_pipe);
896
897 SCM
898 scm_open_output_pipe(pipestr)
899 SCM pipestr;
900 {
901 return scm_open_pipe(pipestr, scm_makfromstr("w", (sizeof "w")-1, 0));
902 }
903
904
905 SCM_PROC (s_sys_utime, "utime", 1, 2, 0, scm_sys_utime);
906
907 SCM
908 scm_sys_utime (pathname, actime, modtime)
909 SCM pathname;
910 SCM actime;
911 SCM modtime;
912 {
913 int rv;
914 struct utimbuf utm_tmp;
915
916 SCM_ASSERT (SCM_NIMP (pathname) && SCM_STRINGP (pathname), pathname, SCM_ARG1, s_sys_utime);
917
918 if (SCM_UNBNDP (actime))
919 SCM_SYSCALL (time (&utm_tmp.actime));
920 else
921 utm_tmp.actime = scm_num2ulong (actime, (char *) SCM_ARG2, s_sys_utime);
922
923 if (SCM_UNBNDP (modtime))
924 SCM_SYSCALL (time (&utm_tmp.modtime));
925 else
926 utm_tmp.modtime = scm_num2ulong (modtime, (char *) SCM_ARG3, s_sys_utime);
927
928 SCM_SYSCALL (rv = utime (SCM_CHARS (pathname), &utm_tmp));
929 if (rv != 0)
930 scm_syserror (s_sys_utime);
931 return SCM_UNSPECIFIED;
932 }
933
934 SCM_PROC (s_sys_access, "access?", 2, 0, 0, scm_sys_access);
935
936 SCM
937 scm_sys_access (path, how)
938 SCM path;
939 SCM how;
940 {
941 int rv;
942
943 SCM_ASSERT (SCM_NIMP (path) && SCM_ROSTRINGP (path), path, SCM_ARG1, s_sys_access);
944 if (SCM_SUBSTRP (path))
945 path = scm_makfromstr (SCM_ROCHARS (path), SCM_ROLENGTH (path), 0);
946 SCM_ASSERT (SCM_INUMP (how), how, SCM_ARG2, s_sys_access);
947 rv = access (SCM_ROCHARS (path), SCM_INUM (how));
948 return rv ? SCM_BOOL_F : SCM_BOOL_T;
949 }
950
951 SCM_PROC (s_getpid, "getpid", 0, 0, 0, scm_getpid);
952
953 SCM
954 scm_getpid ()
955 {
956 return SCM_MAKINUM ((unsigned long) getpid ());
957 }
958
959 SCM_PROC (s_sys_putenv, "putenv", 1, 0, 0, scm_sys_putenv);
960
961 SCM
962 scm_sys_putenv (str)
963 SCM str;
964 {
965 #ifdef HAVE_PUTENV
966 SCM_ASSERT (SCM_NIMP (str) && SCM_STRINGP (str), str, SCM_ARG1, s_sys_putenv);
967 return putenv (SCM_CHARS (str)) ? SCM_MAKINUM (errno) : SCM_BOOL_T;
968 #else
969 scm_sysmissing (s_sys_putenv);
970 /* not reached. */
971 return SCM_BOOL_F;
972 #endif
973 }
974
975 SCM_PROC (s_read_line, "read-line", 0, 2, 0, scm_read_line);
976
977 SCM
978 scm_read_line (port, include_terminator)
979 SCM port;
980 SCM include_terminator;
981 {
982 register int c;
983 register int j = 0;
984 scm_sizet len = 30;
985 SCM tok_buf;
986 register char *p;
987 int include;
988
989 tok_buf = scm_makstr ((long) len, 0);
990 p = SCM_CHARS (tok_buf);
991 if (SCM_UNBNDP (port))
992 port = scm_cur_inp;
993 else
994 SCM_ASSERT (SCM_NIMP (port) && SCM_OPINPORTP (port), port, SCM_ARG1, s_read_line);
995
996 if (SCM_UNBNDP (include_terminator))
997 include = 0;
998 else
999 include = SCM_NFALSEP (include_terminator);
1000
1001 if (EOF == (c = scm_gen_getc (port)))
1002 return SCM_EOF_VAL;
1003 while (1)
1004 {
1005 switch (c)
1006 {
1007 case SCM_LINE_INCREMENTORS:
1008 if (j >= len)
1009 {
1010 p = scm_grow_tok_buf (&tok_buf);
1011 len = SCM_LENGTH (tok_buf);
1012 }
1013 p[j++] = c;
1014 /* fallthrough */
1015 case EOF:
1016 if (len == j)
1017 return tok_buf;
1018 return scm_vector_set_length_x (tok_buf, (SCM) SCM_MAKINUM (j));
1019
1020 default:
1021 if (j >= len)
1022 {
1023 p = scm_grow_tok_buf (&tok_buf);
1024 len = SCM_LENGTH (tok_buf);
1025 }
1026 p[j++] = c;
1027 c = scm_gen_getc (port);
1028 break;
1029 }
1030 }
1031 }
1032
1033 SCM_PROC (s_read_line_x, "read-line!", 1, 1, 0, scm_read_line_x);
1034
1035 SCM
1036 scm_read_line_x (str, port)
1037 SCM str;
1038 SCM port;
1039 {
1040 register int c;
1041 register int j = 0;
1042 register char *p;
1043 scm_sizet len;
1044 SCM_ASSERT (SCM_NIMP (str) && SCM_STRINGP (str), str, SCM_ARG1, s_read_line_x);
1045 p = SCM_CHARS (str);
1046 len = SCM_LENGTH (str);
1047 if SCM_UNBNDP
1048 (port) port = scm_cur_inp;
1049 else
1050 SCM_ASSERT (SCM_NIMP (port) && SCM_OPINPORTP (port), port, SCM_ARG2, s_read_line_x);
1051 c = scm_gen_getc (port);
1052 if (EOF == c)
1053 return SCM_EOF_VAL;
1054 while (1)
1055 {
1056 switch (c)
1057 {
1058 case SCM_LINE_INCREMENTORS:
1059 case EOF:
1060 return SCM_MAKINUM (j);
1061 default:
1062 if (j >= len)
1063 {
1064 scm_gen_ungetc (c, port);
1065 return SCM_BOOL_F;
1066 }
1067 p[j++] = c;
1068 c = scm_gen_getc (port);
1069 }
1070 }
1071 }
1072
1073 SCM_PROC (s_write_line, "write-line", 1, 1, 0, scm_write_line);
1074
1075 SCM
1076 scm_write_line (obj, port)
1077 SCM obj;
1078 SCM port;
1079 {
1080 scm_display (obj, port);
1081 return scm_newline (port);
1082 }
1083
1084 SCM_PROC (s_setlocale, "setlocale", 1, 1, 0, scm_setlocale);
1085
1086 SCM
1087 scm_setlocale (category, locale)
1088 SCM category;
1089 SCM locale;
1090 {
1091 #ifdef HAVE_SETLOCALE
1092 char *clocale;
1093 char *rv;
1094
1095 SCM_ASSERT (SCM_INUMP (category), category, SCM_ARG1, s_setlocale);
1096 if (SCM_UNBNDP (locale))
1097 {
1098 clocale = NULL;
1099 }
1100 else
1101 {
1102 SCM_ASSERT (SCM_NIMP (locale) && SCM_STRINGP (locale), locale, SCM_ARG2, s_setlocale);
1103 clocale = SCM_CHARS (locale);
1104 }
1105
1106 rv = setlocale (SCM_INUM (category), clocale);
1107 if (rv == NULL)
1108 scm_syserror (s_setlocale);
1109 return scm_makfrom0str (rv);
1110 #else
1111 scm_sysmissing (s_setlocale);
1112 /* not reached. */
1113 return SCM_BOOL_F;
1114 #endif
1115 }
1116
1117 SCM_PROC (s_strftime, "strftime", 2, 0, 0, scm_strftime);
1118
1119 SCM
1120 scm_strftime (format, stime)
1121 SCM format;
1122 SCM stime;
1123 {
1124 struct tm t;
1125
1126 char *tbuf;
1127 int n;
1128 int size = 50;
1129 char *fmt;
1130 int len;
1131
1132 SCM_ASSERT (SCM_NIMP (format) && SCM_STRINGP (format), format, SCM_ARG1, s_strftime);
1133 SCM_ASSERT (SCM_NIMP (stime) && SCM_VECTORP (stime) && scm_obj_length (stime) == 9,
1134 stime, SCM_ARG2, s_strftime);
1135
1136 fmt = SCM_ROCHARS (format);
1137 len = SCM_ROLENGTH (format);
1138
1139 #define tm_deref scm_num2long (SCM_VELTS (stime)[n++], (char *)SCM_ARG2, s_strftime)
1140 n = 0;
1141 t.tm_sec = tm_deref;
1142 t.tm_min = tm_deref;
1143 t.tm_hour = tm_deref;
1144 t.tm_mday = tm_deref;
1145 t.tm_mon = tm_deref;
1146 t.tm_year = tm_deref;
1147 /* not used by mktime.
1148 t.tm_wday = tm_deref;
1149 t.tm_yday = tm_deref; */
1150 t.tm_isdst = tm_deref;
1151 #undef tm_deref
1152
1153 /* fill in missing fields and set the timezone. */
1154 mktime (&t);
1155
1156 tbuf = scm_must_malloc (size, s_strftime);
1157 while ((len = strftime (tbuf, size, fmt, &t)) == size)
1158 {
1159 scm_must_free (tbuf);
1160 size *= 2;
1161 tbuf = scm_must_malloc (size, s_strftime);
1162 }
1163 return scm_makfromstr (tbuf, len, 0);
1164 }
1165
1166 SCM_PROC (s_sys_strptime, "strptime", 2, 0, 0, scm_sys_strptime);
1167
1168 SCM
1169 scm_sys_strptime (format, string)
1170 SCM format;
1171 SCM string;
1172 {
1173 #ifdef HAVE_STRPTIME
1174 SCM stime;
1175 struct tm t;
1176
1177 char *fmt, *str, *rest;
1178 int n;
1179
1180 SCM_ASSERT (SCM_NIMP (format) && SCM_ROSTRINGP (format), format, SCM_ARG1, s_sys_strptime);
1181 if (SCM_SUBSTRP (format))
1182 format = scm_makfromstr (SCM_ROCHARS (format), SCM_ROLENGTH (format), 0);
1183 SCM_ASSERT (SCM_NIMP (string) && SCM_ROSTRINGP (string), string, SCM_ARG2, s_sys_strptime);
1184 if (SCM_SUBSTRP (string))
1185 string = scm_makfromstr (SCM_ROCHARS (string), SCM_ROLENGTH (string), 0);
1186
1187 fmt = SCM_CHARS (format);
1188 str = SCM_CHARS (string);
1189
1190 /* initialize the struct tm */
1191 #define tm_init(field) t.field = 0
1192 tm_init (tm_sec);
1193 tm_init (tm_min);
1194 tm_init (tm_hour);
1195 tm_init (tm_mday);
1196 tm_init (tm_mon);
1197 tm_init (tm_year);
1198 tm_init (tm_wday);
1199 tm_init (tm_yday);
1200 tm_init (tm_isdst);
1201 #undef tm_init
1202
1203 SCM_DEFER_INTS;
1204 rest = strptime (str, fmt, &t);
1205 SCM_ALLOW_INTS;
1206
1207 if (rest == NULL)
1208 scm_syserror (s_sys_strptime);
1209
1210 stime = scm_make_vector (SCM_MAKINUM (9), scm_long2num (0), SCM_UNDEFINED);
1211
1212 #define stime_set(val) scm_vector_set_x (stime, SCM_MAKINUM (n++), scm_long2num (t.val));
1213 n = 0;
1214 stime_set (tm_sec);
1215 stime_set (tm_min);
1216 stime_set (tm_hour);
1217 stime_set (tm_mday);
1218 stime_set (tm_mon);
1219 stime_set (tm_year);
1220 stime_set (tm_wday);
1221 stime_set (tm_yday);
1222 stime_set (tm_isdst);
1223 #undef stime_set
1224
1225 return scm_cons (stime, scm_makfrom0str (rest));
1226 #else
1227 scm_sysmissing (s_sys_strptime);
1228 /* not reached. */
1229 return SCM_BOOL_F;
1230 #endif
1231 }
1232
1233 SCM_PROC (s_sys_mknod, "mknod", 3, 0, 0, scm_sys_mknod);
1234
1235 SCM
1236 scm_sys_mknod(path, mode, dev)
1237 SCM path;
1238 SCM mode;
1239 SCM dev;
1240 {
1241 #ifdef HAVE_MKNOD
1242 int val;
1243 SCM_ASSERT(SCM_NIMP(path) && SCM_STRINGP(path), path, SCM_ARG1, s_sys_mknod);
1244 SCM_ASSERT(SCM_INUMP(mode), mode, SCM_ARG2, s_sys_mknod);
1245 SCM_ASSERT(SCM_INUMP(dev), dev, SCM_ARG3, s_sys_mknod);
1246 SCM_SYSCALL(val = mknod(SCM_CHARS(path), SCM_INUM(mode), SCM_INUM(dev)));
1247 if (val != 0)
1248 scm_syserror (s_sys_mknod);
1249 return SCM_UNSPECIFIED;
1250 #else
1251 scm_sysmissing (s_sys_mknod);
1252 /* not reached. */
1253 return SCM_BOOL_F;
1254 #endif
1255 }
1256
1257
1258 SCM_PROC (s_sys_nice, "nice", 1, 0, 0, scm_sys_nice);
1259
1260 SCM
1261 scm_sys_nice(incr)
1262 SCM incr;
1263 {
1264 #ifdef HAVE_NICE
1265 SCM_ASSERT(SCM_INUMP(incr), incr, SCM_ARG1, s_sys_nice);
1266 if (nice(SCM_INUM(incr)) != 0)
1267 scm_syserror (s_sys_nice);
1268 return SCM_UNSPECIFIED;
1269 #else
1270 scm_sysmissing (s_sys_nice);
1271 /* not reached. */
1272 return SCM_BOOL_F;
1273 #endif
1274 }
1275
1276
1277 SCM_PROC (s_sync, "sync", 0, 0, 0, scm_sync);
1278
1279 SCM
1280 scm_sync()
1281 {
1282 #ifdef HAVE_SYNC
1283 sync();
1284 #else
1285 scm_sysmissing (s_sync);
1286 /* not reached. */
1287 #endif
1288 return SCM_BOOL_F;
1289 }
1290
1291
1292
1293
1294 void
1295 scm_init_posix ()
1296 {
1297 scm_add_feature ("posix");
1298 #ifdef HAVE_GETEUID
1299 scm_add_feature ("EIDs");
1300 #endif
1301 #ifdef WAIT_ANY
1302 scm_sysintern ("WAIT_ANY", SCM_MAKINUM (WAIT_ANY));
1303 #endif
1304 #ifdef WAIT_MYPGRP
1305 scm_sysintern ("WAIT_MYPGRP", SCM_MAKINUM (WAIT_MYPGRP));
1306 #endif
1307 #ifdef WNOHANG
1308 scm_sysintern ("WNOHANG", SCM_MAKINUM (WNOHANG));
1309 #endif
1310 #ifdef WUNTRACED
1311 scm_sysintern ("WUNTRACED", SCM_MAKINUM (WUNTRACED));
1312 #endif
1313
1314 #ifdef EINTR
1315 scm_sysintern ("EINTR", SCM_MAKINUM (EINTR));
1316 #endif
1317
1318 #ifdef SIGHUP
1319 scm_sysintern ("SIGHUP", SCM_MAKINUM (SIGHUP));
1320 #endif
1321 #ifdef SIGINT
1322 scm_sysintern ("SIGINT", SCM_MAKINUM (SIGINT));
1323 #endif
1324 #ifdef SIGQUIT
1325 scm_sysintern ("SIGQUIT", SCM_MAKINUM (SIGQUIT));
1326 #endif
1327 #ifdef SIGILL
1328 scm_sysintern ("SIGILL", SCM_MAKINUM (SIGILL));
1329 #endif
1330 #ifdef SIGTRAP
1331 scm_sysintern ("SIGTRAP", SCM_MAKINUM (SIGTRAP));
1332 #endif
1333 #ifdef SIGABRT
1334 scm_sysintern ("SIGABRT", SCM_MAKINUM (SIGABRT));
1335 #endif
1336 #ifdef SIGIOT
1337 scm_sysintern ("SIGIOT", SCM_MAKINUM (SIGIOT));
1338 #endif
1339 #ifdef SIGBUS
1340 scm_sysintern ("SIGBUS", SCM_MAKINUM (SIGBUS));
1341 #endif
1342 #ifdef SIGFPE
1343 scm_sysintern ("SIGFPE", SCM_MAKINUM (SIGFPE));
1344 #endif
1345 #ifdef SIGKILL
1346 scm_sysintern ("SIGKILL", SCM_MAKINUM (SIGKILL));
1347 #endif
1348 #ifdef SIGUSR1
1349 scm_sysintern ("SIGUSR1", SCM_MAKINUM (SIGUSR1));
1350 #endif
1351 #ifdef SIGSEGV
1352 scm_sysintern ("SIGSEGV", SCM_MAKINUM (SIGSEGV));
1353 #endif
1354 #ifdef SIGUSR2
1355 scm_sysintern ("SIGUSR2", SCM_MAKINUM (SIGUSR2));
1356 #endif
1357 #ifdef SIGPIPE
1358 scm_sysintern ("SIGPIPE", SCM_MAKINUM (SIGPIPE));
1359 #endif
1360 #ifdef SIGALRM
1361 scm_sysintern ("SIGALRM", SCM_MAKINUM (SIGALRM));
1362 #endif
1363 #ifdef SIGTERM
1364 scm_sysintern ("SIGTERM", SCM_MAKINUM (SIGTERM));
1365 #endif
1366 #ifdef SIGSTKFLT
1367 scm_sysintern ("SIGSTKFLT", SCM_MAKINUM (SIGSTKFLT));
1368 #endif
1369 #ifdef SIGCHLD
1370 scm_sysintern ("SIGCHLD", SCM_MAKINUM (SIGCHLD));
1371 #endif
1372 #ifdef SIGCONT
1373 scm_sysintern ("SIGCONT", SCM_MAKINUM (SIGCONT));
1374 #endif
1375 #ifdef SIGSTOP
1376 scm_sysintern ("SIGSTOP", SCM_MAKINUM (SIGSTOP));
1377 #endif
1378 #ifdef SIGTSTP
1379 scm_sysintern ("SIGTSTP", SCM_MAKINUM (SIGTSTP));
1380 #endif
1381 #ifdef SIGTTIN
1382 scm_sysintern ("SIGTTIN", SCM_MAKINUM (SIGTTIN));
1383 #endif
1384 #ifdef SIGTTOU
1385 scm_sysintern ("SIGTTOU", SCM_MAKINUM (SIGTTOU));
1386 #endif
1387 #ifdef SIGIO
1388 scm_sysintern ("SIGIO", SCM_MAKINUM (SIGIO));
1389 #endif
1390 #ifdef SIGPOLL
1391 scm_sysintern ("SIGPOLL", SCM_MAKINUM (SIGPOLL));
1392 #endif
1393 #ifdef SIGURG
1394 scm_sysintern ("SIGURG", SCM_MAKINUM (SIGURG));
1395 #endif
1396 #ifdef SIGXCPU
1397 scm_sysintern ("SIGXCPU", SCM_MAKINUM (SIGXCPU));
1398 #endif
1399 #ifdef SIGXFSZ
1400 scm_sysintern ("SIGXFSZ", SCM_MAKINUM (SIGXFSZ));
1401 #endif
1402 #ifdef SIGVTALRM
1403 scm_sysintern ("SIGVTALRM", SCM_MAKINUM (SIGVTALRM));
1404 #endif
1405 #ifdef SIGPROF
1406 scm_sysintern ("SIGPROF", SCM_MAKINUM (SIGPROF));
1407 #endif
1408 #ifdef SIGWINCH
1409 scm_sysintern ("SIGWINCH", SCM_MAKINUM (SIGWINCH));
1410 #endif
1411 #ifdef SIGLOST
1412 scm_sysintern ("SIGLOST", SCM_MAKINUM (SIGLOST));
1413 #endif
1414 #ifdef SIGPWR
1415 scm_sysintern ("SIGPWR", SCM_MAKINUM (SIGPWR));
1416 #endif
1417 /* access() symbols. */
1418 scm_sysintern ("R_OK", SCM_MAKINUM (R_OK));
1419 scm_sysintern ("W_OK", SCM_MAKINUM (W_OK));
1420 scm_sysintern ("X_OK", SCM_MAKINUM (X_OK));
1421 scm_sysintern ("F_OK", SCM_MAKINUM (F_OK));
1422
1423 #ifdef LC_COLLATE
1424 scm_sysintern ("LC_COLLATE", SCM_MAKINUM (LC_COLLATE));
1425 #endif
1426 #ifdef LC_CTYPE
1427 scm_sysintern ("LC_CTYPE", SCM_MAKINUM (LC_CTYPE));
1428 #endif
1429 #ifdef LC_MONETARY
1430 scm_sysintern ("LC_MONETARY", SCM_MAKINUM (LC_MONETARY));
1431 #endif
1432 #ifdef LC_NUMERIC
1433 scm_sysintern ("LC_NUMERIC", SCM_MAKINUM (LC_NUMERIC));
1434 #endif
1435 #ifdef LC_TIME
1436 scm_sysintern ("LC_TIME", SCM_MAKINUM (LC_TIME));
1437 #endif
1438 #ifdef LC_MESSAGES
1439 scm_sysintern ("LC_MESSAGES", SCM_MAKINUM (LC_MESSAGES));
1440 #endif
1441 #ifdef LC_ALL
1442 scm_sysintern ("LC_ALL", SCM_MAKINUM (LC_ALL));
1443 #endif
1444 #include "posix.x"
1445 }