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.
48 #include "sequences.h"
56 #ifdef TIME_WITH_SYS_TIME
57 # include <sys/time.h>
61 # include <sys/time.h>
71 extern char *ttyname();
75 #ifdef LIBC_H_WITH_UNISTD_H
79 #ifdef HAVE_SYS_SELECT_H
80 #include <sys/select.h>
83 #include <sys/types.h>
90 # include <sys/wait.h>
93 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
96 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
103 #define SELECT_TYPE fd_set
104 #define SELECT_SET_SIZE FD_SETSIZE
106 #else /* no FD_SET */
108 /* Define the macros to access a single-int bitmap of descriptors. */
109 #define SELECT_SET_SIZE 32
110 #define SELECT_TYPE int
111 #define FD_SET(n, p) (*(p) |= (1 << (n)))
112 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
113 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
114 #define FD_ZERO(p) (*(p) = 0)
116 #endif /* no FD_SET */
118 extern FILE *popen ();
119 extern char ** environ
;
122 #include <sys/utsname.h>
126 # define NAMLEN(dirent) strlen((dirent)->d_name)
128 # define dirent direct
129 # define NAMLEN(dirent) (dirent)->d_namlen
131 # include <sys/ndir.h>
134 # include <sys/dir.h>
143 #ifdef HAVE_SETLOCALE
147 /* Some Unix systems don't define these. CPP hair is dangerous, but
148 this seems safe enough... */
165 /* On NextStep, <utime.h> doesn't define struct utime, unless we
166 #define _POSIX_SOURCE before #including it. I think this is less
167 of a kludge than defining struct utimbuf ourselves. */
168 #ifdef UTIMBUF_NEEDS_POSIX
169 #define _POSIX_SOURCE
172 #ifdef HAVE_SYS_UTIME_H
173 #include <sys/utime.h>
180 /* Please don't add any more #includes or #defines here. The hack
181 above means that _POSIX_SOURCE may be #defined, which will
182 encourage header files to do strange things. */
187 SCM_PROC (s_pipe
, "pipe", 0, 0, 0, scm_pipe
);
195 struct scm_port_table
* ptr
;
196 struct scm_port_table
* ptw
;
202 scm_syserror (s_pipe
);
203 f_rd
= fdopen (fd
[0], "r");
206 SCM_SYSCALL (close (fd
[0]));
207 SCM_SYSCALL (close (fd
[1]));
208 scm_syserror (s_pipe
);
210 f_wt
= fdopen (fd
[1], "w");
216 SCM_SYSCALL (close (fd
[1]));
218 scm_syserror (s_pipe
);
220 ptr
= scm_add_to_port_table (p_rd
);
221 ptw
= scm_add_to_port_table (p_wt
);
222 SCM_SETPTAB_ENTRY (p_rd
, ptr
);
223 SCM_SETPTAB_ENTRY (p_wt
, ptw
);
224 SCM_SETCAR (p_rd
, scm_tc16_fport
| scm_mode_bits ("r"));
225 SCM_SETCAR (p_wt
, scm_tc16_fport
| scm_mode_bits ("w"));
226 SCM_SETSTREAM (p_rd
, (SCM
)f_rd
);
227 SCM_SETSTREAM (p_wt
, (SCM
)f_wt
);
230 return scm_cons (p_rd
, p_wt
);
235 SCM_PROC (s_getgroups
, "getgroups", 0, 0, 0, scm_getgroups
);
241 int ngroups
= getgroups (0, NULL
);
243 scm_syserror (s_getgroups
);
250 groups
= (GETGROUPS_T
*) scm_must_malloc(ngroups
* sizeof(GETGROUPS_T
),
252 val
= getgroups(ngroups
, groups
);
255 scm_must_free((char *)groups
);
256 scm_syserror (s_getgroups
);
258 SCM_SETCHARS(grps
, groups
); /* set up grps as a GC protect */
259 SCM_SETLENGTH(grps
, 0L + ngroups
* sizeof(GETGROUPS_T
), scm_tc7_string
);
261 ans
= scm_make_vector(SCM_MAKINUM(ngroups
), SCM_UNDEFINED
, SCM_BOOL_F
);
262 while (--ngroups
>= 0) SCM_VELTS(ans
)[ngroups
] = SCM_MAKINUM(groups
[ngroups
]);
263 SCM_SETCHARS(grps
, groups
); /* to make sure grps stays around. */
270 SCM_PROC (s_getpwuid
, "getpw", 0, 1, 0, scm_getpwuid
);
277 struct passwd
*entry
;
280 result
= scm_make_vector (SCM_MAKINUM (7), SCM_UNSPECIFIED
, SCM_BOOL_F
);
281 ve
= SCM_VELTS (result
);
282 if (SCM_UNBNDP (user
) || SCM_FALSEP (user
))
285 SCM_SYSCALL (entry
= getpwent ());
287 else if (SCM_INUMP (user
))
290 entry
= getpwuid (SCM_INUM (user
));
294 SCM_ASSERT (SCM_NIMP (user
) && SCM_ROSTRINGP (user
), user
, SCM_ARG1
, s_getpwuid
);
295 if (SCM_SUBSTRP (user
))
296 user
= scm_makfromstr (SCM_ROCHARS (user
), SCM_ROLENGTH (user
), 0);
298 entry
= getpwnam (SCM_ROCHARS (user
));
301 scm_syserror (s_getpwuid
);
303 ve
[0] = scm_makfrom0str (entry
->pw_name
);
304 ve
[1] = scm_makfrom0str (entry
->pw_passwd
);
305 ve
[2] = scm_ulong2num ((unsigned long) entry
->pw_uid
);
306 ve
[3] = scm_ulong2num ((unsigned long) entry
->pw_gid
);
307 ve
[4] = scm_makfrom0str (entry
->pw_gecos
);
309 ve
[5] = scm_makfrom0str ("");
311 ve
[5] = scm_makfrom0str (entry
->pw_dir
);
312 if (!entry
->pw_shell
)
313 ve
[6] = scm_makfrom0str ("");
315 ve
[6] = scm_makfrom0str (entry
->pw_shell
);
322 SCM_PROC (s_setpwent
, "setpw", 0, 1, 0, scm_setpwent
);
328 if (SCM_UNBNDP (arg
) || SCM_FALSEP (arg
))
332 return SCM_UNSPECIFIED
;
337 /* Combines getgrgid and getgrnam. */
338 SCM_PROC (s_getgrgid
, "getgr", 0, 1, 0, scm_getgrgid
);
347 result
= scm_make_vector (SCM_MAKINUM (4), SCM_UNSPECIFIED
, SCM_BOOL_F
);
348 ve
= SCM_VELTS (result
);
350 if (SCM_UNBNDP (name
) || (name
== SCM_BOOL_F
))
351 SCM_SYSCALL (entry
= getgrent ());
352 else if (SCM_INUMP (name
))
353 SCM_SYSCALL (entry
= getgrgid (SCM_INUM (name
)));
356 SCM_ASSERT (SCM_NIMP (name
) && SCM_ROSTRINGP (name
), name
, SCM_ARG1
,
358 SCM_SYSCALL (entry
= getgrnam (SCM_ROCHARS (name
)));
361 scm_syserror (s_getgrgid
);
363 ve
[0] = scm_makfrom0str (entry
->gr_name
);
364 ve
[1] = scm_makfrom0str (entry
->gr_passwd
);
365 ve
[2] = scm_ulong2num ((unsigned long) entry
->gr_gid
);
366 ve
[3] = scm_makfromstrs (-1, entry
->gr_mem
);
373 SCM_PROC (s_setgrent
, "setgr", 0, 1, 0, scm_setgrent
);
379 if (SCM_UNBNDP (arg
) || SCM_FALSEP (arg
))
383 return SCM_UNSPECIFIED
;
388 SCM_PROC (s_kill
, "kill", 2, 0, 0, scm_kill
);
395 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_kill
);
396 SCM_ASSERT (SCM_INUMP (sig
), sig
, SCM_ARG2
, s_kill
);
397 /* Signal values are interned in scm_init_posix(). */
398 if (kill ((int) SCM_INUM (pid
), (int) SCM_INUM (sig
)) != 0)
399 scm_syserror (s_kill
);
400 return SCM_UNSPECIFIED
;
405 SCM_PROC (s_waitpid
, "waitpid", 1, 1, 0, scm_waitpid
);
408 scm_waitpid (pid
, options
)
416 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_waitpid
);
417 if (SCM_UNBNDP (options
))
421 SCM_ASSERT (SCM_INUMP (options
), options
, SCM_ARG2
, s_waitpid
);
422 /* Flags are interned in scm_init_posix. */
423 ioptions
= SCM_INUM (options
);
425 SCM_SYSCALL (i
= waitpid (SCM_INUM (pid
), &status
, ioptions
));
427 scm_syserror (s_waitpid
);
428 return scm_cons (SCM_MAKINUM (0L + i
), SCM_MAKINUM (0L + status
));
430 scm_sysmissing (s_waitpid
);
436 SCM_PROC (s_status_exit_val
, "status:exit-val", 1, 0, 0, scm_status_exit_val
);
438 scm_status_exit_val (status
)
441 SCM_ASSERT (SCM_INUMP (status
), status
, SCM_ARG1
,s_status_exit_val
);
442 if (WIFEXITED (SCM_INUM (status
)))
443 return (SCM_MAKINUM (WEXITSTATUS (SCM_INUM (status
))));
447 SCM_PROC (s_status_term_sig
, "status:term-sig", 1, 0, 0, scm_status_term_sig
);
449 scm_status_term_sig (status
)
452 SCM_ASSERT (SCM_INUMP (status
), status
, SCM_ARG1
,s_status_term_sig
);
453 if (WIFSIGNALED (SCM_INUM (status
)))
454 return SCM_MAKINUM (WTERMSIG (SCM_INUM (status
)));
459 SCM_PROC (s_status_stop_sig
, "status:stop-sig", 1, 0, 0, scm_status_stop_sig
);
461 scm_status_stop_sig (status
)
464 SCM_ASSERT (SCM_INUMP (status
), status
, SCM_ARG1
,s_status_stop_sig
);
465 if (WIFSTOPPED (SCM_INUM (status
)))
466 return SCM_MAKINUM (WSTOPSIG (SCM_INUM (status
)));
471 SCM_PROC (s_getppid
, "getppid", 0, 0, 0, scm_getppid
);
476 return SCM_MAKINUM (0L + getppid ());
481 SCM_PROC (s_getuid
, "getuid", 0, 0, 0, scm_getuid
);
486 return SCM_MAKINUM (0L + getuid ());
491 SCM_PROC (s_getgid
, "getgid", 0, 0, 0, scm_getgid
);
496 return SCM_MAKINUM (0L + getgid ());
501 SCM_PROC (s_geteuid
, "geteuid", 0, 0, 0, scm_geteuid
);
507 return SCM_MAKINUM (0L + geteuid ());
509 return SCM_MAKINUM (0L + getuid ());
515 SCM_PROC (s_getegid
, "getegid", 0, 0, 0, scm_getegid
);
521 return SCM_MAKINUM (0L + getegid ());
523 return SCM_MAKINUM (0L + getgid ());
528 SCM_PROC (s_setuid
, "setuid", 1, 0, 0, scm_setuid
);
534 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_setuid
);
535 if (setuid (SCM_INUM (id
)) != 0)
536 scm_syserror (s_setuid
);
537 return SCM_UNSPECIFIED
;
540 SCM_PROC (s_setgid
, "setgid", 1, 0, 0, scm_setgid
);
546 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_setgid
);
547 if (setgid (SCM_INUM (id
)) != 0)
548 scm_syserror (s_setgid
);
549 return SCM_UNSPECIFIED
;
552 SCM_PROC (s_seteuid
, "seteuid", 1, 0, 0, scm_seteuid
);
560 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_seteuid
);
562 rv
= seteuid (SCM_INUM (id
));
564 rv
= setuid (SCM_INUM (id
));
567 scm_syserror (s_seteuid
);
568 return SCM_UNSPECIFIED
;
571 SCM_PROC (s_setegid
, "setegid", 1, 0, 0, scm_setegid
);
579 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_setegid
);
581 rv
= setegid (SCM_INUM (id
));
583 rv
= setgid (SCM_INUM (id
));
586 scm_syserror (s_setegid
);
587 return SCM_UNSPECIFIED
;
591 SCM_PROC (s_getpgrp
, "getpgrp", 0, 0, 0, scm_getpgrp
);
596 fn
= (int (*) ()) getpgrp
;
597 return SCM_MAKINUM (fn (0));
600 SCM_PROC (s_setpgid
, "setpgid", 2, 0, 0, scm_setpgid
);
602 scm_setpgid (pid
, pgid
)
606 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_setpgid
);
607 SCM_ASSERT (SCM_INUMP (pgid
), pgid
, SCM_ARG2
, s_setpgid
);
608 /* FIXME(?): may be known as setpgrp. */
609 if (setpgid (SCM_INUM (pid
), SCM_INUM (pgid
)) != 0)
610 scm_syserror (s_setpgid
);
611 return SCM_UNSPECIFIED
;
613 scm_sysmissing (s_setpgid
);
619 SCM_PROC (s_setsid
, "setsid", 0, 0, 0, scm_setsid
);
624 pid_t sid
= setsid ();
626 scm_syserror (s_setsid
);
627 return SCM_UNSPECIFIED
;
629 scm_sysmissing (s_setsid
);
635 SCM_PROC (s_ttyname
, "ttyname", 1, 0, 0, scm_ttyname
);
643 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPPORTP (port
), port
, SCM_ARG1
, s_ttyname
);
644 if (scm_tc16_fport
!= SCM_TYP16 (port
))
646 fd
= fileno ((FILE *)SCM_STREAM (port
));
648 scm_syserror (s_ttyname
);
649 SCM_SYSCALL (ans
= ttyname (fd
));
651 scm_syserror (s_ttyname
);
652 /* ans could be overwritten by another call to ttyname */
653 return (scm_makfrom0str (ans
));
657 SCM_PROC (s_ctermid
, "ctermid", 0, 0, 0, scm_ctermid
);
662 char *result
= ctermid (NULL
);
664 scm_syserror (s_ctermid
);
665 return scm_makfrom0str (result
);
667 scm_sysmissing (s_ctermid
);
673 SCM_PROC (s_tcgetpgrp
, "tcgetpgrp", 1, 0, 0, scm_tcgetpgrp
);
678 #ifdef HAVE_TCGETPGRP
681 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPFPORTP (port
), port
, SCM_ARG1
, s_tcgetpgrp
);
682 fd
= fileno ((FILE *)SCM_STREAM (port
));
683 if (fd
== -1 || (pgid
= tcgetpgrp (fd
)) == -1)
684 scm_syserror (s_tcgetpgrp
);
685 return SCM_MAKINUM (pgid
);
687 scm_sysmissing (s_tcgetpgrp
);
693 SCM_PROC (s_tcsetpgrp
, "tcsetpgrp", 2, 0, 0, scm_tcsetpgrp
);
695 scm_tcsetpgrp (port
, pgid
)
698 #ifdef HAVE_TCSETPGRP
700 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPFPORTP (port
), port
, SCM_ARG1
, s_tcsetpgrp
);
701 SCM_ASSERT (SCM_INUMP (pgid
), pgid
, SCM_ARG2
, s_tcsetpgrp
);
702 fd
= fileno ((FILE *)SCM_STREAM (port
));
703 if (fd
== -1 || tcsetpgrp (fd
, SCM_INUM (pgid
)) == -1)
704 scm_syserror (s_tcsetpgrp
);
705 return SCM_UNSPECIFIED
;
707 scm_sysmissing (s_tcsetpgrp
);
713 /* Copy exec args from an SCM vector into a new C array. */
715 static char ** scm_convert_exec_args
SCM_P ((SCM args
));
718 scm_convert_exec_args (args
)
725 num_args
= scm_ilength (args
);
727 scm_must_malloc ((num_args
+ 1) * sizeof (char *), s_ttyname
);
728 for (i
= 0; SCM_NNULLP (args
); args
= SCM_CDR (args
), ++i
)
733 SCM_ASSERT (SCM_NIMP (SCM_CAR (args
)) && SCM_ROSTRINGP (SCM_CAR (args
)),
734 SCM_CAR (args
), "wrong type in SCM_ARG", "exec arg");
735 len
= 1 + SCM_ROLENGTH (SCM_CAR (args
));
736 dst
= (char *) scm_must_malloc ((long) len
, s_ttyname
);
737 src
= SCM_ROCHARS (SCM_CAR (args
));
747 SCM_PROC (s_execl
, "execl", 0, 0, 1, scm_execl
);
754 SCM filename
= SCM_CAR (args
);
755 SCM_ASSERT (SCM_NIMP (filename
) && SCM_ROSTRINGP (filename
), filename
, SCM_ARG1
, s_execl
);
756 if (SCM_SUBSTRP (filename
))
757 filename
= scm_makfromstr (SCM_ROCHARS (filename
), SCM_ROLENGTH (filename
), 0);
758 args
= SCM_CDR (args
);
759 execargv
= scm_convert_exec_args (args
);
760 execv (SCM_ROCHARS (filename
), execargv
);
761 scm_syserror (s_execl
);
766 SCM_PROC (s_execlp
, "execlp", 0, 0, 1, scm_execlp
);
773 SCM filename
= SCM_CAR (args
);
774 SCM_ASSERT (SCM_NIMP (filename
) && SCM_ROSTRINGP (filename
), filename
,
776 if (SCM_SUBSTRP (filename
))
777 filename
= scm_makfromstr (SCM_ROCHARS (filename
),
778 SCM_ROLENGTH (filename
), 0);
779 args
= SCM_CDR (args
);
780 execargv
= scm_convert_exec_args (args
);
781 execvp (SCM_ROCHARS (filename
), execargv
);
782 scm_syserror (s_execlp
);
787 SCM_PROC (s_fork
, "primitive-fork", 0, 0, 0, scm_fork
);
795 scm_syserror (s_fork
);
796 return SCM_MAKINUM (0L+pid
);
800 SCM_PROC (s_uname
, "uname", 0, 0, 0, scm_uname
);
807 SCM ans
= scm_make_vector(SCM_MAKINUM(5), SCM_UNSPECIFIED
, SCM_BOOL_F
);
808 SCM
*ve
= SCM_VELTS (ans
);
811 scm_syserror (s_uname
);
812 ve
[0] = scm_makfrom0str (buf
.sysname
);
813 ve
[1] = scm_makfrom0str (buf
.nodename
);
814 ve
[2] = scm_makfrom0str (buf
.release
);
815 ve
[3] = scm_makfrom0str (buf
.version
);
816 ve
[4] = scm_makfrom0str (buf
.machine
);
819 ve[5] = scm_makfrom0str (buf.domainname);
824 scm_sysmissing (s_uname
);
830 SCM_PROC (s_environ
, "environ", 0, 1, 0, scm_environ
);
836 if (SCM_UNBNDP (env
))
837 return scm_makfromstrs (-1, environ
);
843 SCM_ASSERT (SCM_NULLP (env
) || (SCM_NIMP (env
) && SCM_CONSP (env
)),
844 env
, SCM_ARG1
, s_environ
);
845 num_strings
= scm_ilength (env
);
846 new_environ
= (char **) scm_must_malloc ((num_strings
+ 1)
849 while (SCM_NNULLP (env
))
853 SCM_ASSERT (SCM_NIMP (SCM_CAR (env
))
854 && SCM_ROSTRINGP (SCM_CAR (env
)),
855 env
, SCM_ARG1
, s_environ
);
856 len
= 1 + SCM_ROLENGTH (SCM_CAR (env
));
857 new_environ
[i
] = scm_must_malloc ((long) len
, s_environ
);
858 src
= SCM_ROCHARS (SCM_CAR (env
));
860 new_environ
[i
][len
] = src
[len
];
865 /* Free the old environment, except when called for the first
870 static int first
= 1;
873 for (ep
= environ
; *ep
!= NULL
; ep
++)
875 scm_must_free ((char *) environ
);
879 environ
= new_environ
;
880 return SCM_UNSPECIFIED
;
886 SCM_PROC (s_tmpnam
, "tmpnam", 0, 0, 0, scm_tmpnam
);
891 SCM_SYSCALL (tmpnam (name
););
892 return scm_makfrom0str (name
);
896 SCM_PROC (s_open_pipe
, "open-pipe", 2, 0, 0, scm_open_pipe
);
899 scm_open_pipe (pipestr
, modes
)
905 struct scm_port_table
* pt
;
907 SCM_ASSERT (SCM_NIMP (pipestr
) && SCM_ROSTRINGP (pipestr
), pipestr
,
908 SCM_ARG1
, s_open_pipe
);
909 if (SCM_SUBSTRP (pipestr
))
910 pipestr
= scm_makfromstr (SCM_ROCHARS (pipestr
),
911 SCM_ROLENGTH (pipestr
), 0);
912 SCM_ASSERT (SCM_NIMP (modes
) && SCM_ROSTRINGP (modes
), modes
, SCM_ARG2
,
914 if (SCM_SUBSTRP (modes
))
915 modes
= scm_makfromstr (SCM_ROCHARS (modes
), SCM_ROLENGTH (modes
), 0);
918 scm_ignore_signals ();
919 SCM_SYSCALL (f
= popen (SCM_ROCHARS (pipestr
), SCM_ROCHARS (modes
)));
920 scm_unignore_signals ();
922 scm_syserror (s_open_pipe
);
923 pt
= scm_add_to_port_table (z
);
924 SCM_SETPTAB_ENTRY (z
, pt
);
925 SCM_SETCAR (z
, scm_tc16_pipe
| SCM_OPN
926 | (strchr (SCM_ROCHARS (modes
), 'r') ? SCM_RDNG
: SCM_WRTNG
));
927 SCM_SETSTREAM (z
, (SCM
)f
);
933 SCM_PROC (s_open_input_pipe
, "open-input-pipe", 1, 0, 0, scm_open_input_pipe
);
936 scm_open_input_pipe(pipestr
)
939 return scm_open_pipe(pipestr
, scm_makfromstr("r", (sizeof "r")-1, 0));
942 SCM_PROC (s_open_output_pipe
, "open-output-pipe", 1, 0, 0, scm_open_output_pipe
);
945 scm_open_output_pipe(pipestr
)
948 return scm_open_pipe(pipestr
, scm_makfromstr("w", (sizeof "w")-1, 0));
952 SCM_PROC (s_utime
, "utime", 1, 2, 0, scm_utime
);
955 scm_utime (pathname
, actime
, modtime
)
961 struct utimbuf utm_tmp
;
963 SCM_ASSERT (SCM_NIMP (pathname
) && SCM_STRINGP (pathname
), pathname
,
966 if (SCM_UNBNDP (actime
))
967 SCM_SYSCALL (time (&utm_tmp
.actime
));
969 utm_tmp
.actime
= scm_num2ulong (actime
, (char *) SCM_ARG2
, s_utime
);
971 if (SCM_UNBNDP (modtime
))
972 SCM_SYSCALL (time (&utm_tmp
.modtime
));
974 utm_tmp
.modtime
= scm_num2ulong (modtime
, (char *) SCM_ARG3
, s_utime
);
976 SCM_SYSCALL (rv
= utime (SCM_CHARS (pathname
), &utm_tmp
));
978 scm_syserror (s_utime
);
979 return SCM_UNSPECIFIED
;
982 SCM_PROC (s_access
, "access?", 2, 0, 0, scm_access
);
985 scm_access (path
, how
)
991 SCM_ASSERT (SCM_NIMP (path
) && SCM_ROSTRINGP (path
), path
, SCM_ARG1
,
993 if (SCM_SUBSTRP (path
))
994 path
= scm_makfromstr (SCM_ROCHARS (path
), SCM_ROLENGTH (path
), 0);
995 SCM_ASSERT (SCM_INUMP (how
), how
, SCM_ARG2
, s_access
);
996 rv
= access (SCM_ROCHARS (path
), SCM_INUM (how
));
997 return rv
? SCM_BOOL_F
: SCM_BOOL_T
;
1000 SCM_PROC (s_getpid
, "getpid", 0, 0, 0, scm_getpid
);
1005 return SCM_MAKINUM ((unsigned long) getpid ());
1008 SCM_PROC (s_putenv
, "putenv", 1, 0, 0, scm_putenv
);
1017 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_putenv
);
1018 rv
= putenv (SCM_CHARS (str
));
1020 scm_syserror (s_putenv
);
1021 return SCM_UNSPECIFIED
;
1023 scm_sysmissing (s_putenv
);
1029 SCM_PROC (s_setlocale
, "setlocale", 1, 1, 0, scm_setlocale
);
1032 scm_setlocale (category
, locale
)
1036 #ifdef HAVE_SETLOCALE
1040 SCM_ASSERT (SCM_INUMP (category
), category
, SCM_ARG1
, s_setlocale
);
1041 if (SCM_UNBNDP (locale
))
1047 SCM_ASSERT (SCM_NIMP (locale
) && SCM_STRINGP (locale
), locale
,
1048 SCM_ARG2
, s_setlocale
);
1049 clocale
= SCM_CHARS (locale
);
1052 rv
= setlocale (SCM_INUM (category
), clocale
);
1054 scm_syserror (s_setlocale
);
1055 return scm_makfrom0str (rv
);
1057 scm_sysmissing (s_setlocale
);
1063 SCM_PROC (s_strftime
, "strftime", 2, 0, 0, scm_strftime
);
1066 scm_strftime (format
, stime
)
1078 SCM_ASSERT (SCM_NIMP (format
) && SCM_STRINGP (format
), format
, SCM_ARG1
,
1080 SCM_ASSERT (SCM_NIMP (stime
) && SCM_VECTORP (stime
)
1081 && scm_obj_length (stime
) == 9,
1082 stime
, SCM_ARG2
, s_strftime
);
1084 fmt
= SCM_ROCHARS (format
);
1085 len
= SCM_ROLENGTH (format
);
1087 #define tm_deref scm_num2long (SCM_VELTS (stime)[n++], (char *)SCM_ARG2, s_strftime)
1089 t
.tm_sec
= tm_deref
;
1090 t
.tm_min
= tm_deref
;
1091 t
.tm_hour
= tm_deref
;
1092 t
.tm_mday
= tm_deref
;
1093 t
.tm_mon
= tm_deref
;
1094 t
.tm_year
= tm_deref
;
1095 /* not used by mktime.
1096 t.tm_wday = tm_deref;
1097 t.tm_yday = tm_deref; */
1098 t
.tm_isdst
= tm_deref
;
1101 /* fill in missing fields and set the timezone. */
1104 tbuf
= scm_must_malloc (size
, s_strftime
);
1105 while ((len
= strftime (tbuf
, size
, fmt
, &t
)) == size
)
1107 scm_must_free (tbuf
);
1109 tbuf
= scm_must_malloc (size
, s_strftime
);
1111 return scm_makfromstr (tbuf
, len
, 0);
1114 SCM_PROC (s_strptime
, "strptime", 2, 0, 0, scm_strptime
);
1117 scm_strptime (format
, string
)
1121 #ifdef HAVE_STRPTIME
1125 char *fmt
, *str
, *rest
;
1128 SCM_ASSERT (SCM_NIMP (format
) && SCM_ROSTRINGP (format
), format
, SCM_ARG1
,
1130 if (SCM_SUBSTRP (format
))
1131 format
= scm_makfromstr (SCM_ROCHARS (format
), SCM_ROLENGTH (format
), 0);
1132 SCM_ASSERT (SCM_NIMP (string
) && SCM_ROSTRINGP (string
), string
, SCM_ARG2
,
1134 if (SCM_SUBSTRP (string
))
1135 string
= scm_makfromstr (SCM_ROCHARS (string
), SCM_ROLENGTH (string
), 0);
1137 fmt
= SCM_CHARS (format
);
1138 str
= SCM_CHARS (string
);
1140 /* initialize the struct tm */
1141 #define tm_init(field) t.field = 0
1154 rest
= strptime (str
, fmt
, &t
);
1158 scm_syserror (s_strptime
);
1160 stime
= scm_make_vector (SCM_MAKINUM (9), scm_long2num (0), SCM_UNDEFINED
);
1162 #define stime_set(val) scm_vector_set_x (stime, SCM_MAKINUM (n++), scm_long2num (t.val));
1166 stime_set (tm_hour
);
1167 stime_set (tm_mday
);
1169 stime_set (tm_year
);
1170 stime_set (tm_wday
);
1171 stime_set (tm_yday
);
1172 stime_set (tm_isdst
);
1175 return scm_cons (stime
, scm_makfrom0str (rest
));
1177 scm_sysmissing (s_strptime
);
1183 SCM_PROC (s_mknod
, "mknod", 3, 0, 0, scm_mknod
);
1186 scm_mknod(path
, mode
, dev
)
1193 SCM_ASSERT(SCM_NIMP(path
) && SCM_ROSTRINGP(path
), path
, SCM_ARG1
, s_mknod
);
1194 SCM_ASSERT(SCM_INUMP(mode
), mode
, SCM_ARG2
, s_mknod
);
1195 SCM_ASSERT(SCM_INUMP(dev
), dev
, SCM_ARG3
, s_mknod
);
1196 SCM_SYSCALL(val
= mknod(SCM_ROCHARS(path
), SCM_INUM(mode
), SCM_INUM(dev
)));
1198 scm_syserror (s_mknod
);
1199 return SCM_UNSPECIFIED
;
1201 scm_sysmissing (s_mknod
);
1208 SCM_PROC (s_nice
, "nice", 1, 0, 0, scm_nice
);
1215 SCM_ASSERT(SCM_INUMP(incr
), incr
, SCM_ARG1
, s_nice
);
1216 if (nice(SCM_INUM(incr
)) != 0)
1217 scm_syserror (s_nice
);
1218 return SCM_UNSPECIFIED
;
1220 scm_sysmissing (s_nice
);
1227 SCM_PROC (s_sync
, "sync", 0, 0, 0, scm_sync
);
1235 scm_sysmissing (s_sync
);
1247 scm_add_feature ("posix");
1249 scm_add_feature ("EIDs");
1252 scm_sysintern ("WAIT_ANY", SCM_MAKINUM (WAIT_ANY
));
1255 scm_sysintern ("WAIT_MYPGRP", SCM_MAKINUM (WAIT_MYPGRP
));
1258 scm_sysintern ("WNOHANG", SCM_MAKINUM (WNOHANG
));
1261 scm_sysintern ("WUNTRACED", SCM_MAKINUM (WUNTRACED
));
1264 /* access() symbols. */
1265 scm_sysintern ("R_OK", SCM_MAKINUM (R_OK
));
1266 scm_sysintern ("W_OK", SCM_MAKINUM (W_OK
));
1267 scm_sysintern ("X_OK", SCM_MAKINUM (X_OK
));
1268 scm_sysintern ("F_OK", SCM_MAKINUM (F_OK
));
1271 scm_sysintern ("LC_COLLATE", SCM_MAKINUM (LC_COLLATE
));
1274 scm_sysintern ("LC_CTYPE", SCM_MAKINUM (LC_CTYPE
));
1277 scm_sysintern ("LC_MONETARY", SCM_MAKINUM (LC_MONETARY
));
1280 scm_sysintern ("LC_NUMERIC", SCM_MAKINUM (LC_NUMERIC
));
1283 scm_sysintern ("LC_TIME", SCM_MAKINUM (LC_TIME
));
1286 scm_sysintern ("LC_MESSAGES", SCM_MAKINUM (LC_MESSAGES
));
1289 scm_sysintern ("LC_ALL", SCM_MAKINUM (LC_ALL
));
1291 #include "cpp_sig_symbols.c"