1 /* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
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)
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.
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.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
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.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
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.
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.
55 #ifdef TIME_WITH_SYS_TIME
56 # include <sys/time.h>
60 # include <sys/time.h>
70 extern char *ttyname();
74 #ifdef LIBC_H_WITH_UNISTD_H
78 #ifdef HAVE_SYS_SELECT_H
79 #include <sys/select.h>
82 #include <sys/types.h>
89 # include <sys/wait.h>
92 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
95 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
102 #define SELECT_TYPE fd_set
103 #define SELECT_SET_SIZE FD_SETSIZE
105 #else /* no FD_SET */
107 /* Define the macros to access a single-int bitmap of descriptors. */
108 #define SELECT_SET_SIZE 32
109 #define SELECT_TYPE int
110 #define FD_SET(n, p) (*(p) |= (1 << (n)))
111 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
112 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
113 #define FD_ZERO(p) (*(p) = 0)
115 #endif /* no FD_SET */
117 extern FILE *popen ();
118 extern char ** environ
;
121 #include <sys/utsname.h>
125 # define NAMLEN(dirent) strlen((dirent)->d_name)
127 # define dirent direct
128 # define NAMLEN(dirent) (dirent)->d_namlen
130 # include <sys/ndir.h>
133 # include <sys/dir.h>
140 #ifdef HAVE_SETLOCALE
144 /* Some Unix systems don't define these. CPP hair is dangerous, but
145 this seems safe enough... */
162 /* On NextStep, <utime.h> doesn't define struct utime, unless we
163 #define _POSIX_SOURCE before #including it. I think this is less
164 of a kludge than defining struct utimbuf ourselves. */
165 #ifdef UTIMBUF_NEEDS_POSIX
166 #define _POSIX_SOURCE
169 #ifdef HAVE_SYS_UTIME_H
170 #include <sys/utime.h>
177 /* Please don't add any more #includes or #defines here. The hack
178 above means that _POSIX_SOURCE may be #defined, which will
179 encourage header files to do strange things. */
184 SCM_PROC (s_pipe
, "pipe", 0, 0, 0, scm_pipe
);
192 struct scm_port_table
* ptr
;
193 struct scm_port_table
* ptw
;
199 scm_syserror (s_pipe
);
200 f_rd
= fdopen (fd
[0], "r");
203 SCM_SYSCALL (close (fd
[0]));
204 SCM_SYSCALL (close (fd
[1]));
205 scm_syserror (s_pipe
);
207 f_wt
= fdopen (fd
[1], "w");
213 SCM_SYSCALL (close (fd
[1]));
215 scm_syserror (s_pipe
);
217 ptr
= scm_add_to_port_table (p_rd
);
218 ptw
= scm_add_to_port_table (p_wt
);
219 SCM_SETPTAB_ENTRY (p_rd
, ptr
);
220 SCM_SETPTAB_ENTRY (p_wt
, ptw
);
221 SCM_SETCAR (p_rd
, scm_tc16_fport
| scm_mode_bits ("r"));
222 SCM_SETCAR (p_wt
, scm_tc16_fport
| scm_mode_bits ("w"));
223 SCM_SETSTREAM (p_rd
, (SCM
)f_rd
);
224 SCM_SETSTREAM (p_wt
, (SCM
)f_wt
);
227 return scm_cons (p_rd
, p_wt
);
232 SCM_PROC (s_getgroups
, "getgroups", 0, 0, 0, scm_getgroups
);
238 int ngroups
= getgroups (0, NULL
);
240 scm_syserror (s_getgroups
);
247 groups
= (GETGROUPS_T
*) scm_must_malloc(ngroups
* sizeof(GETGROUPS_T
),
249 val
= getgroups(ngroups
, groups
);
252 scm_must_free((char *)groups
);
253 scm_syserror (s_getgroups
);
255 SCM_SETCHARS(grps
, groups
); /* set up grps as a GC protect */
256 SCM_SETLENGTH(grps
, 0L + ngroups
* sizeof(GETGROUPS_T
), scm_tc7_string
);
258 ans
= scm_make_vector(SCM_MAKINUM(ngroups
), SCM_UNDEFINED
, SCM_BOOL_F
);
259 while (--ngroups
>= 0) SCM_VELTS(ans
)[ngroups
] = SCM_MAKINUM(groups
[ngroups
]);
260 SCM_SETCHARS(grps
, groups
); /* to make sure grps stays around. */
267 SCM_PROC (s_getpwuid
, "getpw", 0, 1, 0, scm_getpwuid
);
274 struct passwd
*entry
;
277 result
= scm_make_vector (SCM_MAKINUM (7), SCM_UNSPECIFIED
, SCM_BOOL_F
);
278 ve
= SCM_VELTS (result
);
279 if (SCM_UNBNDP (user
) || SCM_FALSEP (user
))
282 SCM_SYSCALL (entry
= getpwent ());
284 else if (SCM_INUMP (user
))
287 entry
= getpwuid (SCM_INUM (user
));
291 SCM_ASSERT (SCM_NIMP (user
) && SCM_ROSTRINGP (user
), user
, SCM_ARG1
, s_getpwuid
);
292 if (SCM_SUBSTRP (user
))
293 user
= scm_makfromstr (SCM_ROCHARS (user
), SCM_ROLENGTH (user
), 0);
295 entry
= getpwnam (SCM_ROCHARS (user
));
298 scm_syserror (s_getpwuid
);
300 ve
[0] = scm_makfrom0str (entry
->pw_name
);
301 ve
[1] = scm_makfrom0str (entry
->pw_passwd
);
302 ve
[2] = scm_ulong2num ((unsigned long) entry
->pw_uid
);
303 ve
[3] = scm_ulong2num ((unsigned long) entry
->pw_gid
);
304 ve
[4] = scm_makfrom0str (entry
->pw_gecos
);
306 ve
[5] = scm_makfrom0str ("");
308 ve
[5] = scm_makfrom0str (entry
->pw_dir
);
309 if (!entry
->pw_shell
)
310 ve
[6] = scm_makfrom0str ("");
312 ve
[6] = scm_makfrom0str (entry
->pw_shell
);
319 SCM_PROC (s_setpwent
, "setpw", 0, 1, 0, scm_setpwent
);
325 if (SCM_UNBNDP (arg
) || SCM_FALSEP (arg
))
329 return SCM_UNSPECIFIED
;
334 /* Combines getgrgid and getgrnam. */
335 SCM_PROC (s_getgrgid
, "getgr", 0, 1, 0, scm_getgrgid
);
344 result
= scm_make_vector (SCM_MAKINUM (4), SCM_UNSPECIFIED
, SCM_BOOL_F
);
345 ve
= SCM_VELTS (result
);
347 if (SCM_UNBNDP (name
) || (name
== SCM_BOOL_F
))
348 SCM_SYSCALL (entry
= getgrent ());
349 else if (SCM_INUMP (name
))
350 SCM_SYSCALL (entry
= getgrgid (SCM_INUM (name
)));
353 SCM_ASSERT (SCM_NIMP (name
) && SCM_ROSTRINGP (name
), name
, SCM_ARG1
,
355 SCM_COERCE_SUBSTR (name
);
356 SCM_SYSCALL (entry
= getgrnam (SCM_ROCHARS (name
)));
359 scm_syserror (s_getgrgid
);
361 ve
[0] = scm_makfrom0str (entry
->gr_name
);
362 ve
[1] = scm_makfrom0str (entry
->gr_passwd
);
363 ve
[2] = scm_ulong2num ((unsigned long) entry
->gr_gid
);
364 ve
[3] = scm_makfromstrs (-1, entry
->gr_mem
);
371 SCM_PROC (s_setgrent
, "setgr", 0, 1, 0, scm_setgrent
);
377 if (SCM_UNBNDP (arg
) || SCM_FALSEP (arg
))
381 return SCM_UNSPECIFIED
;
386 SCM_PROC (s_kill
, "kill", 2, 0, 0, scm_kill
);
393 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_kill
);
394 SCM_ASSERT (SCM_INUMP (sig
), sig
, SCM_ARG2
, s_kill
);
395 /* Signal values are interned in scm_init_posix(). */
396 if (kill ((int) SCM_INUM (pid
), (int) SCM_INUM (sig
)) != 0)
397 scm_syserror (s_kill
);
398 return SCM_UNSPECIFIED
;
403 SCM_PROC (s_waitpid
, "waitpid", 1, 1, 0, scm_waitpid
);
406 scm_waitpid (pid
, options
)
414 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_waitpid
);
415 if (SCM_UNBNDP (options
))
419 SCM_ASSERT (SCM_INUMP (options
), options
, SCM_ARG2
, s_waitpid
);
420 /* Flags are interned in scm_init_posix. */
421 ioptions
= SCM_INUM (options
);
423 SCM_SYSCALL (i
= waitpid (SCM_INUM (pid
), &status
, ioptions
));
425 scm_syserror (s_waitpid
);
426 return scm_cons (SCM_MAKINUM (0L + i
), SCM_MAKINUM (0L + status
));
428 scm_sysmissing (s_waitpid
);
434 SCM_PROC (s_status_exit_val
, "status:exit-val", 1, 0, 0, scm_status_exit_val
);
436 scm_status_exit_val (status
)
441 SCM_ASSERT (SCM_INUMP (status
), status
, SCM_ARG1
,s_status_exit_val
);
443 /* On Ultrix, the WIF... macros assume their argument is an lvalue;
444 go figure. SCM_INUM does not yield an lvalue. */
445 lstatus
= SCM_INUM (status
);
446 if (WIFEXITED (lstatus
))
447 return (SCM_MAKINUM (WEXITSTATUS (lstatus
)));
452 SCM_PROC (s_status_term_sig
, "status:term-sig", 1, 0, 0, scm_status_term_sig
);
454 scm_status_term_sig (status
)
459 SCM_ASSERT (SCM_INUMP (status
), status
, SCM_ARG1
,s_status_term_sig
);
461 lstatus
= SCM_INUM (status
);
462 if (WIFSIGNALED (lstatus
))
463 return SCM_MAKINUM (WTERMSIG (lstatus
));
468 SCM_PROC (s_status_stop_sig
, "status:stop-sig", 1, 0, 0, scm_status_stop_sig
);
470 scm_status_stop_sig (status
)
475 SCM_ASSERT (SCM_INUMP (status
), status
, SCM_ARG1
,s_status_stop_sig
);
477 lstatus
= SCM_INUM (status
);
478 if (WIFSTOPPED (lstatus
))
479 return SCM_MAKINUM (WSTOPSIG (lstatus
));
484 SCM_PROC (s_getppid
, "getppid", 0, 0, 0, scm_getppid
);
489 return SCM_MAKINUM (0L + getppid ());
494 SCM_PROC (s_getuid
, "getuid", 0, 0, 0, scm_getuid
);
499 return SCM_MAKINUM (0L + getuid ());
504 SCM_PROC (s_getgid
, "getgid", 0, 0, 0, scm_getgid
);
509 return SCM_MAKINUM (0L + getgid ());
514 SCM_PROC (s_geteuid
, "geteuid", 0, 0, 0, scm_geteuid
);
520 return SCM_MAKINUM (0L + geteuid ());
522 return SCM_MAKINUM (0L + getuid ());
528 SCM_PROC (s_getegid
, "getegid", 0, 0, 0, scm_getegid
);
534 return SCM_MAKINUM (0L + getegid ());
536 return SCM_MAKINUM (0L + getgid ());
541 SCM_PROC (s_setuid
, "setuid", 1, 0, 0, scm_setuid
);
547 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_setuid
);
548 if (setuid (SCM_INUM (id
)) != 0)
549 scm_syserror (s_setuid
);
550 return SCM_UNSPECIFIED
;
553 SCM_PROC (s_setgid
, "setgid", 1, 0, 0, scm_setgid
);
559 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_setgid
);
560 if (setgid (SCM_INUM (id
)) != 0)
561 scm_syserror (s_setgid
);
562 return SCM_UNSPECIFIED
;
565 SCM_PROC (s_seteuid
, "seteuid", 1, 0, 0, scm_seteuid
);
573 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_seteuid
);
575 rv
= seteuid (SCM_INUM (id
));
577 rv
= setuid (SCM_INUM (id
));
580 scm_syserror (s_seteuid
);
581 return SCM_UNSPECIFIED
;
584 SCM_PROC (s_setegid
, "setegid", 1, 0, 0, scm_setegid
);
592 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_setegid
);
594 rv
= setegid (SCM_INUM (id
));
596 rv
= setgid (SCM_INUM (id
));
599 scm_syserror (s_setegid
);
600 return SCM_UNSPECIFIED
;
604 SCM_PROC (s_getpgrp
, "getpgrp", 0, 0, 0, scm_getpgrp
);
609 fn
= (int (*) ()) getpgrp
;
610 return SCM_MAKINUM (fn (0));
613 SCM_PROC (s_setpgid
, "setpgid", 2, 0, 0, scm_setpgid
);
615 scm_setpgid (pid
, pgid
)
619 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_setpgid
);
620 SCM_ASSERT (SCM_INUMP (pgid
), pgid
, SCM_ARG2
, s_setpgid
);
621 /* FIXME(?): may be known as setpgrp. */
622 if (setpgid (SCM_INUM (pid
), SCM_INUM (pgid
)) != 0)
623 scm_syserror (s_setpgid
);
624 return SCM_UNSPECIFIED
;
626 scm_sysmissing (s_setpgid
);
632 SCM_PROC (s_setsid
, "setsid", 0, 0, 0, scm_setsid
);
637 pid_t sid
= setsid ();
639 scm_syserror (s_setsid
);
640 return SCM_UNSPECIFIED
;
642 scm_sysmissing (s_setsid
);
648 SCM_PROC (s_ttyname
, "ttyname", 1, 0, 0, scm_ttyname
);
656 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPPORTP (port
), port
, SCM_ARG1
, s_ttyname
);
657 if (scm_tc16_fport
!= SCM_TYP16 (port
))
659 fd
= fileno ((FILE *)SCM_STREAM (port
));
661 scm_syserror (s_ttyname
);
662 SCM_SYSCALL (ans
= ttyname (fd
));
664 scm_syserror (s_ttyname
);
665 /* ans could be overwritten by another call to ttyname */
666 return (scm_makfrom0str (ans
));
670 SCM_PROC (s_ctermid
, "ctermid", 0, 0, 0, scm_ctermid
);
675 char *result
= ctermid (NULL
);
677 scm_syserror (s_ctermid
);
678 return scm_makfrom0str (result
);
680 scm_sysmissing (s_ctermid
);
686 SCM_PROC (s_tcgetpgrp
, "tcgetpgrp", 1, 0, 0, scm_tcgetpgrp
);
691 #ifdef HAVE_TCGETPGRP
694 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPFPORTP (port
), port
, SCM_ARG1
, s_tcgetpgrp
);
695 fd
= fileno ((FILE *)SCM_STREAM (port
));
696 if (fd
== -1 || (pgid
= tcgetpgrp (fd
)) == -1)
697 scm_syserror (s_tcgetpgrp
);
698 return SCM_MAKINUM (pgid
);
700 scm_sysmissing (s_tcgetpgrp
);
706 SCM_PROC (s_tcsetpgrp
, "tcsetpgrp", 2, 0, 0, scm_tcsetpgrp
);
708 scm_tcsetpgrp (port
, pgid
)
711 #ifdef HAVE_TCSETPGRP
713 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPFPORTP (port
), port
, SCM_ARG1
, s_tcsetpgrp
);
714 SCM_ASSERT (SCM_INUMP (pgid
), pgid
, SCM_ARG2
, s_tcsetpgrp
);
715 fd
= fileno ((FILE *)SCM_STREAM (port
));
716 if (fd
== -1 || tcsetpgrp (fd
, SCM_INUM (pgid
)) == -1)
717 scm_syserror (s_tcsetpgrp
);
718 return SCM_UNSPECIFIED
;
720 scm_sysmissing (s_tcsetpgrp
);
726 /* Copy exec args from an SCM vector into a new C array. */
728 static char ** scm_convert_exec_args
SCM_P ((SCM args
));
731 scm_convert_exec_args (args
)
738 num_args
= scm_ilength (args
);
740 scm_must_malloc ((num_args
+ 1) * sizeof (char *), s_ttyname
);
741 for (i
= 0; SCM_NNULLP (args
); args
= SCM_CDR (args
), ++i
)
746 SCM_ASSERT (SCM_NIMP (SCM_CAR (args
)) && SCM_ROSTRINGP (SCM_CAR (args
)),
747 SCM_CAR (args
), "wrong type in SCM_ARG", "exec arg");
748 len
= 1 + SCM_ROLENGTH (SCM_CAR (args
));
749 dst
= (char *) scm_must_malloc ((long) len
, s_ttyname
);
750 src
= SCM_ROCHARS (SCM_CAR (args
));
760 SCM_PROC (s_execl
, "execl", 0, 0, 1, scm_execl
);
767 SCM filename
= SCM_CAR (args
);
768 SCM_ASSERT (SCM_NIMP (filename
) && SCM_ROSTRINGP (filename
), filename
, SCM_ARG1
, s_execl
);
769 if (SCM_SUBSTRP (filename
))
770 filename
= scm_makfromstr (SCM_ROCHARS (filename
), SCM_ROLENGTH (filename
), 0);
771 args
= SCM_CDR (args
);
772 execargv
= scm_convert_exec_args (args
);
773 execv (SCM_ROCHARS (filename
), execargv
);
774 scm_syserror (s_execl
);
779 SCM_PROC (s_execlp
, "execlp", 0, 0, 1, scm_execlp
);
786 SCM filename
= SCM_CAR (args
);
787 SCM_ASSERT (SCM_NIMP (filename
) && SCM_ROSTRINGP (filename
), filename
,
789 if (SCM_SUBSTRP (filename
))
790 filename
= scm_makfromstr (SCM_ROCHARS (filename
),
791 SCM_ROLENGTH (filename
), 0);
792 args
= SCM_CDR (args
);
793 execargv
= scm_convert_exec_args (args
);
794 execvp (SCM_ROCHARS (filename
), execargv
);
795 scm_syserror (s_execlp
);
800 SCM_PROC (s_fork
, "primitive-fork", 0, 0, 0, scm_fork
);
808 scm_syserror (s_fork
);
809 return SCM_MAKINUM (0L+pid
);
813 SCM_PROC (s_uname
, "uname", 0, 0, 0, scm_uname
);
820 SCM ans
= scm_make_vector(SCM_MAKINUM(5), SCM_UNSPECIFIED
, SCM_BOOL_F
);
821 SCM
*ve
= SCM_VELTS (ans
);
824 scm_syserror (s_uname
);
825 ve
[0] = scm_makfrom0str (buf
.sysname
);
826 ve
[1] = scm_makfrom0str (buf
.nodename
);
827 ve
[2] = scm_makfrom0str (buf
.release
);
828 ve
[3] = scm_makfrom0str (buf
.version
);
829 ve
[4] = scm_makfrom0str (buf
.machine
);
832 ve[5] = scm_makfrom0str (buf.domainname);
837 scm_sysmissing (s_uname
);
843 SCM_PROC (s_environ
, "environ", 0, 1, 0, scm_environ
);
849 if (SCM_UNBNDP (env
))
850 return scm_makfromstrs (-1, environ
);
856 SCM_ASSERT (SCM_NULLP (env
) || (SCM_NIMP (env
) && SCM_CONSP (env
)),
857 env
, SCM_ARG1
, s_environ
);
858 num_strings
= scm_ilength (env
);
859 new_environ
= (char **) malloc ((num_strings
+ 1) * sizeof (char *));
860 if (new_environ
== NULL
)
861 scm_memory_error (s_environ
);
862 while (SCM_NNULLP (env
))
866 SCM_ASSERT (SCM_NIMP (SCM_CAR (env
))
867 && SCM_ROSTRINGP (SCM_CAR (env
)),
868 env
, SCM_ARG1
, s_environ
);
869 len
= 1 + SCM_ROLENGTH (SCM_CAR (env
));
870 new_environ
[i
] = malloc ((long) len
);
871 if (new_environ
[i
] == NULL
)
872 scm_memory_error (s_environ
);
873 src
= SCM_ROCHARS (SCM_CAR (env
));
875 new_environ
[i
][len
] = src
[len
];
880 /* Free the old environment, except when called for the first
885 static int first
= 1;
888 for (ep
= environ
; *ep
!= NULL
; ep
++)
890 free ((char *) environ
);
894 environ
= new_environ
;
895 return SCM_UNSPECIFIED
;
901 SCM_PROC (s_tmpnam
, "tmpnam", 0, 0, 0, scm_tmpnam
);
906 SCM_SYSCALL (tmpnam (name
););
907 return scm_makfrom0str (name
);
911 SCM_PROC (s_open_pipe
, "open-pipe", 2, 0, 0, scm_open_pipe
);
914 scm_open_pipe (pipestr
, modes
)
920 struct scm_port_table
* pt
;
922 SCM_ASSERT (SCM_NIMP (pipestr
) && SCM_ROSTRINGP (pipestr
), pipestr
,
923 SCM_ARG1
, s_open_pipe
);
924 if (SCM_SUBSTRP (pipestr
))
925 pipestr
= scm_makfromstr (SCM_ROCHARS (pipestr
),
926 SCM_ROLENGTH (pipestr
), 0);
927 SCM_ASSERT (SCM_NIMP (modes
) && SCM_ROSTRINGP (modes
), modes
, SCM_ARG2
,
929 if (SCM_SUBSTRP (modes
))
930 modes
= scm_makfromstr (SCM_ROCHARS (modes
), SCM_ROLENGTH (modes
), 0);
933 scm_ignore_signals ();
934 SCM_SYSCALL (f
= popen (SCM_ROCHARS (pipestr
), SCM_ROCHARS (modes
)));
935 scm_unignore_signals ();
937 scm_syserror (s_open_pipe
);
938 pt
= scm_add_to_port_table (z
);
939 SCM_SETPTAB_ENTRY (z
, pt
);
940 SCM_SETCAR (z
, scm_tc16_pipe
| SCM_OPN
941 | (strchr (SCM_ROCHARS (modes
), 'r') ? SCM_RDNG
: SCM_WRTNG
));
942 SCM_SETSTREAM (z
, (SCM
)f
);
947 SCM_PROC (s_close_pipe
, "close-pipe", 1, 0, 0, scm_close_pipe
);
950 scm_close_pipe (port
)
955 SCM_ASSERT (SCM_NIMP (port
) && SCM_TYP16(port
) == scm_tc16_pipe
956 && SCM_OPENP (port
), port
, SCM_ARG1
, s_close_pipe
);
958 rv
= pclose ((FILE *) SCM_STREAM (port
));
960 scm_syserror (s_close_pipe
);
962 return SCM_MAKINUM (rv
);
965 SCM_PROC (s_utime
, "utime", 1, 2, 0, scm_utime
);
968 scm_utime (pathname
, actime
, modtime
)
974 struct utimbuf utm_tmp
;
976 SCM_ASSERT (SCM_NIMP (pathname
) && SCM_ROSTRINGP (pathname
), pathname
,
979 SCM_COERCE_SUBSTR (pathname
);
980 if (SCM_UNBNDP (actime
))
981 SCM_SYSCALL (time (&utm_tmp
.actime
));
983 utm_tmp
.actime
= scm_num2ulong (actime
, (char *) SCM_ARG2
, s_utime
);
985 if (SCM_UNBNDP (modtime
))
986 SCM_SYSCALL (time (&utm_tmp
.modtime
));
988 utm_tmp
.modtime
= scm_num2ulong (modtime
, (char *) SCM_ARG3
, s_utime
);
990 SCM_SYSCALL (rv
= utime (SCM_ROCHARS (pathname
), &utm_tmp
));
992 scm_syserror (s_utime
);
993 return SCM_UNSPECIFIED
;
996 SCM_PROC (s_access
, "access?", 2, 0, 0, scm_access
);
999 scm_access (path
, how
)
1005 SCM_ASSERT (SCM_NIMP (path
) && SCM_ROSTRINGP (path
), path
, SCM_ARG1
,
1007 if (SCM_SUBSTRP (path
))
1008 path
= scm_makfromstr (SCM_ROCHARS (path
), SCM_ROLENGTH (path
), 0);
1009 SCM_ASSERT (SCM_INUMP (how
), how
, SCM_ARG2
, s_access
);
1010 rv
= access (SCM_ROCHARS (path
), SCM_INUM (how
));
1011 return rv
? SCM_BOOL_F
: SCM_BOOL_T
;
1014 SCM_PROC (s_getpid
, "getpid", 0, 0, 0, scm_getpid
);
1019 return SCM_MAKINUM ((unsigned long) getpid ());
1022 SCM_PROC (s_putenv
, "putenv", 1, 0, 0, scm_putenv
);
1031 SCM_ASSERT (SCM_NIMP (str
) && SCM_ROSTRINGP (str
), str
, SCM_ARG1
, s_putenv
);
1032 /* must make a new copy to be left in the environment, safe from gc. */
1033 ptr
= malloc (SCM_LENGTH (str
) + 1);
1035 scm_memory_error (s_putenv
);
1036 strncpy (ptr
, SCM_ROCHARS (str
), SCM_LENGTH (str
));
1037 ptr
[SCM_LENGTH(str
)] = 0;
1040 scm_syserror (s_putenv
);
1041 return SCM_UNSPECIFIED
;
1044 SCM_PROC (s_setlocale
, "setlocale", 1, 1, 0, scm_setlocale
);
1047 scm_setlocale (category
, locale
)
1051 #ifdef HAVE_SETLOCALE
1055 SCM_ASSERT (SCM_INUMP (category
), category
, SCM_ARG1
, s_setlocale
);
1056 if (SCM_UNBNDP (locale
))
1062 SCM_ASSERT (SCM_NIMP (locale
) && SCM_ROSTRINGP (locale
), locale
,
1063 SCM_ARG2
, s_setlocale
);
1064 SCM_COERCE_SUBSTR (locale
);
1065 clocale
= SCM_ROCHARS (locale
);
1068 rv
= setlocale (SCM_INUM (category
), clocale
);
1070 scm_syserror (s_setlocale
);
1071 return scm_makfrom0str (rv
);
1073 scm_sysmissing (s_setlocale
);
1079 SCM_PROC (s_mknod
, "mknod", 4, 0, 0, scm_mknod
);
1082 scm_mknod(path
, type
, perms
, dev
)
1093 SCM_ASSERT (SCM_NIMP(path
) && SCM_ROSTRINGP(path
), path
, SCM_ARG1
, s_mknod
);
1094 SCM_ASSERT (SCM_NIMP(type
) && SCM_SYMBOLP (type
), type
, SCM_ARG2
, s_mknod
);
1095 SCM_ASSERT (SCM_INUMP (perms
), perms
, SCM_ARG3
, s_mknod
);
1096 SCM_ASSERT (SCM_INUMP(dev
), dev
, SCM_ARG4
, s_mknod
);
1097 SCM_COERCE_SUBSTR (path
);
1099 p
= SCM_CHARS (type
);
1100 if (strcmp (p
, "regular") == 0)
1102 else if (strcmp (p
, "directory") == 0)
1104 else if (strcmp (p
, "symlink") == 0)
1106 else if (strcmp (p
, "block-special") == 0)
1108 else if (strcmp (p
, "char-special") == 0)
1110 else if (strcmp (p
, "fifo") == 0)
1112 else if (strcmp (p
, "socket") == 0)
1115 scm_out_of_range (s_mknod
, type
);
1118 SCM_SYSCALL (val
= mknod(SCM_ROCHARS(path
), ctype
| SCM_INUM (perms
),
1121 scm_syserror (s_mknod
);
1123 return SCM_UNSPECIFIED
;
1125 scm_sysmissing (s_mknod
);
1132 SCM_PROC (s_nice
, "nice", 1, 0, 0, scm_nice
);
1139 SCM_ASSERT(SCM_INUMP(incr
), incr
, SCM_ARG1
, s_nice
);
1140 if (nice(SCM_INUM(incr
)) != 0)
1141 scm_syserror (s_nice
);
1142 return SCM_UNSPECIFIED
;
1144 scm_sysmissing (s_nice
);
1151 SCM_PROC (s_sync
, "sync", 0, 0, 0, scm_sync
);
1159 scm_sysmissing (s_sync
);
1171 scm_add_feature ("posix");
1173 scm_add_feature ("EIDs");
1176 scm_sysintern ("WAIT_ANY", SCM_MAKINUM (WAIT_ANY
));
1179 scm_sysintern ("WAIT_MYPGRP", SCM_MAKINUM (WAIT_MYPGRP
));
1182 scm_sysintern ("WNOHANG", SCM_MAKINUM (WNOHANG
));
1185 scm_sysintern ("WUNTRACED", SCM_MAKINUM (WUNTRACED
));
1188 /* access() symbols. */
1189 scm_sysintern ("R_OK", SCM_MAKINUM (R_OK
));
1190 scm_sysintern ("W_OK", SCM_MAKINUM (W_OK
));
1191 scm_sysintern ("X_OK", SCM_MAKINUM (X_OK
));
1192 scm_sysintern ("F_OK", SCM_MAKINUM (F_OK
));
1195 scm_sysintern ("LC_COLLATE", SCM_MAKINUM (LC_COLLATE
));
1198 scm_sysintern ("LC_CTYPE", SCM_MAKINUM (LC_CTYPE
));
1201 scm_sysintern ("LC_MONETARY", SCM_MAKINUM (LC_MONETARY
));
1204 scm_sysintern ("LC_NUMERIC", SCM_MAKINUM (LC_NUMERIC
));
1207 scm_sysintern ("LC_TIME", SCM_MAKINUM (LC_TIME
));
1210 scm_sysintern ("LC_MESSAGES", SCM_MAKINUM (LC_MESSAGES
));
1213 scm_sysintern ("LC_ALL", SCM_MAKINUM (LC_ALL
));
1215 #include "cpp_sig_symbols.c"