1 /* Copyright (C) 1995, 1996 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.
51 #ifdef TIME_WITH_SYS_TIME
52 # include <sys/time.h>
56 # include <sys/time.h>
66 #ifdef HAVE_SYS_SELECT_H
67 #include <sys/select.h>
70 #include <sys/types.h>
77 # include <sys/wait.h>
80 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
83 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
90 #define SELECT_TYPE fd_set
91 #define SELECT_SET_SIZE FD_SETSIZE
95 /* Define the macros to access a single-int bitmap of descriptors. */
96 #define SELECT_SET_SIZE 32
97 #define SELECT_TYPE int
98 #define FD_SET(n, p) (*(p) |= (1 << (n)))
99 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
100 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
101 #define FD_ZERO(p) (*(p) = 0)
103 #endif /* no FD_SET */
105 extern char *ttyname ();
106 extern FILE *popen ();
107 extern char ** environ
;
110 #include <sys/utsname.h>
114 # define NAMLEN(dirent) strlen((dirent)->d_name)
116 # define dirent direct
117 # define NAMLEN(dirent) (dirent)->d_namlen
119 # include <sys/ndir.h>
122 # include <sys/dir.h>
131 #ifdef HAVE_SETLOCALE
139 SCM_PROC (s_sys_pipe
, "pipe", 0, 0, 0, scm_sys_pipe
);
151 struct scm_port_table
* ptr
;
152 struct scm_port_table
* ptw
;
158 SCM_SYSERROR (s_sys_pipe
);
159 f_rd
= fdopen (fd
[0], "r");
162 SCM_SYSCALL (close (fd
[0]));
163 SCM_SYSCALL (close (fd
[1]));
164 SCM_SYSERROR (s_sys_pipe
);
166 f_wt
= fdopen (fd
[1], "w");
172 SCM_SYSCALL (close (fd
[1]));
174 SCM_SYSERROR (s_sys_pipe
);
176 ptr
= scm_add_to_port_table (p_rd
);
177 ptw
= scm_add_to_port_table (p_wt
);
178 SCM_SETPTAB_ENTRY (p_rd
, ptr
);
179 SCM_SETPTAB_ENTRY (p_wt
, ptw
);
180 SCM_CAR (p_rd
) = scm_tc16_fport
| scm_mode_bits ("r");
181 SCM_CAR (p_wt
) = scm_tc16_fport
| scm_mode_bits ("w");
182 SCM_SETSTREAM (p_rd
, (SCM
)f_rd
);
183 SCM_SETSTREAM (p_wt
, (SCM
)f_wt
);
186 return scm_cons (p_rd
, p_wt
);
191 SCM_PROC (s_sys_getgroups
, "getgroups", 0, 0, 0, scm_sys_getgroups
);
194 scm_sys_getgroups(void)
201 int ngroups
= getgroups (0, NULL
);
203 SCM_SYSERROR (s_sys_getgroups
);
210 groups
= (gid_t
*)scm_must_malloc(ngroups
* sizeof(GETGROUPS_T
),
212 val
= getgroups(ngroups
, groups
);
215 scm_must_free((char *)groups
);
216 SCM_SYSERROR (s_sys_getgroups
);
218 SCM_SETCHARS(grps
, groups
); /* set up grps as a GC protect */
219 SCM_SETLENGTH(grps
, 0L + ngroups
* sizeof(GETGROUPS_T
), scm_tc7_string
);
221 ans
= scm_make_vector(SCM_MAKINUM(ngroups
), SCM_UNDEFINED
, SCM_BOOL_F
);
222 while (--ngroups
>= 0) SCM_VELTS(ans
)[ngroups
] = SCM_MAKINUM(groups
[ngroups
]);
223 SCM_SETCHARS(grps
, groups
); /* to make sure grps stays around. */
230 SCM_PROC (s_sys_getpwuid
, "getpw", 0, 1, 0, scm_sys_getpwuid
);
233 scm_sys_getpwuid (SCM user
)
236 scm_sys_getpwuid (user
)
241 struct passwd
*entry
;
244 result
= scm_make_vector (SCM_MAKINUM (7), SCM_UNSPECIFIED
, SCM_BOOL_F
);
245 ve
= SCM_VELTS (result
);
246 if (SCM_UNBNDP (user
) || SCM_FALSEP (user
))
249 SCM_SYSCALL (entry
= getpwent ());
251 else if (SCM_INUMP (user
))
254 entry
= getpwuid (SCM_INUM (user
));
258 SCM_ASSERT (SCM_NIMP (user
) && SCM_ROSTRINGP (user
), user
, SCM_ARG1
, s_sys_getpwuid
);
259 if (SCM_SUBSTRP (user
))
260 user
= scm_makfromstr (SCM_ROCHARS (user
), SCM_ROLENGTH (user
), 0);
262 entry
= getpwnam (SCM_ROCHARS (user
));
265 SCM_SYSERROR (s_sys_getpwuid
);
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
);
273 ve
[5] = scm_makfrom0str ("");
275 ve
[5] = scm_makfrom0str (entry
->pw_dir
);
276 if (!entry
->pw_shell
)
277 ve
[6] = scm_makfrom0str ("");
279 ve
[6] = scm_makfrom0str (entry
->pw_shell
);
286 SCM_PROC (s_setpwent
, "setpw", 0, 1, 0, scm_setpwent
);
289 scm_setpwent (SCM arg
)
296 if (SCM_UNBNDP (arg
) || SCM_FALSEP (arg
))
300 return SCM_UNSPECIFIED
;
305 /* Combines getgrgid and getgrnam. */
306 SCM_PROC (s_sys_getgrgid
, "getgr", 0, 1, 0, scm_sys_getgrgid
);
309 scm_sys_getgrgid (SCM name
)
312 scm_sys_getgrgid (name
)
319 result
= scm_make_vector (SCM_MAKINUM (4), SCM_UNSPECIFIED
, SCM_BOOL_F
);
320 ve
= SCM_VELTS (result
);
322 if (SCM_UNBNDP (name
) || (name
== SCM_BOOL_F
))
323 SCM_SYSCALL (entry
= getgrent ());
324 else if (SCM_INUMP (name
))
325 SCM_SYSCALL (entry
= getgrgid (SCM_INUM (name
)));
328 SCM_ASSERT (SCM_NIMP (name
) && SCM_STRINGP (name
), name
, SCM_ARG1
, s_sys_getgrgid
);
329 if (SCM_SUBSTRP (name
))
330 name
= scm_makfromstr (SCM_ROCHARS (name
), SCM_ROLENGTH (name
), 0);
331 SCM_SYSCALL (entry
= getgrnam (SCM_CHARS (name
)));
334 SCM_SYSERROR (s_sys_getgrgid
);
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
);
346 SCM_PROC (s_setgrent
, "setgr", 0, 1, 0, scm_setgrent
);
349 scm_setgrent (SCM arg
)
356 if (SCM_UNBNDP (arg
) || SCM_FALSEP (arg
))
360 return SCM_UNSPECIFIED
;
365 SCM_PROC (s_sys_kill
, "kill", 2, 0, 0, scm_sys_kill
);
368 scm_sys_kill (SCM pid
, SCM sig
)
371 scm_sys_kill (pid
, sig
)
376 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_sys_kill
);
377 SCM_ASSERT (SCM_INUMP (sig
), sig
, SCM_ARG2
, s_sys_kill
);
378 /* Signal values are interned in scm_init_posix(). */
379 if (kill ((int) SCM_INUM (pid
), (int) SCM_INUM (sig
)) != 0)
380 SCM_SYSERROR (s_sys_kill
);
381 return SCM_UNSPECIFIED
;
386 SCM_PROC (s_sys_waitpid
, "waitpid", 1, 1, 0, scm_sys_waitpid
);
389 scm_sys_waitpid (SCM pid
, SCM options
)
392 scm_sys_waitpid (pid
, options
)
400 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_sys_waitpid
);
401 if (SCM_UNBNDP (options
))
405 SCM_ASSERT (SCM_INUMP (options
), options
, SCM_ARG2
, s_sys_waitpid
);
406 /* Flags are interned in scm_init_posix. */
407 ioptions
= SCM_INUM (options
);
409 SCM_SYSCALL (i
= waitpid (SCM_INUM (pid
), &status
, ioptions
));
411 SCM_SYSERROR (s_sys_waitpid
);
412 return scm_cons (SCM_MAKINUM (0L + i
), SCM_MAKINUM (0L + status
));
417 SCM_PROC (s_getppid
, "getppid", 0, 0, 0, scm_getppid
);
426 return SCM_MAKINUM (0L + getppid ());
431 SCM_PROC (s_getuid
, "getuid", 0, 0, 0, scm_getuid
);
440 return SCM_MAKINUM (0L + getuid ());
445 SCM_PROC (s_getgid
, "getgid", 0, 0, 0, scm_getgid
);
454 return SCM_MAKINUM (0L + getgid ());
459 SCM_PROC (s_geteuid
, "geteuid", 0, 0, 0, scm_geteuid
);
469 return SCM_MAKINUM (0L + geteuid ());
471 return SCM_MAKINUM (0L + getuid ());
477 SCM_PROC (s_getegid
, "getegid", 0, 0, 0, scm_getegid
);
487 return SCM_MAKINUM (0L + getegid ());
489 return SCM_MAKINUM (0L + getgid ());
494 SCM_PROC (s_sys_setuid
, "setuid", 1, 0, 0, scm_sys_setuid
);
497 scm_sys_setuid (SCM id
)
504 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_sys_setuid
);
505 if (setuid (SCM_INUM (id
)) != 0)
506 SCM_SYSERROR (s_sys_setuid
);
507 return SCM_UNSPECIFIED
;
510 SCM_PROC (s_sys_setgid
, "setgid", 1, 0, 0, scm_sys_setgid
);
513 scm_sys_setgid (SCM id
)
520 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_sys_setgid
);
521 if (setgid (SCM_INUM (id
)) != 0)
522 SCM_SYSERROR (s_sys_setgid
);
523 return SCM_UNSPECIFIED
;
526 SCM_PROC (s_sys_seteuid
, "seteuid", 1, 0, 0, scm_sys_seteuid
);
529 scm_sys_seteuid (SCM id
)
538 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_sys_seteuid
);
540 rv
= seteuid (SCM_INUM (id
));
542 rv
= setuid (SCM_INUM (id
));
545 SCM_SYSERROR (s_sys_seteuid
);
546 return SCM_UNSPECIFIED
;
549 SCM_PROC (s_sys_setegid
, "setegid", 1, 0, 0, scm_sys_setegid
);
552 scm_sys_setegid (SCM id
)
561 SCM_ASSERT (SCM_INUMP (id
), id
, SCM_ARG1
, s_sys_setegid
);
563 rv
= setegid (SCM_INUM (id
));
565 rv
= setgid (SCM_INUM (id
));
568 SCM_SYSERROR (s_sys_setegid
);
569 return SCM_UNSPECIFIED
;
573 SCM_PROC (s_getpgrp
, "getpgrp", 0, 0, 0, scm_getpgrp
);
579 return SCM_MAKINUM (fn (0));
582 SCM_PROC (s_setpgid
, "setpgid", 2, 0, 0, scm_setpgid
);
584 scm_setpgid (pid
, pgid
)
587 SCM_ASSERT (SCM_INUMP (pid
), pid
, SCM_ARG1
, s_setpgid
);
588 SCM_ASSERT (SCM_INUMP (pgid
), pgid
, SCM_ARG2
, s_setpgid
);
589 /* FIXME(?): may be known as setpgrp. */
590 if (setpgid (SCM_INUM (pid
), SCM_INUM (pgid
)) != 0)
591 SCM_SYSERROR (s_setpgid
);
592 return SCM_UNSPECIFIED
;
595 SCM_PROC (s_setsid
, "setsid", 0, 0, 0, scm_setsid
);
599 pid_t sid
= setsid ();
601 SCM_SYSERROR (s_setsid
);
602 return SCM_UNSPECIFIED
;
606 extern char * ttyname();
609 SCM_PROC (s_ttyname
, "ttyname", 1, 0, 0, scm_ttyname
);
612 scm_ttyname (SCM port
)
621 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPPORTP (port
), port
, SCM_ARG1
, s_ttyname
);
622 if (scm_tc16_fport
!= SCM_TYP16 (port
))
624 fd
= fileno ((FILE *)SCM_STREAM (port
));
626 SCM_SYSERROR (s_ttyname
);
627 SCM_SYSCALL (ans
= ttyname (fd
));
629 SCM_SYSERROR (s_ttyname
);
630 /* ans could be overwritten by another call to ttyname */
631 return (scm_makfrom0str (ans
));
635 SCM_PROC (s_ctermid
, "ctermid", 0, 0, 0, scm_ctermid
);
639 char *result
= ctermid (NULL
);
641 SCM_SYSERROR (s_ctermid
);
642 return scm_makfrom0str (result
);
645 SCM_PROC (s_tcgetpgrp
, "tcgetpgrp", 1, 0, 0, scm_tcgetpgrp
);
652 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPFPORTP (port
), port
, SCM_ARG1
, s_tcgetpgrp
);
653 fd
= fileno ((FILE *)SCM_STREAM (port
));
654 if (fd
== -1 || (pgid
= tcgetpgrp (fd
)) == -1)
655 SCM_SYSERROR (s_tcgetpgrp
);
656 return SCM_MAKINUM (pgid
);
659 SCM_PROC (s_tcsetpgrp
, "tcsetpgrp", 2, 0, 0, scm_tcsetpgrp
);
661 scm_tcsetpgrp (port
, pgid
)
665 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPFPORTP (port
), port
, SCM_ARG1
, s_tcsetpgrp
);
666 SCM_ASSERT (SCM_INUMP (pgid
), pgid
, SCM_ARG2
, s_tcsetpgrp
);
667 fd
= fileno ((FILE *)SCM_STREAM (port
));
668 if (fd
== -1 || tcsetpgrp (fd
, SCM_INUM (pgid
)) == -1)
669 SCM_SYSERROR (s_tcsetpgrp
);
670 return SCM_UNSPECIFIED
;
673 /* Copy exec args from an SCM vector into a new C array. */
676 scm_convert_exec_args (SCM args
)
679 scm_convert_exec_args (args
)
687 num_args
= scm_ilength (args
);
689 scm_must_malloc ((num_args
+ 1) * sizeof (char *), s_ttyname
);
690 for (i
= 0; SCM_NNULLP (args
); args
= SCM_CDR (args
), ++i
)
695 SCM_ASSERT (SCM_NIMP (SCM_CAR (args
)) && SCM_ROSTRINGP (SCM_CAR (args
)), SCM_CAR (args
),
696 "wrong type in SCM_ARG", "exec arg");
697 len
= 1 + SCM_ROLENGTH (SCM_CAR (args
));
698 dst
= (char *) scm_must_malloc ((long) len
, s_ttyname
);
699 src
= SCM_ROCHARS (SCM_CAR (args
));
709 SCM_PROC (s_sys_execl
, "execl", 0, 0, 1, scm_sys_execl
);
712 scm_sys_execl (SCM args
)
720 SCM filename
= SCM_CAR (args
);
721 SCM_ASSERT (SCM_NIMP (filename
) && SCM_ROSTRINGP (filename
), filename
, SCM_ARG1
, s_sys_execl
);
722 if (SCM_SUBSTRP (filename
))
723 filename
= scm_makfromstr (SCM_ROCHARS (filename
), SCM_ROLENGTH (filename
), 0);
724 args
= SCM_CDR (args
);
725 execargv
= scm_convert_exec_args (args
);
726 execv (SCM_ROCHARS (filename
), execargv
);
727 SCM_SYSERROR (s_sys_execl
);
732 SCM_PROC (s_sys_execlp
, "execlp", 0, 0, 1, scm_sys_execlp
);
735 scm_sys_execlp (SCM args
)
738 scm_sys_execlp (args
)
743 SCM filename
= SCM_CAR (args
);
744 SCM_ASSERT (SCM_NIMP (filename
) && SCM_ROSTRINGP (filename
), filename
, SCM_ARG1
, s_sys_execlp
);
745 if (SCM_SUBSTRP (filename
))
746 filename
= scm_makfromstr (SCM_ROCHARS (filename
), SCM_ROLENGTH (filename
), 0);
747 args
= SCM_CDR (args
);
748 execargv
= scm_convert_exec_args (args
);
749 execvp (SCM_ROCHARS (filename
), execargv
);
750 SCM_SYSERROR (s_sys_execlp
);
755 /* Flushing streams etc., is not done here. */
756 SCM_PROC (s_sys_fork
, "fork", 0, 0, 0, scm_sys_fork
);
768 SCM_SYSERROR (s_sys_fork
);
769 return SCM_MAKINUM (0L+pid
);
773 SCM_PROC (s_sys_uname
, "uname", 0, 0, 0, scm_sys_uname
);
784 SCM ans
= scm_make_vector(SCM_MAKINUM(5), SCM_UNSPECIFIED
, SCM_BOOL_F
);
785 SCM
*ve
= SCM_VELTS (ans
);
787 return SCM_MAKINUM (errno
);
788 ve
[0] = scm_makfrom0str (buf
.sysname
);
789 ve
[1] = scm_makfrom0str (buf
.nodename
);
790 ve
[2] = scm_makfrom0str (buf
.release
);
791 ve
[3] = scm_makfrom0str (buf
.version
);
792 ve
[4] = scm_makfrom0str (buf
.machine
);
795 ve[5] = scm_makfrom0str (buf.domainname);
799 SCM_SYSMISSING (s_sys_uname
);
805 SCM_PROC (s_environ
, "environ", 0, 1, 0, scm_environ
);
808 scm_environ (SCM env
)
815 if (SCM_UNBNDP (env
))
816 return scm_makfromstrs (-1, environ
);
822 SCM_ASSERT (SCM_NULLP (env
) || (SCM_NIMP (env
) && SCM_CONSP (env
)),
823 env
, SCM_ARG1
, s_environ
);
824 num_strings
= scm_ilength (env
);
825 new_environ
= (char **) scm_must_malloc ((num_strings
+ 1)
828 while (SCM_NNULLP (env
))
832 SCM_ASSERT (SCM_NIMP (SCM_CAR (env
)) && SCM_ROSTRINGP (SCM_CAR (env
)), env
, SCM_ARG1
,
834 len
= 1 + SCM_ROLENGTH (SCM_CAR (env
));
835 new_environ
[i
] = scm_must_malloc ((long) len
, s_environ
);
836 src
= SCM_ROCHARS (SCM_CAR (env
));
838 new_environ
[i
][len
] = src
[len
];
843 /* Free the old environment, except when called for the first
848 static int first
= 1;
851 for (ep
= environ
; *ep
!= NULL
; ep
++)
853 scm_must_free ((char *) environ
);
857 environ
= new_environ
;
858 return SCM_UNSPECIFIED
;
863 SCM_PROC (s_open_pipe
, "open-pipe", 2, 0, 0, scm_open_pipe
);
866 scm_open_pipe (SCM pipestr
, SCM modes
)
869 scm_open_pipe (pipestr
, modes
)
876 struct scm_port_table
* pt
;
878 SCM_ASSERT (SCM_NIMP (pipestr
) && SCM_ROSTRINGP (pipestr
), pipestr
, SCM_ARG1
, s_open_pipe
);
879 if (SCM_SUBSTRP (pipestr
))
880 pipestr
= scm_makfromstr (SCM_ROCHARS (pipestr
), SCM_ROLENGTH (pipestr
), 0);
881 SCM_ASSERT (SCM_NIMP (modes
) && SCM_ROSTRINGP (modes
), modes
, SCM_ARG2
, s_open_pipe
);
882 if (SCM_SUBSTRP (modes
))
883 modes
= scm_makfromstr (SCM_ROCHARS (modes
), SCM_ROLENGTH (modes
), 0);
886 scm_ignore_signals ();
887 SCM_SYSCALL (f
= popen (SCM_ROCHARS (pipestr
), SCM_ROCHARS (modes
)));
888 scm_unignore_signals ();
890 SCM_SYSERROR (s_open_pipe
);
891 pt
= scm_add_to_port_table (z
);
892 SCM_SETPTAB_ENTRY (z
, pt
);
893 SCM_CAR (z
) = scm_tc16_pipe
| SCM_OPN
894 | (strchr (SCM_ROCHARS (modes
), 'r') ? SCM_RDNG
: SCM_WRTNG
);
895 SCM_SETSTREAM (z
, (SCM
)f
);
901 SCM_PROC (s_open_input_pipe
, "open-input-pipe", 1, 0, 0, scm_open_input_pipe
);
904 scm_open_input_pipe(SCM pipestr
)
907 scm_open_input_pipe(pipestr
)
911 return scm_open_pipe(pipestr
, scm_makfromstr("r", (sizeof "r")-1, 0));
914 SCM_PROC (s_open_output_pipe
, "open-output-pipe", 1, 0, 0, scm_open_output_pipe
);
917 scm_open_output_pipe(SCM pipestr
)
920 scm_open_output_pipe(pipestr
)
924 return scm_open_pipe(pipestr
, scm_makfromstr("w", (sizeof "w")-1, 0));
929 #include <sys/utime.h>
934 SCM_PROC (s_sys_utime
, "utime", 1, 2, 0, scm_sys_utime
);
937 scm_sys_utime (SCM pathname
, SCM actime
, SCM modtime
)
940 scm_sys_utime (pathname
, actime
, modtime
)
947 struct utimbuf utm_tmp
;
949 SCM_ASSERT (SCM_NIMP (pathname
) && SCM_STRINGP (pathname
), pathname
, SCM_ARG1
, s_sys_utime
);
951 if (SCM_UNBNDP (actime
))
952 SCM_SYSCALL (time (&utm_tmp
.actime
));
954 utm_tmp
.actime
= scm_num2ulong (actime
, (char *) SCM_ARG2
, s_sys_utime
);
956 if (SCM_UNBNDP (modtime
))
957 SCM_SYSCALL (time (&utm_tmp
.modtime
));
959 utm_tmp
.modtime
= scm_num2ulong (modtime
, (char *) SCM_ARG3
, s_sys_utime
);
961 SCM_SYSCALL (rv
= utime (SCM_CHARS (pathname
), &utm_tmp
));
963 SCM_SYSERROR (s_sys_utime
);
964 return SCM_UNSPECIFIED
;
967 SCM_PROC (s_sys_access
, "access?", 2, 0, 0, scm_sys_access
);
970 scm_sys_access (SCM path
, SCM how
)
973 scm_sys_access (path
, how
)
980 SCM_ASSERT (SCM_NIMP (path
) && SCM_ROSTRINGP (path
), path
, SCM_ARG1
, s_sys_access
);
981 if (SCM_SUBSTRP (path
))
982 path
= scm_makfromstr (SCM_ROCHARS (path
), SCM_ROLENGTH (path
), 0);
983 SCM_ASSERT (SCM_INUMP (how
), how
, SCM_ARG2
, s_sys_access
);
984 rv
= access (SCM_ROCHARS (path
), SCM_INUM (how
));
985 return rv
? SCM_BOOL_F
: SCM_BOOL_T
;
988 SCM_PROC (s_getpid
, "getpid", 0, 0, 0, scm_getpid
);
997 return SCM_MAKINUM ((unsigned long) getpid ());
1000 SCM_PROC (s_sys_putenv
, "putenv", 1, 0, 0, scm_sys_putenv
);
1003 scm_sys_putenv (SCM str
)
1006 scm_sys_putenv (str
)
1011 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_sys_putenv
);
1012 return putenv (SCM_CHARS (str
)) ? SCM_MAKINUM (errno
) : SCM_BOOL_T
;
1014 SCM_SYSMISSING (s_sys_putenv
);
1020 SCM_PROC (s_read_line
, "read-line", 0, 2, 0, scm_read_line
);
1023 scm_read_line (SCM port
, SCM include_terminator
)
1026 scm_read_line (port
, include_terminator
)
1028 SCM include_terminator
;
1038 tok_buf
= scm_makstr ((long) len
, 0);
1039 p
= SCM_CHARS (tok_buf
);
1040 if (SCM_UNBNDP (port
))
1043 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPINPORTP (port
), port
, SCM_ARG1
, s_read_line
);
1045 if (SCM_UNBNDP (include_terminator
))
1048 include
= SCM_NFALSEP (include_terminator
);
1050 if (EOF
== (c
= scm_gen_getc (port
)))
1056 case SCM_LINE_INCREMENTORS
:
1059 p
= scm_grow_tok_buf (&tok_buf
);
1060 len
= SCM_LENGTH (tok_buf
);
1067 return scm_vector_set_length_x (tok_buf
, (SCM
) SCM_MAKINUM (j
));
1072 p
= scm_grow_tok_buf (&tok_buf
);
1073 len
= SCM_LENGTH (tok_buf
);
1076 c
= scm_gen_getc (port
);
1082 SCM_PROC (s_read_line_x
, "read-line!", 1, 1, 0, scm_read_line_x
);
1085 scm_read_line_x (SCM str
, SCM port
)
1088 scm_read_line_x (str
, port
)
1097 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_read_line_x
);
1098 p
= SCM_CHARS (str
);
1099 len
= SCM_LENGTH (str
);
1101 (port
) port
= scm_cur_inp
;
1103 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPINPORTP (port
), port
, SCM_ARG2
, s_read_line_x
);
1104 c
= scm_gen_getc (port
);
1111 case SCM_LINE_INCREMENTORS
:
1113 return SCM_MAKINUM (j
);
1117 scm_gen_ungetc (c
, port
);
1121 c
= scm_gen_getc (port
);
1126 SCM_PROC (s_write_line
, "write-line", 1, 1, 0, scm_write_line
);
1129 scm_write_line (SCM obj
, SCM port
)
1132 scm_write_line (obj
, port
)
1137 scm_display (obj
, port
);
1138 return scm_newline (port
);
1141 SCM_PROC (s_setlocale
, "setlocale", 1, 1, 0, scm_setlocale
);
1144 scm_setlocale (SCM category
, SCM locale
)
1147 scm_setlocale (category
, locale
)
1152 #ifdef HAVE_SETLOCALE
1156 SCM_ASSERT (SCM_INUMP (category
), category
, SCM_ARG1
, s_setlocale
);
1157 if (SCM_UNBNDP (locale
))
1163 SCM_ASSERT (SCM_NIMP (locale
) && SCM_STRINGP (locale
), locale
, SCM_ARG2
, s_setlocale
);
1164 clocale
= SCM_CHARS (locale
);
1167 rv
= setlocale (SCM_INUM (category
), clocale
);
1169 SCM_SYSERROR (s_setlocale
);
1170 return scm_makfrom0str (rv
);
1172 SCM_SYSMISSING (s_setlocale
);
1178 SCM_PROC (s_strftime
, "strftime", 2, 0, 0, scm_strftime
);
1181 scm_strftime (SCM format
, SCM stime
)
1184 scm_strftime (format
, stime
)
1197 SCM_ASSERT (SCM_NIMP (format
) && SCM_STRINGP (format
), format
, SCM_ARG1
, s_strftime
);
1198 SCM_ASSERT (SCM_NIMP (stime
) && SCM_VECTORP (stime
) && scm_obj_length (stime
) == 9,
1199 stime
, SCM_ARG2
, s_strftime
);
1201 fmt
= SCM_ROCHARS (format
);
1202 len
= SCM_ROLENGTH (format
);
1204 #define tm_deref scm_num2long (SCM_VELTS (stime)[n++], (char *)SCM_ARG2, s_strftime)
1206 t
.tm_sec
= tm_deref
;
1207 t
.tm_min
= tm_deref
;
1208 t
.tm_hour
= tm_deref
;
1209 t
.tm_mday
= tm_deref
;
1210 t
.tm_mon
= tm_deref
;
1211 t
.tm_year
= tm_deref
;
1212 /* not used by mktime.
1213 t.tm_wday = tm_deref;
1214 t.tm_yday = tm_deref; */
1215 t
.tm_isdst
= tm_deref
;
1218 /* fill in missing fields and set the timezone. */
1221 tbuf
= scm_must_malloc (size
, s_strftime
);
1222 while ((len
= strftime (tbuf
, size
, fmt
, &t
)) == size
)
1224 scm_must_free (tbuf
);
1226 tbuf
= scm_must_malloc (size
, s_strftime
);
1228 return scm_makfromstr (tbuf
, len
, 0);
1231 SCM_PROC (s_sys_strptime
, "strptime", 2, 0, 0, scm_sys_strptime
);
1234 scm_sys_strptime (SCM format
, SCM string
)
1237 scm_sys_strptime (format
, string
)
1242 #ifdef HAVE_STRPTIME
1246 char *fmt
, *str
, *rest
;
1249 SCM_ASSERT (SCM_NIMP (format
) && SCM_ROSTRINGP (format
), format
, SCM_ARG1
, s_sys_strptime
);
1250 if (SCM_SUBSTRP (format
))
1251 format
= scm_makfromstr (SCM_ROCHARS (format
), SCM_ROLENGTH (format
), 0);
1252 SCM_ASSERT (SCM_NIMP (string
) && SCM_ROSTRINGP (string
), string
, SCM_ARG2
, s_sys_strptime
);
1253 if (SCM_SUBSTRP (string
))
1254 string
= scm_makfromstr (SCM_ROCHARS (string
), SCM_ROLENGTH (string
), 0);
1256 fmt
= SCM_CHARS (format
);
1257 str
= SCM_CHARS (string
);
1259 /* initialize the struct tm */
1260 #define tm_init(field) t.field = 0
1273 rest
= strptime (str
, fmt
, &t
);
1277 SCM_SYSERROR (s_sys_strptime
);
1279 stime
= scm_make_vector (SCM_MAKINUM (9), scm_long2num (0), SCM_UNDEFINED
);
1281 #define stime_set(val) scm_vector_set_x (stime, SCM_MAKINUM (n++), scm_long2num (t.val));
1285 stime_set (tm_hour
);
1286 stime_set (tm_mday
);
1288 stime_set (tm_year
);
1289 stime_set (tm_wday
);
1290 stime_set (tm_yday
);
1291 stime_set (tm_isdst
);
1294 return scm_cons (stime
, scm_makfrom0str (rest
));
1296 SCM_SYSMISSING (s_sys_strptime
);
1302 SCM_PROC (s_sys_mknod
, "mknod", 3, 0, 0, scm_sys_mknod
);
1305 scm_sys_mknod(SCM path
, SCM mode
, SCM dev
)
1308 scm_sys_mknod(path
, mode
, dev
)
1316 SCM_ASSERT(SCM_NIMP(path
) && SCM_STRINGP(path
), path
, SCM_ARG1
, s_sys_mknod
);
1317 SCM_ASSERT(SCM_INUMP(mode
), mode
, SCM_ARG2
, s_sys_mknod
);
1318 SCM_ASSERT(SCM_INUMP(dev
), dev
, SCM_ARG3
, s_sys_mknod
);
1319 SCM_SYSCALL(val
= mknod(SCM_CHARS(path
), SCM_INUM(mode
), SCM_INUM(dev
)));
1321 SCM_SYSERROR (s_sys_mknod
);
1322 return SCM_UNSPECIFIED
;
1324 SCM_SYSMISSING (s_sys_mknod
);
1331 SCM_PROC (s_sys_nice
, "nice", 1, 0, 0, scm_sys_nice
);
1334 scm_sys_nice(SCM incr
)
1342 SCM_ASSERT(SCM_INUMP(incr
), incr
, SCM_ARG1
, s_sys_nice
);
1343 if (nice(SCM_INUM(incr
)) != 0)
1344 SCM_SYSERROR (s_sys_nice
);
1345 return SCM_UNSPECIFIED
;
1347 SCM_SYSMISSING (s_sys_nice
);
1354 SCM_PROC (s_sync
, "sync", 0, 0, 0, scm_sync
);
1366 SCM_SYSMISSING (s_sync
);
1375 scm_init_posix (void)
1381 scm_add_feature ("posix");
1383 scm_add_feature ("EIDs");
1386 scm_sysintern ("WAIT_ANY", SCM_MAKINUM (WAIT_ANY
));
1389 scm_sysintern ("WAIT_MYPGRP", SCM_MAKINUM (WAIT_MYPGRP
));
1392 scm_sysintern ("WNOHANG", SCM_MAKINUM (WNOHANG
));
1395 scm_sysintern ("WUNTRACED", SCM_MAKINUM (WUNTRACED
));
1399 scm_sysintern ("EINTR", SCM_MAKINUM (EINTR
));
1403 scm_sysintern ("SIGHUP", SCM_MAKINUM (SIGHUP
));
1406 scm_sysintern ("SIGINT", SCM_MAKINUM (SIGINT
));
1409 scm_sysintern ("SIGQUIT", SCM_MAKINUM (SIGQUIT
));
1412 scm_sysintern ("SIGILL", SCM_MAKINUM (SIGILL
));
1415 scm_sysintern ("SIGTRAP", SCM_MAKINUM (SIGTRAP
));
1418 scm_sysintern ("SIGABRT", SCM_MAKINUM (SIGABRT
));
1421 scm_sysintern ("SIGIOT", SCM_MAKINUM (SIGIOT
));
1424 scm_sysintern ("SIGBUS", SCM_MAKINUM (SIGBUS
));
1427 scm_sysintern ("SIGFPE", SCM_MAKINUM (SIGFPE
));
1430 scm_sysintern ("SIGKILL", SCM_MAKINUM (SIGKILL
));
1433 scm_sysintern ("SIGUSR1", SCM_MAKINUM (SIGUSR1
));
1436 scm_sysintern ("SIGSEGV", SCM_MAKINUM (SIGSEGV
));
1439 scm_sysintern ("SIGUSR2", SCM_MAKINUM (SIGUSR2
));
1442 scm_sysintern ("SIGPIPE", SCM_MAKINUM (SIGPIPE
));
1445 scm_sysintern ("SIGALRM", SCM_MAKINUM (SIGALRM
));
1448 scm_sysintern ("SIGTERM", SCM_MAKINUM (SIGTERM
));
1451 scm_sysintern ("SIGSTKFLT", SCM_MAKINUM (SIGSTKFLT
));
1454 scm_sysintern ("SIGCHLD", SCM_MAKINUM (SIGCHLD
));
1457 scm_sysintern ("SIGCONT", SCM_MAKINUM (SIGCONT
));
1460 scm_sysintern ("SIGSTOP", SCM_MAKINUM (SIGSTOP
));
1463 scm_sysintern ("SIGTSTP", SCM_MAKINUM (SIGTSTP
));
1466 scm_sysintern ("SIGTTIN", SCM_MAKINUM (SIGTTIN
));
1469 scm_sysintern ("SIGTTOU", SCM_MAKINUM (SIGTTOU
));
1472 scm_sysintern ("SIGIO", SCM_MAKINUM (SIGIO
));
1475 scm_sysintern ("SIGPOLL", SCM_MAKINUM (SIGPOLL
));
1478 scm_sysintern ("SIGURG", SCM_MAKINUM (SIGURG
));
1481 scm_sysintern ("SIGXCPU", SCM_MAKINUM (SIGXCPU
));
1484 scm_sysintern ("SIGXFSZ", SCM_MAKINUM (SIGXFSZ
));
1487 scm_sysintern ("SIGVTALRM", SCM_MAKINUM (SIGVTALRM
));
1490 scm_sysintern ("SIGPROF", SCM_MAKINUM (SIGPROF
));
1493 scm_sysintern ("SIGWINCH", SCM_MAKINUM (SIGWINCH
));
1496 scm_sysintern ("SIGLOST", SCM_MAKINUM (SIGLOST
));
1499 scm_sysintern ("SIGPWR", SCM_MAKINUM (SIGPWR
));
1501 /* access() symbols. */
1502 scm_sysintern ("R_OK", SCM_MAKINUM (R_OK
));
1503 scm_sysintern ("W_OK", SCM_MAKINUM (W_OK
));
1504 scm_sysintern ("X_OK", SCM_MAKINUM (X_OK
));
1505 scm_sysintern ("F_OK", SCM_MAKINUM (F_OK
));
1508 scm_sysintern ("LC_COLLATE", SCM_MAKINUM (LC_COLLATE
));
1511 scm_sysintern ("LC_CTYPE", SCM_MAKINUM (LC_CTYPE
));
1514 scm_sysintern ("LC_MONETARY", SCM_MAKINUM (LC_MONETARY
));
1517 scm_sysintern ("LC_NUMERIC", SCM_MAKINUM (LC_NUMERIC
));
1520 scm_sysintern ("LC_TIME", SCM_MAKINUM (LC_TIME
));
1523 scm_sysintern ("LC_MESSAGES", SCM_MAKINUM (LC_MESSAGES
));
1526 scm_sysintern ("LC_ALL", SCM_MAKINUM (LC_ALL
));