Merge from mvo-vcell-cleanup-1-branch.
[bpt/guile.git] / libguile / posix.c
CommitLineData
e4b265d8 1/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
0f2d19dd
JB
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
82892bed
JB
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
0f2d19dd
JB
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
82892bed 40 * If you do not wish that, delete this exception notice. */
1bbd0b84
GB
41
42/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
43 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
44
0f2d19dd
JB
45\f
46
8b50fe8e
MV
47/* Make GNU/Linux libc declare everything it has. */
48#define _GNU_SOURCE
49
0f2d19dd 50#include <stdio.h>
e6e2e95a
MD
51#include <errno.h>
52
a0599745
MD
53#include "libguile/_scm.h"
54#include "libguile/fports.h"
55#include "libguile/scmsigs.h"
56#include "libguile/feature.h"
57#include "libguile/strings.h"
58#include "libguile/vectors.h"
59
60#include "libguile/validate.h"
61#include "libguile/posix.h"
0f2d19dd
JB
62\f
63
02b754d3
GH
64#ifdef HAVE_STRING_H
65#include <string.h>
66#endif
0f2d19dd
JB
67#ifdef TIME_WITH_SYS_TIME
68# include <sys/time.h>
69# include <time.h>
70#else
71# if HAVE_SYS_TIME_H
72# include <sys/time.h>
73# else
74# include <time.h>
75# endif
76#endif
77
78#ifdef HAVE_UNISTD_H
79#include <unistd.h>
95b88819
GH
80#else
81#ifndef ttyname
82extern char *ttyname();
83#endif
0f2d19dd
JB
84#endif
85
3594582b 86#ifdef LIBC_H_WITH_UNISTD_H
bab0f4e5
JB
87#include <libc.h>
88#endif
89
8cc71382 90#include <sys/types.h>
0f2d19dd
JB
91#include <sys/stat.h>
92#include <fcntl.h>
93
94#include <pwd.h>
95
96#if HAVE_SYS_WAIT_H
97# include <sys/wait.h>
98#endif
99#ifndef WEXITSTATUS
100# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
101#endif
102#ifndef WIFEXITED
103# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
104#endif
105
106#include <signal.h>
107
0f2d19dd
JB
108extern char ** environ;
109
110#include <grp.h>
111#include <sys/utsname.h>
112
113#if HAVE_DIRENT_H
114# include <dirent.h>
115# define NAMLEN(dirent) strlen((dirent)->d_name)
116#else
117# define dirent direct
118# define NAMLEN(dirent) (dirent)->d_namlen
119# if HAVE_SYS_NDIR_H
120# include <sys/ndir.h>
121# endif
122# if HAVE_SYS_DIR_H
123# include <sys/dir.h>
124# endif
125# if HAVE_NDIR_H
126# include <ndir.h>
127# endif
128#endif
129
0f2d19dd
JB
130#ifdef HAVE_SETLOCALE
131#include <locale.h>
132#endif
133
94e6d793
MG
134#if HAVE_LIBCRYPT && HAVE_CRYPT_H
135# include <crypt.h>
136#endif
137
138#if HAVE_SYS_RESOURCE_H
139# include <sys/resource.h>
140#endif
141
142#if HAVE_SYS_FILE_H
143# include <sys/file.h>
144#endif
145
bab0f4e5
JB
146/* Some Unix systems don't define these. CPP hair is dangerous, but
147 this seems safe enough... */
148#ifndef R_OK
149#define R_OK 4
150#endif
151
152#ifndef W_OK
153#define W_OK 2
154#endif
155
156#ifndef X_OK
157#define X_OK 1
158#endif
159
160#ifndef F_OK
161#define F_OK 0
162#endif
398609a5
JB
163
164/* On NextStep, <utime.h> doesn't define struct utime, unless we
165 #define _POSIX_SOURCE before #including it. I think this is less
166 of a kludge than defining struct utimbuf ourselves. */
167#ifdef UTIMBUF_NEEDS_POSIX
168#define _POSIX_SOURCE
169#endif
170
171#ifdef HAVE_SYS_UTIME_H
172#include <sys/utime.h>
173#endif
174
175#ifdef HAVE_UTIME_H
176#include <utime.h>
177#endif
178
179/* Please don't add any more #includes or #defines here. The hack
180 above means that _POSIX_SOURCE may be #defined, which will
181 encourage header files to do strange things. */
182
0f2d19dd 183\f
bc45012d
JB
184SCM_SYMBOL (sym_read_pipe, "read pipe");
185SCM_SYMBOL (sym_write_pipe, "write pipe");
0f2d19dd 186
a1ec6916 187SCM_DEFINE (scm_pipe, "pipe", 0, 0, 0,
1bbd0b84 188 (),
1e6808ea
MG
189 "Return a newly created pipe: a pair of ports which are linked\n"
190 "together on the local machine. The @emph{car} is the input\n"
191 "port and the @emph{cdr} is the output port. Data written (and\n"
192 "flushed) to the output port can be read from the input port.\n"
193 "Pipes are commonly used for communication with a newly forked\n"
194 "child process. The need to flush the output port can be\n"
195 "avoided by making it unbuffered using @code{setvbuf}.\n"
196 "\n"
197 "Writes occur atomically provided the size of the data in bytes\n"
198 "is not greater than the value of @code{PIPE_BUF}. Note that\n"
199 "the output port is likely to block if too much data (typically\n"
200 "equal to @code{PIPE_BUF}) has been written but not yet read\n"
201 "from the input port.")
1bbd0b84 202#define FUNC_NAME s_scm_pipe
0f2d19dd
JB
203{
204 int fd[2], rv;
0f2d19dd 205 SCM p_rd, p_wt;
02b754d3 206
0f2d19dd
JB
207 rv = pipe (fd);
208 if (rv)
1bbd0b84 209 SCM_SYSERROR;
ee149d03
JB
210
211 p_rd = scm_fdes_to_port (fd[0], "r", sym_read_pipe);
212 p_wt = scm_fdes_to_port (fd[1], "w", sym_write_pipe);
0f2d19dd
JB
213 return scm_cons (p_rd, p_wt);
214}
1bbd0b84 215#undef FUNC_NAME
0f2d19dd
JB
216
217
0e958795 218#ifdef HAVE_GETGROUPS
a1ec6916 219SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
1bbd0b84 220 (),
1e6808ea
MG
221 "Return a vector of integers representing the current\n"
222 "supplimentary group IDs.")
1bbd0b84 223#define FUNC_NAME s_scm_getgroups
0f2d19dd 224{
66460dfb
DH
225 SCM ans;
226 int ngroups;
227 scm_sizet size;
228 GETGROUPS_T *groups;
229
230 ngroups = getgroups (0, NULL);
231 if (ngroups <= 0)
1bbd0b84 232 SCM_SYSERROR;
66460dfb
DH
233
234 size = ngroups * sizeof (GETGROUPS_T);
235 groups = scm_must_malloc (size, FUNC_NAME);
236 getgroups (ngroups, groups);
237
00ffa0e7 238 ans = scm_c_make_vector (ngroups, SCM_UNDEFINED);
66460dfb
DH
239 while (--ngroups >= 0)
240 SCM_VELTS (ans) [ngroups] = SCM_MAKINUM (groups [ngroups]);
241
242 scm_must_free (groups);
243 scm_done_free (size);
244
245 return ans;
1bbd0b84
GB
246}
247#undef FUNC_NAME
0e958795 248#endif
0f2d19dd
JB
249
250
a1ec6916 251SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
1bbd0b84 252 (SCM user),
b380b885
MD
253 "Look up an entry in the user database. @var{obj} can be an integer,\n"
254 "a string, or omitted, giving the behaviour of getpwuid, getpwnam\n"
255 "or getpwent respectively.")
1bbd0b84 256#define FUNC_NAME s_scm_getpwuid
0f2d19dd
JB
257{
258 SCM result;
259 struct passwd *entry;
260 SCM *ve;
261
00ffa0e7 262 result = scm_c_make_vector (7, SCM_UNSPECIFIED);
0f2d19dd
JB
263 ve = SCM_VELTS (result);
264 if (SCM_UNBNDP (user) || SCM_FALSEP (user))
265 {
0f2d19dd 266 SCM_SYSCALL (entry = getpwent ());
3d781d49
JB
267 if (! entry)
268 {
3d781d49
JB
269 return SCM_BOOL_F;
270 }
0f2d19dd
JB
271 }
272 else if (SCM_INUMP (user))
273 {
0f2d19dd
JB
274 entry = getpwuid (SCM_INUM (user));
275 }
276 else
277 {
a6d9e5ab
DH
278 SCM_VALIDATE_STRING (1, user);
279 SCM_STRING_COERCE_0TERMINATION_X (user);
280 entry = getpwnam (SCM_STRING_CHARS (user));
0f2d19dd
JB
281 }
282 if (!entry)
1bbd0b84 283 SCM_MISC_ERROR ("entry not found", SCM_EOL);
02b754d3 284
0f2d19dd
JB
285 ve[0] = scm_makfrom0str (entry->pw_name);
286 ve[1] = scm_makfrom0str (entry->pw_passwd);
287 ve[2] = scm_ulong2num ((unsigned long) entry->pw_uid);
288 ve[3] = scm_ulong2num ((unsigned long) entry->pw_gid);
289 ve[4] = scm_makfrom0str (entry->pw_gecos);
290 if (!entry->pw_dir)
291 ve[5] = scm_makfrom0str ("");
292 else
293 ve[5] = scm_makfrom0str (entry->pw_dir);
294 if (!entry->pw_shell)
295 ve[6] = scm_makfrom0str ("");
296 else
297 ve[6] = scm_makfrom0str (entry->pw_shell);
0f2d19dd
JB
298 return result;
299}
1bbd0b84 300#undef FUNC_NAME
0f2d19dd
JB
301
302
0e958795 303#ifdef HAVE_SETPWENT
a1ec6916 304SCM_DEFINE (scm_setpwent, "setpw", 0, 1, 0,
1bbd0b84 305 (SCM arg),
b380b885
MD
306 "If called with a true argument, initialize or reset the password data\n"
307 "stream. Otherwise, close the stream. The @code{setpwent} and\n"
308 "@code{endpwent} procedures are implemented on top of this.")
1bbd0b84 309#define FUNC_NAME s_scm_setpwent
0f2d19dd
JB
310{
311 if (SCM_UNBNDP (arg) || SCM_FALSEP (arg))
312 endpwent ();
313 else
314 setpwent ();
315 return SCM_UNSPECIFIED;
316}
1bbd0b84 317#undef FUNC_NAME
0e958795 318#endif
0f2d19dd
JB
319
320
321
322/* Combines getgrgid and getgrnam. */
a1ec6916 323SCM_DEFINE (scm_getgrgid, "getgr", 0, 1, 0,
1bbd0b84 324 (SCM name),
b380b885
MD
325 "Look up an entry in the group database. @var{obj} can be an integer,\n"
326 "a string, or omitted, giving the behaviour of getgrgid, getgrnam\n"
327 "or getgrent respectively.")
1bbd0b84 328#define FUNC_NAME s_scm_getgrgid
0f2d19dd
JB
329{
330 SCM result;
331 struct group *entry;
332 SCM *ve;
00ffa0e7 333 result = scm_c_make_vector (4, SCM_UNSPECIFIED);
0f2d19dd 334 ve = SCM_VELTS (result);
4260a7fc 335 if (SCM_UNBNDP (name) || SCM_FALSEP (name))
3d781d49
JB
336 {
337 SCM_SYSCALL (entry = getgrent ());
338 if (! entry)
339 {
3d781d49
JB
340 return SCM_BOOL_F;
341 }
342 }
0f2d19dd
JB
343 else if (SCM_INUMP (name))
344 SCM_SYSCALL (entry = getgrgid (SCM_INUM (name)));
345 else
346 {
a6d9e5ab
DH
347 SCM_VALIDATE_STRING (1, name);
348 SCM_STRING_COERCE_0TERMINATION_X (name);
349 SCM_SYSCALL (entry = getgrnam (SCM_STRING_CHARS (name)));
0f2d19dd
JB
350 }
351 if (!entry)
1bbd0b84 352 SCM_SYSERROR;
02b754d3 353
0f2d19dd
JB
354 ve[0] = scm_makfrom0str (entry->gr_name);
355 ve[1] = scm_makfrom0str (entry->gr_passwd);
356 ve[2] = scm_ulong2num ((unsigned long) entry->gr_gid);
357 ve[3] = scm_makfromstrs (-1, entry->gr_mem);
0f2d19dd
JB
358 return result;
359}
1bbd0b84 360#undef FUNC_NAME
0f2d19dd
JB
361
362
363
a1ec6916 364SCM_DEFINE (scm_setgrent, "setgr", 0, 1, 0,
1bbd0b84 365 (SCM arg),
b380b885
MD
366 "If called with a true argument, initialize or reset the group data\n"
367 "stream. Otherwise, close the stream. The @code{setgrent} and\n"
368 "@code{endgrent} procedures are implemented on top of this.")
1bbd0b84 369#define FUNC_NAME s_scm_setgrent
0f2d19dd
JB
370{
371 if (SCM_UNBNDP (arg) || SCM_FALSEP (arg))
372 endgrent ();
373 else
374 setgrent ();
375 return SCM_UNSPECIFIED;
376}
1bbd0b84 377#undef FUNC_NAME
0f2d19dd
JB
378
379
380
a1ec6916 381SCM_DEFINE (scm_kill, "kill", 2, 0, 0,
1bbd0b84 382 (SCM pid, SCM sig),
b380b885
MD
383 "Sends a signal to the specified process or group of processes.\n\n"
384 "@var{pid} specifies the processes to which the signal is sent:\n\n"
385 "@table @r\n"
386 "@item @var{pid} greater than 0\n"
387 "The process whose identifier is @var{pid}.\n"
388 "@item @var{pid} equal to 0\n"
389 "All processes in the current process group.\n"
390 "@item @var{pid} less than -1\n"
391 "The process group whose identifier is -@var{pid}\n"
392 "@item @var{pid} equal to -1\n"
393 "If the process is privileged, all processes except for some special\n"
394 "system processes. Otherwise, all processes with the current effective\n"
395 "user ID.\n"
396 "@end table\n\n"
397 "@var{sig} should be specified using a variable corresponding to\n"
398 "the Unix symbolic name, e.g.,\n\n"
399 "@defvar SIGHUP\n"
400 "Hang-up signal.\n"
401 "@end defvar\n\n"
402 "@defvar SIGINT\n"
403 "Interrupt signal.\n"
404 "@end defvar")
1bbd0b84 405#define FUNC_NAME s_scm_kill
0f2d19dd 406{
3b3b36dd
GB
407 SCM_VALIDATE_INUM (1,pid);
408 SCM_VALIDATE_INUM (2,sig);
0f2d19dd 409 /* Signal values are interned in scm_init_posix(). */
02b754d3 410 if (kill ((int) SCM_INUM (pid), (int) SCM_INUM (sig)) != 0)
1bbd0b84 411 SCM_SYSERROR;
02b754d3 412 return SCM_UNSPECIFIED;
0f2d19dd 413}
1bbd0b84 414#undef FUNC_NAME
0f2d19dd 415
d00ae47e 416#ifdef HAVE_WAITPID
a1ec6916 417SCM_DEFINE (scm_waitpid, "waitpid", 1, 1, 0,
1bbd0b84 418 (SCM pid, SCM options),
b380b885
MD
419 "This procedure collects status information from a child process which\n"
420 "has terminated or (optionally) stopped. Normally it will\n"
421 "suspend the calling process until this can be done. If more than one\n"
422 "child process is eligible then one will be chosen by the operating system.\n\n"
423 "The value of @var{pid} determines the behaviour:\n\n"
424 "@table @r\n"
425 "@item @var{pid} greater than 0\n"
426 "Request status information from the specified child process.\n"
427 "@item @var{pid} equal to -1 or WAIT_ANY\n"
428 "Request status information for any child process.\n"
429 "@item @var{pid} equal to 0 or WAIT_MYPGRP\n"
430 "Request status information for any child process in the current process\n"
431 "group.\n"
432 "@item @var{pid} less than -1\n"
433 "Request status information for any child process whose process group ID\n"
434 "is -@var{PID}.\n"
435 "@end table\n\n"
436 "The @var{options} argument, if supplied, should be the bitwise OR of the\n"
437 "values of zero or more of the following variables:\n\n"
438 "@defvar WNOHANG\n"
439 "Return immediately even if there are no child processes to be collected.\n"
440 "@end defvar\n\n"
441 "@defvar WUNTRACED\n"
442 "Report status information for stopped processes as well as terminated\n"
443 "processes.\n"
444 "@end defvar\n\n"
445 "The return value is a pair containing:\n\n"
446 "@enumerate\n"
447 "@item\n"
448 "The process ID of the child process, or 0 if @code{WNOHANG} was\n"
449 "specified and no process was collected.\n"
450 "@item\n"
451 "The integer status value.\n"
452 "@end enumerate")
1bbd0b84 453#define FUNC_NAME s_scm_waitpid
0f2d19dd
JB
454{
455 int i;
456 int status;
457 int ioptions;
3b3b36dd 458 SCM_VALIDATE_INUM (1,pid);
0f2d19dd
JB
459 if (SCM_UNBNDP (options))
460 ioptions = 0;
461 else
462 {
3b3b36dd 463 SCM_VALIDATE_INUM (2,options);
0f2d19dd
JB
464 /* Flags are interned in scm_init_posix. */
465 ioptions = SCM_INUM (options);
466 }
467 SCM_SYSCALL (i = waitpid (SCM_INUM (pid), &status, ioptions));
02b754d3 468 if (i == -1)
1bbd0b84 469 SCM_SYSERROR;
02b754d3 470 return scm_cons (SCM_MAKINUM (0L + i), SCM_MAKINUM (0L + status));
0f2d19dd 471}
1bbd0b84 472#undef FUNC_NAME
d00ae47e 473#endif /* HAVE_WAITPID */
0f2d19dd 474
a1ec6916 475SCM_DEFINE (scm_status_exit_val, "status:exit-val", 1, 0, 0,
1bbd0b84 476 (SCM status),
1e6808ea
MG
477 "Return the exit status value, as would be set if a process\n"
478 "ended normally through a call to @code{exit} or @code{_exit},\n"
479 "if any, otherwise @code{#f}.")
1bbd0b84 480#define FUNC_NAME s_scm_status_exit_val
67ec3667 481{
e67dc2be
JB
482 int lstatus;
483
3b3b36dd 484 SCM_VALIDATE_INUM (1,status);
e67dc2be
JB
485
486 /* On Ultrix, the WIF... macros assume their argument is an lvalue;
487 go figure. SCM_INUM does not yield an lvalue. */
488 lstatus = SCM_INUM (status);
489 if (WIFEXITED (lstatus))
490 return (SCM_MAKINUM (WEXITSTATUS (lstatus)));
67ec3667
GH
491 else
492 return SCM_BOOL_F;
493}
1bbd0b84 494#undef FUNC_NAME
e67dc2be 495
a1ec6916 496SCM_DEFINE (scm_status_term_sig, "status:term-sig", 1, 0, 0,
1bbd0b84 497 (SCM status),
1e6808ea
MG
498 "Return the signal number which terminated the process, if any,\n"
499 "otherwise @code{#f}.")
1bbd0b84 500#define FUNC_NAME s_scm_status_term_sig
67ec3667 501{
e67dc2be
JB
502 int lstatus;
503
3b3b36dd 504 SCM_VALIDATE_INUM (1,status);
e67dc2be
JB
505
506 lstatus = SCM_INUM (status);
507 if (WIFSIGNALED (lstatus))
508 return SCM_MAKINUM (WTERMSIG (lstatus));
67ec3667
GH
509 else
510 return SCM_BOOL_F;
511}
1bbd0b84 512#undef FUNC_NAME
0f2d19dd 513
a1ec6916 514SCM_DEFINE (scm_status_stop_sig, "status:stop-sig", 1, 0, 0,
1bbd0b84 515 (SCM status),
1e6808ea
MG
516 "Return the signal number which stopped the process, if any,\n"
517 "otherwise @code{#f}.")
1bbd0b84 518#define FUNC_NAME s_scm_status_stop_sig
67ec3667 519{
e67dc2be
JB
520 int lstatus;
521
3b3b36dd 522 SCM_VALIDATE_INUM (1,status);
e67dc2be
JB
523
524 lstatus = SCM_INUM (status);
525 if (WIFSTOPPED (lstatus))
526 return SCM_MAKINUM (WSTOPSIG (lstatus));
67ec3667
GH
527 else
528 return SCM_BOOL_F;
529}
1bbd0b84 530#undef FUNC_NAME
0f2d19dd 531
a1ec6916 532SCM_DEFINE (scm_getppid, "getppid", 0, 0, 0,
1bbd0b84 533 (),
1e6808ea
MG
534 "Return an integer representing the process ID of the parent\n"
535 "process.")
1bbd0b84 536#define FUNC_NAME s_scm_getppid
0f2d19dd
JB
537{
538 return SCM_MAKINUM (0L + getppid ());
539}
1bbd0b84 540#undef FUNC_NAME
0f2d19dd
JB
541
542
543
a1ec6916 544SCM_DEFINE (scm_getuid, "getuid", 0, 0, 0,
1bbd0b84 545 (),
1e6808ea 546 "Return an integer representing the current real user ID.")
1bbd0b84 547#define FUNC_NAME s_scm_getuid
0f2d19dd
JB
548{
549 return SCM_MAKINUM (0L + getuid ());
550}
1bbd0b84 551#undef FUNC_NAME
0f2d19dd
JB
552
553
554
a1ec6916 555SCM_DEFINE (scm_getgid, "getgid", 0, 0, 0,
1bbd0b84 556 (),
1e6808ea 557 "Return an integer representing the current real group ID.")
1bbd0b84 558#define FUNC_NAME s_scm_getgid
0f2d19dd
JB
559{
560 return SCM_MAKINUM (0L + getgid ());
561}
1bbd0b84 562#undef FUNC_NAME
0f2d19dd
JB
563
564
565
a1ec6916 566SCM_DEFINE (scm_geteuid, "geteuid", 0, 0, 0,
1bbd0b84 567 (),
1e6808ea 568 "Return an integer representing the current effective user ID.\n"
b380b885 569 "If the system does not support effective IDs, then the real ID\n"
1e6808ea
MG
570 "is returned. @code{(feature? 'EIDs)} reports whether the\n"
571 "system supports effective IDs.")
1bbd0b84 572#define FUNC_NAME s_scm_geteuid
0f2d19dd
JB
573{
574#ifdef HAVE_GETEUID
575 return SCM_MAKINUM (0L + geteuid ());
576#else
577 return SCM_MAKINUM (0L + getuid ());
578#endif
579}
1bbd0b84 580#undef FUNC_NAME
0f2d19dd
JB
581
582
583
a1ec6916 584SCM_DEFINE (scm_getegid, "getegid", 0, 0, 0,
1bbd0b84 585 (),
1e6808ea 586 "Return an integer representing the current effective group ID.\n"
b380b885 587 "If the system does not support effective IDs, then the real ID\n"
1e6808ea
MG
588 "is returned. @code{(feature? 'EIDs)} reports whether the\n"
589 "system supports effective IDs.")
1bbd0b84 590#define FUNC_NAME s_scm_getegid
0f2d19dd
JB
591{
592#ifdef HAVE_GETEUID
593 return SCM_MAKINUM (0L + getegid ());
594#else
595 return SCM_MAKINUM (0L + getgid ());
596#endif
597}
1bbd0b84 598#undef FUNC_NAME
0f2d19dd
JB
599
600
a1ec6916 601SCM_DEFINE (scm_setuid, "setuid", 1, 0, 0,
1bbd0b84 602 (SCM id),
b380b885
MD
603 "Sets both the real and effective user IDs to the integer @var{id}, provided\n"
604 "the process has appropriate privileges.\n"
605 "The return value is unspecified.")
1bbd0b84 606#define FUNC_NAME s_scm_setuid
0f2d19dd 607{
3b3b36dd 608 SCM_VALIDATE_INUM (1,id);
02b754d3 609 if (setuid (SCM_INUM (id)) != 0)
1bbd0b84 610 SCM_SYSERROR;
02b754d3 611 return SCM_UNSPECIFIED;
0f2d19dd 612}
1bbd0b84 613#undef FUNC_NAME
0f2d19dd 614
a1ec6916 615SCM_DEFINE (scm_setgid, "setgid", 1, 0, 0,
1bbd0b84 616 (SCM id),
b380b885
MD
617 "Sets both the real and effective group IDs to the integer @var{id}, provided\n"
618 "the process has appropriate privileges.\n"
619 "The return value is unspecified.")
1bbd0b84 620#define FUNC_NAME s_scm_setgid
0f2d19dd 621{
3b3b36dd 622 SCM_VALIDATE_INUM (1,id);
02b754d3 623 if (setgid (SCM_INUM (id)) != 0)
1bbd0b84 624 SCM_SYSERROR;
02b754d3 625 return SCM_UNSPECIFIED;
0f2d19dd 626}
1bbd0b84 627#undef FUNC_NAME
0f2d19dd 628
a1ec6916 629SCM_DEFINE (scm_seteuid, "seteuid", 1, 0, 0,
1bbd0b84 630 (SCM id),
b380b885
MD
631 "Sets the effective user ID to the integer @var{id}, provided the process\n"
632 "has appropriate privileges. If effective IDs are not supported, the\n"
633 "real ID is set instead -- @code{(feature? 'EIDs)} reports whether the\n"
634 "system supports effective IDs.\n"
635 "The return value is unspecified.")
1bbd0b84 636#define FUNC_NAME s_scm_seteuid
0f2d19dd 637{
02b754d3
GH
638 int rv;
639
3b3b36dd 640 SCM_VALIDATE_INUM (1,id);
0f2d19dd 641#ifdef HAVE_SETEUID
02b754d3 642 rv = seteuid (SCM_INUM (id));
0f2d19dd 643#else
02b754d3 644 rv = setuid (SCM_INUM (id));
0f2d19dd 645#endif
02b754d3 646 if (rv != 0)
1bbd0b84 647 SCM_SYSERROR;
02b754d3 648 return SCM_UNSPECIFIED;
0f2d19dd 649}
1bbd0b84 650#undef FUNC_NAME
0f2d19dd 651
0e958795 652#ifdef HAVE_SETEGID
a1ec6916 653SCM_DEFINE (scm_setegid, "setegid", 1, 0, 0,
1bbd0b84 654 (SCM id),
b380b885
MD
655 "Sets the effective group ID to the integer @var{id}, provided the process\n"
656 "has appropriate privileges. If effective IDs are not supported, the\n"
657 "real ID is set instead -- @code{(feature? 'EIDs)} reports whether the\n"
658 "system supports effective IDs.\n"
659 "The return value is unspecified.")
1bbd0b84 660#define FUNC_NAME s_scm_setegid
0f2d19dd 661{
02b754d3
GH
662 int rv;
663
3b3b36dd 664 SCM_VALIDATE_INUM (1,id);
0f2d19dd 665#ifdef HAVE_SETEUID
02b754d3 666 rv = setegid (SCM_INUM (id));
0f2d19dd 667#else
02b754d3 668 rv = setgid (SCM_INUM (id));
0f2d19dd 669#endif
02b754d3 670 if (rv != 0)
1bbd0b84 671 SCM_SYSERROR;
02b754d3
GH
672 return SCM_UNSPECIFIED;
673
0f2d19dd 674}
1bbd0b84 675#undef FUNC_NAME
0e958795 676#endif
0f2d19dd 677
a1ec6916 678SCM_DEFINE (scm_getpgrp, "getpgrp", 0, 0, 0,
1bbd0b84 679 (),
1e6808ea 680 "Return an integer representing the current process group ID.\n"
b380b885 681 "This is the POSIX definition, not BSD.")
1bbd0b84 682#define FUNC_NAME s_scm_getpgrp
0f2d19dd
JB
683{
684 int (*fn)();
4625e44f 685 fn = (int (*) ()) getpgrp;
0f2d19dd
JB
686 return SCM_MAKINUM (fn (0));
687}
1bbd0b84 688#undef FUNC_NAME
0f2d19dd 689
f25f761d 690#ifdef HAVE_SETPGID
a1ec6916 691SCM_DEFINE (scm_setpgid, "setpgid", 2, 0, 0,
1bbd0b84 692 (SCM pid, SCM pgid),
b380b885
MD
693 "Move the process @var{pid} into the process group @var{pgid}. @var{pid} or\n"
694 "@var{pgid} must be integers: they can be zero to indicate the ID of the\n"
695 "current process.\n"
696 "Fails on systems that do not support job control.\n"
697 "The return value is unspecified.")
1bbd0b84 698#define FUNC_NAME s_scm_setpgid
0f2d19dd 699{
3b3b36dd
GB
700 SCM_VALIDATE_INUM (1,pid);
701 SCM_VALIDATE_INUM (2,pgid);
02b754d3
GH
702 /* FIXME(?): may be known as setpgrp. */
703 if (setpgid (SCM_INUM (pid), SCM_INUM (pgid)) != 0)
1bbd0b84 704 SCM_SYSERROR;
02b754d3 705 return SCM_UNSPECIFIED;
0f2d19dd 706}
1bbd0b84 707#undef FUNC_NAME
f25f761d 708#endif /* HAVE_SETPGID */
0f2d19dd 709
f25f761d 710#ifdef HAVE_SETSID
a1ec6916 711SCM_DEFINE (scm_setsid, "setsid", 0, 0, 0,
1bbd0b84 712 (),
b380b885
MD
713 "Creates a new session. The current process becomes the session leader\n"
714 "and is put in a new process group. The process will be detached\n"
715 "from its controlling terminal if it has one.\n"
716 "The return value is an integer representing the new process group ID.")
1bbd0b84 717#define FUNC_NAME s_scm_setsid
0f2d19dd
JB
718{
719 pid_t sid = setsid ();
02b754d3 720 if (sid == -1)
1bbd0b84 721 SCM_SYSERROR;
02b754d3 722 return SCM_UNSPECIFIED;
0f2d19dd 723}
1bbd0b84 724#undef FUNC_NAME
f25f761d 725#endif /* HAVE_SETSID */
0f2d19dd 726
a1ec6916 727SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
1bbd0b84 728 (SCM port),
1e6808ea
MG
729 "Return a string with the name of the serial terminal device\n"
730 "underlying @var{port}.")
1bbd0b84 731#define FUNC_NAME s_scm_ttyname
0f2d19dd
JB
732{
733 char *ans;
734 int fd;
78446828
MV
735
736 port = SCM_COERCE_OUTPORT (port);
3b3b36dd 737 SCM_VALIDATE_OPPORT (1,port);
a98bddfd 738 if (!SCM_FPORTP (port))
0f2d19dd 739 return SCM_BOOL_F;
ee149d03 740 fd = SCM_FPORT_FDES (port);
02b754d3
GH
741 SCM_SYSCALL (ans = ttyname (fd));
742 if (!ans)
1bbd0b84 743 SCM_SYSERROR;
0f2d19dd 744 /* ans could be overwritten by another call to ttyname */
02b754d3 745 return (scm_makfrom0str (ans));
0f2d19dd 746}
1bbd0b84 747#undef FUNC_NAME
0f2d19dd 748
f25f761d 749#ifdef HAVE_CTERMID
a1ec6916 750SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
1bbd0b84 751 (),
1e6808ea
MG
752 "Return a string containing the file name of the controlling\n"
753 "terminal for the current process.")
1bbd0b84 754#define FUNC_NAME s_scm_ctermid
0f2d19dd
JB
755{
756 char *result = ctermid (NULL);
02b754d3 757 if (*result == '\0')
1bbd0b84 758 SCM_SYSERROR;
02b754d3 759 return scm_makfrom0str (result);
0f2d19dd 760}
1bbd0b84 761#undef FUNC_NAME
f25f761d 762#endif /* HAVE_CTERMID */
0f2d19dd 763
f25f761d 764#ifdef HAVE_TCGETPGRP
a1ec6916 765SCM_DEFINE (scm_tcgetpgrp, "tcgetpgrp", 1, 0, 0,
1bbd0b84 766 (SCM port),
1e6808ea
MG
767 "Return the process group ID of the foreground process group\n"
768 "associated with the terminal open on the file descriptor\n"
769 "underlying @var{port}.\n"
770 "\n"
b380b885
MD
771 "If there is no foreground process group, the return value is a\n"
772 "number greater than 1 that does not match the process group ID\n"
773 "of any existing process group. This can happen if all of the\n"
774 "processes in the job that was formerly the foreground job have\n"
775 "terminated, and no other job has yet been moved into the\n"
776 "foreground.")
1bbd0b84 777#define FUNC_NAME s_scm_tcgetpgrp
0f2d19dd
JB
778{
779 int fd;
780 pid_t pgid;
78446828
MV
781
782 port = SCM_COERCE_OUTPORT (port);
783
3b3b36dd 784 SCM_VALIDATE_OPFPORT (1,port);
ee149d03
JB
785 fd = SCM_FPORT_FDES (port);
786 if ((pgid = tcgetpgrp (fd)) == -1)
1bbd0b84 787 SCM_SYSERROR;
02b754d3 788 return SCM_MAKINUM (pgid);
1bbd0b84
GB
789}
790#undef FUNC_NAME
f25f761d 791#endif /* HAVE_TCGETPGRP */
0f2d19dd 792
f25f761d 793#ifdef HAVE_TCSETPGRP
a1ec6916 794SCM_DEFINE (scm_tcsetpgrp, "tcsetpgrp", 2, 0, 0,
1bbd0b84 795 (SCM port, SCM pgid),
b380b885
MD
796 "Set the foreground process group ID for the terminal used by the file\n"
797 "descriptor underlying @var{port} to the integer @var{pgid}.\n"
798 "The calling process\n"
799 "must be a member of the same session as @var{pgid} and must have the same\n"
800 "controlling terminal. The return value is unspecified.")
1bbd0b84 801#define FUNC_NAME s_scm_tcsetpgrp
0f2d19dd
JB
802{
803 int fd;
78446828
MV
804
805 port = SCM_COERCE_OUTPORT (port);
806
3b3b36dd
GB
807 SCM_VALIDATE_OPFPORT (1,port);
808 SCM_VALIDATE_INUM (2,pgid);
ee149d03
JB
809 fd = SCM_FPORT_FDES (port);
810 if (tcsetpgrp (fd, SCM_INUM (pgid)) == -1)
1bbd0b84 811 SCM_SYSERROR;
02b754d3 812 return SCM_UNSPECIFIED;
1bbd0b84
GB
813}
814#undef FUNC_NAME
f25f761d 815#endif /* HAVE_TCSETPGRP */
0f2d19dd 816
a6d9e5ab
DH
817/* Create a new C argv array from a scheme list of strings. */
818/* Dirk:FIXME:: A quite similar function is implemented in dynl.c */
819/* Dirk:FIXME:: In case of assertion errors, we get memory leaks */
1cc91f1b 820
0f2d19dd 821static char **
a6d9e5ab 822scm_convert_exec_args (SCM args, int argn, const char *subr)
0f2d19dd 823{
a6d9e5ab
DH
824 char **argv;
825 int argc;
0f2d19dd 826 int i;
6afcd3b2 827
a6d9e5ab
DH
828 argc = scm_ilength (args);
829 SCM_ASSERT (argc >= 0, args, argn, subr);
830 argv = (char **) scm_must_malloc ((argc + 1) * sizeof (char *), subr);
af45e3b0 831 for (i = 0; !SCM_NULLP (args); args = SCM_CDR (args), ++i)
0f2d19dd 832 {
a6d9e5ab 833 SCM arg = SCM_CAR (args);
0f2d19dd
JB
834 scm_sizet len;
835 char *dst;
836 char *src;
a6d9e5ab
DH
837
838 SCM_ASSERT (SCM_STRINGP (arg), args, argn, subr);
839 len = SCM_STRING_LENGTH (arg);
34f0f2b8 840 src = SCM_STRING_CHARS (arg);
a6d9e5ab
DH
841 dst = (char *) scm_must_malloc (len + 1, subr);
842 memcpy (dst, src, len);
843 dst[len] = 0;
844 argv[i] = dst;
0f2d19dd 845 }
a6d9e5ab
DH
846 argv[i] = 0;
847 return argv;
0f2d19dd
JB
848}
849
a1ec6916 850SCM_DEFINE (scm_execl, "execl", 1, 0, 1,
1bbd0b84 851 (SCM filename, SCM args),
b380b885
MD
852 "Executes the file named by @var{path} as a new process image.\n"
853 "The remaining arguments are supplied to the process; from a C program\n"
854 "they are accessable as the @code{argv} argument to @code{main}.\n"
855 "Conventionally the first @var{arg} is the same as @var{path}.\n"
856 "All arguments must be strings. \n\n"
857 "If @var{arg} is missing, @var{path} is executed with a null\n"
858 "argument list, which may have system-dependent side-effects.\n\n"
859 "This procedure is currently implemented using the @code{execv} system\n"
860 "call, but we call it @code{execl} because of its Scheme calling interface.")
1bbd0b84 861#define FUNC_NAME s_scm_execl
0f2d19dd
JB
862{
863 char **execargv;
a6d9e5ab
DH
864 SCM_VALIDATE_STRING (1, filename);
865 SCM_STRING_COERCE_0TERMINATION_X (filename);
1bbd0b84 866 execargv = scm_convert_exec_args (args, SCM_ARG2, FUNC_NAME);
a6d9e5ab 867 execv (SCM_STRING_CHARS (filename), execargv);
1bbd0b84 868 SCM_SYSERROR;
02b754d3
GH
869 /* not reached. */
870 return SCM_BOOL_F;
0f2d19dd 871}
1bbd0b84 872#undef FUNC_NAME
0f2d19dd 873
a1ec6916 874SCM_DEFINE (scm_execlp, "execlp", 1, 0, 1,
1bbd0b84 875 (SCM filename, SCM args),
b380b885
MD
876 "Similar to @code{execl}, however if\n"
877 "@var{filename} does not contain a slash\n"
878 "then the file to execute will be located by searching the\n"
879 "directories listed in the @code{PATH} environment variable.\n\n"
6bcd01fc 880 "This procedure is currently implemented using the @code{execvp} system\n"
b380b885 881 "call, but we call it @code{execlp} because of its Scheme calling interface.")
1bbd0b84 882#define FUNC_NAME s_scm_execlp
0f2d19dd
JB
883{
884 char **execargv;
a6d9e5ab
DH
885 SCM_VALIDATE_STRING (1, filename);
886 SCM_STRING_COERCE_0TERMINATION_X (filename);
1bbd0b84 887 execargv = scm_convert_exec_args (args, SCM_ARG2, FUNC_NAME);
a6d9e5ab 888 execvp (SCM_STRING_CHARS (filename), execargv);
1bbd0b84 889 SCM_SYSERROR;
02b754d3
GH
890 /* not reached. */
891 return SCM_BOOL_F;
0f2d19dd 892}
1bbd0b84 893#undef FUNC_NAME
0f2d19dd 894
6afcd3b2 895static char **
3eeba8d4 896environ_list_to_c (SCM envlist, int arg, const char *proc)
6afcd3b2
GH
897{
898 int num_strings;
899 char **result;
a6d9e5ab 900 int i;
6afcd3b2 901
6afcd3b2 902 num_strings = scm_ilength (envlist);
a6d9e5ab 903 SCM_ASSERT (num_strings >= 0, envlist, arg, proc);
6afcd3b2
GH
904 result = (char **) malloc ((num_strings + 1) * sizeof (char *));
905 if (result == NULL)
906 scm_memory_error (proc);
a6d9e5ab 907 for (i = 0; !SCM_NULLP (envlist); ++i, envlist = SCM_CDR (envlist))
6afcd3b2 908 {
a6d9e5ab 909 SCM str = SCM_CAR (envlist);
6afcd3b2
GH
910 int len;
911 char *src;
912
a6d9e5ab
DH
913 SCM_ASSERT (SCM_STRINGP (str), envlist, arg, proc);
914 len = SCM_STRING_LENGTH (str);
34f0f2b8 915 src = SCM_STRING_CHARS (str);
a6d9e5ab 916 result[i] = malloc (len + 1);
6afcd3b2
GH
917 if (result[i] == NULL)
918 scm_memory_error (proc);
a6d9e5ab
DH
919 memcpy (result[i], src, len);
920 result[i][len] = 0;
6afcd3b2
GH
921 }
922 result[i] = 0;
6afcd3b2
GH
923 return result;
924}
925
a1ec6916 926SCM_DEFINE (scm_execle, "execle", 2, 0, 1,
1bbd0b84 927 (SCM filename, SCM env, SCM args),
b380b885
MD
928 "Similar to @code{execl}, but the environment of the new process is\n"
929 "specified by @var{env}, which must be a list of strings as returned by the\n"
930 "@code{environ} procedure.\n\n"
931 "This procedure is currently implemented using the @code{execve} system\n"
932 "call, but we call it @code{execle} because of its Scheme calling interface.")
1bbd0b84 933#define FUNC_NAME s_scm_execle
6afcd3b2
GH
934{
935 char **execargv;
936 char **exec_env;
937
a6d9e5ab
DH
938 SCM_VALIDATE_STRING (1, filename);
939 SCM_STRING_COERCE_0TERMINATION_X (filename);
6afcd3b2 940
1bbd0b84
GB
941 execargv = scm_convert_exec_args (args, SCM_ARG1, FUNC_NAME);
942 exec_env = environ_list_to_c (env, SCM_ARG2, FUNC_NAME);
a6d9e5ab 943 execve (SCM_STRING_CHARS (filename), execargv, exec_env);
1bbd0b84 944 SCM_SYSERROR;
6afcd3b2
GH
945 /* not reached. */
946 return SCM_BOOL_F;
947}
1bbd0b84 948#undef FUNC_NAME
6afcd3b2 949
a1ec6916 950SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
1bbd0b84 951 (),
b380b885
MD
952 "Creates a new \"child\" process by duplicating the current \"parent\" process.\n"
953 "In the child the return value is 0. In the parent the return value is\n"
954 "the integer process ID of the child.\n\n"
955 "This procedure has been renamed from @code{fork} to avoid a naming conflict\n"
956 "with the scsh fork.")
1bbd0b84 957#define FUNC_NAME s_scm_fork
0f2d19dd 958{
bab0f4e5 959 int pid;
0f2d19dd
JB
960 pid = fork ();
961 if (pid == -1)
1bbd0b84 962 SCM_SYSERROR;
02b754d3 963 return SCM_MAKINUM (0L+pid);
0f2d19dd 964}
1bbd0b84 965#undef FUNC_NAME
0f2d19dd 966
f25f761d 967#ifdef HAVE_UNAME
a1ec6916 968SCM_DEFINE (scm_uname, "uname", 0, 0, 0,
1bbd0b84 969 (),
1e6808ea
MG
970 "Return an object with some information about the computer\n"
971 "system the program is running on.")
1bbd0b84 972#define FUNC_NAME s_scm_uname
0f2d19dd 973{
0f2d19dd 974 struct utsname buf;
00ffa0e7 975 SCM ans = scm_c_make_vector (5, SCM_UNSPECIFIED);
0f2d19dd 976 SCM *ve = SCM_VELTS (ans);
e1a191a8 977 if (uname (&buf) < 0)
1bbd0b84 978 SCM_SYSERROR;
0f2d19dd
JB
979 ve[0] = scm_makfrom0str (buf.sysname);
980 ve[1] = scm_makfrom0str (buf.nodename);
981 ve[2] = scm_makfrom0str (buf.release);
982 ve[3] = scm_makfrom0str (buf.version);
983 ve[4] = scm_makfrom0str (buf.machine);
984/*
02b754d3 985 a linux special?
0f2d19dd
JB
986 ve[5] = scm_makfrom0str (buf.domainname);
987*/
988 return ans;
0f2d19dd 989}
1bbd0b84 990#undef FUNC_NAME
f25f761d 991#endif /* HAVE_UNAME */
0f2d19dd 992
a1ec6916 993SCM_DEFINE (scm_environ, "environ", 0, 1, 0,
1bbd0b84 994 (SCM env),
1e6808ea
MG
995 "If @var{env} is omitted, return the current environment (in the\n"
996 "Unix sense) as a list of strings. Otherwise set the current\n"
997 "environment, which is also the default environment for child\n"
998 "processes, to the supplied list of strings. Each member of\n"
999 "@var{env} should be of the form @code{NAME=VALUE} and values of\n"
1000 "@code{NAME} should not be duplicated. If @var{env} is supplied\n"
1001 "then the return value is unspecified.")
1bbd0b84 1002#define FUNC_NAME s_scm_environ
0f2d19dd
JB
1003{
1004 if (SCM_UNBNDP (env))
1005 return scm_makfromstrs (-1, environ);
1006 else
1007 {
0f2d19dd 1008 char **new_environ;
6afcd3b2 1009
1bbd0b84 1010 new_environ = environ_list_to_c (env, SCM_ARG1, FUNC_NAME);
0f2d19dd
JB
1011 /* Free the old environment, except when called for the first
1012 * time.
1013 */
1014 {
1015 char **ep;
1016 static int first = 1;
1017 if (!first)
1018 {
1019 for (ep = environ; *ep != NULL; ep++)
19468eff
GH
1020 free (*ep);
1021 free ((char *) environ);
0f2d19dd
JB
1022 }
1023 first = 0;
1024 }
1025 environ = new_environ;
1026 return SCM_UNSPECIFIED;
1027 }
1028}
1bbd0b84 1029#undef FUNC_NAME
0f2d19dd 1030
9ee5fce4
MD
1031#ifdef L_tmpnam
1032
a1ec6916 1033SCM_DEFINE (scm_tmpnam, "tmpnam", 0, 0, 0,
1bbd0b84 1034 (),
1e6808ea
MG
1035 "Return a name in the file system that does not match any\n"
1036 "existing file. However there is no guarantee that another\n"
1037 "process will not create the file after @code{tmpnam} is called.\n"
1038 "Care should be taken if opening the file, e.g., use the\n"
1039 "@code{O_EXCL} open flag or use @code{mkstemp!} instead.")
1bbd0b84 1040#define FUNC_NAME s_scm_tmpnam
9ee5fce4
MD
1041{
1042 char name[L_tmpnam];
6d163216
GH
1043 char *rv;
1044
1045 SCM_SYSCALL (rv = tmpnam (name));
1046 if (rv == NULL)
1047 /* not SCM_SYSERROR since errno probably not set. */
1048 SCM_MISC_ERROR ("tmpnam failed", SCM_EOL);
9ee5fce4
MD
1049 return scm_makfrom0str (name);
1050}
0f981281 1051#undef FUNC_NAME
0f2d19dd 1052
1bbd0b84 1053#endif
1cc91f1b 1054
6d163216
GH
1055SCM_DEFINE (scm_mkstemp, "mkstemp!", 1, 0, 0,
1056 (SCM tmpl),
1e6808ea
MG
1057 "Create a new unique file in the file system and returns a new\n"
1058 "buffered port open for reading and writing to the file.\n"
1059 "@var{tmpl} is a string specifying where the file should be\n"
1060 "created: it must end with @code{XXXXXX} and will be changed in\n"
1061 "place to return the name of the temporary file.")
6d163216
GH
1062#define FUNC_NAME s_scm_mkstemp
1063{
1064 char *c_tmpl;
1065 int rv;
1066
1067 SCM_STRING_COERCE_0TERMINATION_X (tmpl);
1068 SCM_VALIDATE_STRING_COPY (1, tmpl, c_tmpl);
1069 SCM_SYSCALL (rv = mkstemp (c_tmpl));
1070 if (rv == -1)
1071 SCM_SYSERROR;
1072 return scm_fdes_to_port (rv, "w+", tmpl);
1073}
1074#undef FUNC_NAME
1075
a1ec6916 1076SCM_DEFINE (scm_utime, "utime", 1, 2, 0,
1bbd0b84 1077 (SCM pathname, SCM actime, SCM modtime),
1e6808ea
MG
1078 "@code{utime} sets the access and modification times for the\n"
1079 "file named by @var{path}. If @var{actime} or @var{modtime} is\n"
1080 "not supplied, then the current time is used. @var{actime} and\n"
1081 "@var{modtime} must be integer time values as returned by the\n"
1082 "@code{current-time} procedure.\n"
1083 "@lisp\n"
b380b885 1084 "(utime \"foo\" (- (current-time) 3600))\n"
1e6808ea
MG
1085 "@end lisp\n"
1086 "will set the access time to one hour in the past and the\n"
1087 "modification time to the current time.")
1bbd0b84 1088#define FUNC_NAME s_scm_utime
0f2d19dd
JB
1089{
1090 int rv;
1091 struct utimbuf utm_tmp;
1092
a6d9e5ab
DH
1093 SCM_VALIDATE_STRING (1, pathname);
1094 SCM_STRING_COERCE_0TERMINATION_X (pathname);
0f2d19dd
JB
1095 if (SCM_UNBNDP (actime))
1096 SCM_SYSCALL (time (&utm_tmp.actime));
1097 else
e4b265d8 1098 utm_tmp.actime = SCM_NUM2ULONG (2, actime);
0f2d19dd
JB
1099
1100 if (SCM_UNBNDP (modtime))
1101 SCM_SYSCALL (time (&utm_tmp.modtime));
1102 else
e4b265d8 1103 utm_tmp.modtime = SCM_NUM2ULONG (3, modtime);
0f2d19dd 1104
a6d9e5ab 1105 SCM_SYSCALL (rv = utime (SCM_STRING_CHARS (pathname), &utm_tmp));
02b754d3 1106 if (rv != 0)
1bbd0b84 1107 SCM_SYSERROR;
02b754d3 1108 return SCM_UNSPECIFIED;
0f2d19dd 1109}
1bbd0b84 1110#undef FUNC_NAME
0f2d19dd 1111
a1ec6916 1112SCM_DEFINE (scm_access, "access?", 2, 0, 0,
1bbd0b84 1113 (SCM path, SCM how),
1e6808ea
MG
1114 "Return @code{#t} if @var{path} corresponds to an existing file\n"
1115 "and the current process has the type of access specified by\n"
1116 "@var{how}, otherwise @code{#f}. @var{how} should be specified\n"
1117 "using the values of the variables listed below. Multiple\n"
1118 "values can be combined using a bitwise or, in which case\n"
1119 "@code{#t} will only be returned if all accesses are granted.\n"
1120 "\n"
1121 "Permissions are checked using the real id of the current\n"
1122 "process, not the effective id, although it's the effective id\n"
1123 "which determines whether the access would actually be granted.\n"
1124 "\n"
b380b885
MD
1125 "@defvar R_OK\n"
1126 "test for read permission.\n"
1127 "@end defvar\n"
1128 "@defvar W_OK\n"
1129 "test for write permission.\n"
1130 "@end defvar\n"
1131 "@defvar X_OK\n"
1132 "test for execute permission.\n"
1133 "@end defvar\n"
1134 "@defvar F_OK\n"
1135 "test for existence of the file.\n"
1136 "@end defvar")
1bbd0b84 1137#define FUNC_NAME s_scm_access
0f2d19dd
JB
1138{
1139 int rv;
1140
a6d9e5ab
DH
1141 SCM_VALIDATE_STRING (1, path);
1142 SCM_STRING_COERCE_0TERMINATION_X (path);
1143 SCM_VALIDATE_INUM (2, how);
1144 rv = access (SCM_STRING_CHARS (path), SCM_INUM (how));
156dcb09 1145 return SCM_NEGATE_BOOL(rv);
0f2d19dd 1146}
1bbd0b84 1147#undef FUNC_NAME
0f2d19dd 1148
a1ec6916 1149SCM_DEFINE (scm_getpid, "getpid", 0, 0, 0,
1bbd0b84 1150 (),
1e6808ea 1151 "Return an integer representing the current process ID.")
1bbd0b84 1152#define FUNC_NAME s_scm_getpid
0f2d19dd
JB
1153{
1154 return SCM_MAKINUM ((unsigned long) getpid ());
1155}
1bbd0b84 1156#undef FUNC_NAME
0f2d19dd 1157
a1ec6916 1158SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
1bbd0b84 1159 (SCM str),
b380b885
MD
1160 "Modifies the environment of the current process, which is\n"
1161 "also the default environment inherited by child processes.\n\n"
1162 "If @var{string} is of the form @code{NAME=VALUE} then it will be written\n"
1163 "directly into the environment, replacing any existing environment string\n"
1164 "with\n"
1165 "name matching @code{NAME}. If @var{string} does not contain an equal\n"
1166 "sign, then any existing string with name matching @var{string} will\n"
1167 "be removed.\n\n"
1168 "The return value is unspecified.")
1bbd0b84 1169#define FUNC_NAME s_scm_putenv
0f2d19dd 1170{
f93ddd39 1171 int rv;
19468eff 1172 char *ptr;
f93ddd39 1173
9fd38a3d 1174 SCM_VALIDATE_STRING (1, str);
19468eff 1175 /* must make a new copy to be left in the environment, safe from gc. */
9fd38a3d 1176 ptr = malloc (SCM_STRING_LENGTH (str) + 1);
19468eff 1177 if (ptr == NULL)
1bbd0b84 1178 SCM_MEMORY_ERROR;
34f0f2b8 1179 strncpy (ptr, SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str));
9fd38a3d 1180 ptr[SCM_STRING_LENGTH (str)] = 0;
19468eff 1181 rv = putenv (ptr);
f93ddd39 1182 if (rv < 0)
1bbd0b84 1183 SCM_SYSERROR;
f93ddd39 1184 return SCM_UNSPECIFIED;
0f2d19dd 1185}
1bbd0b84 1186#undef FUNC_NAME
0f2d19dd 1187
f25f761d 1188#ifdef HAVE_SETLOCALE
a1ec6916 1189SCM_DEFINE (scm_setlocale, "setlocale", 1, 1, 0,
1bbd0b84 1190 (SCM category, SCM locale),
1e6808ea
MG
1191 "If @var{locale} is omitted, return the current value of the\n"
1192 "specified locale category as a system-dependent string.\n"
1193 "@var{category} should be specified using the values\n"
1194 "@code{LC_COLLATE}, @code{LC_ALL} etc.\n"
1195 "\n"
1196 "Otherwise the specified locale category is set to the string\n"
1197 "@var{locale} and the new value is returned as a\n"
1198 "system-dependent string. If @var{locale} is an empty string,\n"
1199 "the locale will be set using envirionment variables.")
1bbd0b84 1200#define FUNC_NAME s_scm_setlocale
0f2d19dd 1201{
0f2d19dd
JB
1202 char *clocale;
1203 char *rv;
1204
3b3b36dd 1205 SCM_VALIDATE_INUM (1,category);
0f2d19dd
JB
1206 if (SCM_UNBNDP (locale))
1207 {
1208 clocale = NULL;
1209 }
1210 else
1211 {
a6d9e5ab
DH
1212 SCM_VALIDATE_STRING (2, locale);
1213 SCM_STRING_COERCE_0TERMINATION_X (locale);
1214 clocale = SCM_STRING_CHARS (locale);
0f2d19dd
JB
1215 }
1216
1217 rv = setlocale (SCM_INUM (category), clocale);
02b754d3 1218 if (rv == NULL)
1bbd0b84 1219 SCM_SYSERROR;
02b754d3 1220 return scm_makfrom0str (rv);
0f2d19dd 1221}
1bbd0b84 1222#undef FUNC_NAME
f25f761d 1223#endif /* HAVE_SETLOCALE */
0f2d19dd 1224
f25f761d 1225#ifdef HAVE_MKNOD
a1ec6916 1226SCM_DEFINE (scm_mknod, "mknod", 4, 0, 0,
1bbd0b84 1227 (SCM path, SCM type, SCM perms, SCM dev),
b380b885
MD
1228 "Creates a new special file, such as a file corresponding to a device.\n"
1229 "@var{path} specifies the name of the file. @var{type} should\n"
1230 "be one of the following symbols:\n"
1231 "regular, directory, symlink, block-special, char-special,\n"
1232 "fifo, or socket. @var{perms} (an integer) specifies the file permissions.\n"
1233 "@var{dev} (an integer) specifies which device the special file refers\n"
1234 "to. Its exact interpretation depends on the kind of special file\n"
1235 "being created.\n\n"
1236 "E.g.,\n"
1e6808ea 1237 "@lisp\n"
09831f94 1238 "(mknod \"/dev/fd0\" 'block-special #o660 (+ (* 2 256) 2))\n"
1e6808ea 1239 "@end lisp\n\n"
a3c8b9fc 1240 "The return value is unspecified.")
1bbd0b84 1241#define FUNC_NAME s_scm_mknod
0f2d19dd 1242{
0f2d19dd 1243 int val;
19468eff 1244 char *p;
82a76bdf 1245 int ctype = 0;
19468eff 1246
a6d9e5ab 1247 SCM_VALIDATE_STRING (1, path);
3b3b36dd
GB
1248 SCM_VALIDATE_SYMBOL (2,type);
1249 SCM_VALIDATE_INUM (3,perms);
1250 SCM_VALIDATE_INUM (4,dev);
a6d9e5ab 1251 SCM_STRING_COERCE_0TERMINATION_X (path);
19468eff 1252
86c991c2 1253 p = SCM_SYMBOL_CHARS (type);
19468eff
GH
1254 if (strcmp (p, "regular") == 0)
1255 ctype = S_IFREG;
1256 else if (strcmp (p, "directory") == 0)
1257 ctype = S_IFDIR;
1258 else if (strcmp (p, "symlink") == 0)
1259 ctype = S_IFLNK;
1260 else if (strcmp (p, "block-special") == 0)
1261 ctype = S_IFBLK;
1262 else if (strcmp (p, "char-special") == 0)
1263 ctype = S_IFCHR;
1264 else if (strcmp (p, "fifo") == 0)
1265 ctype = S_IFIFO;
e655d034 1266#ifdef S_IFSOCK
19468eff
GH
1267 else if (strcmp (p, "socket") == 0)
1268 ctype = S_IFSOCK;
e655d034 1269#endif
19468eff 1270 else
1bbd0b84 1271 SCM_OUT_OF_RANGE (2,type);
19468eff 1272
a6d9e5ab
DH
1273 SCM_SYSCALL (val = mknod (SCM_STRING_CHARS (path), ctype | SCM_INUM (perms),
1274 SCM_INUM (dev)));
02b754d3 1275 if (val != 0)
1bbd0b84 1276 SCM_SYSERROR;
02b754d3 1277 return SCM_UNSPECIFIED;
0f2d19dd 1278}
1bbd0b84 1279#undef FUNC_NAME
f25f761d 1280#endif /* HAVE_MKNOD */
0f2d19dd 1281
f25f761d 1282#ifdef HAVE_NICE
a1ec6916 1283SCM_DEFINE (scm_nice, "nice", 1, 0, 0,
1bbd0b84 1284 (SCM incr),
b380b885
MD
1285 "Increment the priority of the current process by @var{incr}. A higher\n"
1286 "priority value means that the process runs less often.\n"
1287 "The return value is unspecified.")
1bbd0b84 1288#define FUNC_NAME s_scm_nice
0f2d19dd 1289{
3b3b36dd 1290 SCM_VALIDATE_INUM (1,incr);
02b754d3 1291 if (nice(SCM_INUM(incr)) != 0)
1bbd0b84 1292 SCM_SYSERROR;
02b754d3 1293 return SCM_UNSPECIFIED;
0f2d19dd 1294}
1bbd0b84 1295#undef FUNC_NAME
f25f761d 1296#endif /* HAVE_NICE */
0f2d19dd 1297
f25f761d 1298#ifdef HAVE_SYNC
a1ec6916 1299SCM_DEFINE (scm_sync, "sync", 0, 0, 0,
1bbd0b84 1300 (),
b380b885
MD
1301 "Flush the operating system disk buffers.\n"
1302 "The return value is unspecified.")
1bbd0b84 1303#define FUNC_NAME s_scm_sync
0f2d19dd 1304{
0f2d19dd 1305 sync();
127ec750 1306 return SCM_UNSPECIFIED;
0f2d19dd 1307}
1bbd0b84 1308#undef FUNC_NAME
f25f761d 1309#endif /* HAVE_SYNC */
0f2d19dd 1310
94e6d793
MG
1311#if HAVE_LIBCRYPT && HAVE_CRYPT_H
1312SCM_DEFINE (scm_crypt, "crypt", 2, 0, 0,
1313 (SCM key, SCM salt),
1314 "Encrypt @var{key} using @var{salt} as the salt value to the\n"
1315 "crypt(3) library call\n")
1316#define FUNC_NAME s_scm_crypt
1317{
1318 char * p;
1319
1320 SCM_VALIDATE_STRING (1, key);
1321 SCM_VALIDATE_STRING (2, salt);
1322 SCM_STRING_COERCE_0TERMINATION_X (key);
1323 SCM_STRING_COERCE_0TERMINATION_X (salt);
1324
1325 p = crypt (SCM_STRING_CHARS (key), SCM_STRING_CHARS (salt));
1326 return scm_makfrom0str (p);
1327}
1328#undef FUNC_NAME
1329#endif /* HAVE_LIBCRYPT && HAVE_CRYPT_H */
1330
1331#if HAVE_CHROOT
1332SCM_DEFINE (scm_chroot, "chroot", 1, 0, 0,
1333 (SCM path),
1334 "Change the root directory to that specified in @var{path}.\n"
1335 "This directory will be used for path names beginning with\n"
1336 "@file{/}. The root directory is inherited by all children\n"
1337 "of the current process. Only the superuser may change the\n"
1338 "root directory.")
1339#define FUNC_NAME s_scm_chroot
1340{
1341 SCM_VALIDATE_STRING (1, path);
1342 SCM_STRING_COERCE_0TERMINATION_X (path);
1343
1344 if (chroot (SCM_STRING_CHARS (path)) == -1)
1345 SCM_SYSERROR;
1346 return SCM_UNSPECIFIED;
1347}
1348#undef FUNC_NAME
1349#endif /* HAVE_CHROOT */
1350
1351#if HAVE_GETLOGIN
1352SCM_DEFINE (scm_getlogin, "getlogin", 0, 0, 0,
1353 (void),
1354 "Return a string containing the name of the user logged in on\n"
1355 "the controlling terminal of the process, or @code{#f} if this\n"
1356 "information cannot be obtained.")
1357#define FUNC_NAME s_scm_getlogin
1358{
1359 char * p;
1360
1361 p = getlogin ();
1362 if (!p || !*p)
1363 return SCM_BOOL_F;
1364 return scm_makfrom0str (p);
1365}
1366#undef FUNC_NAME
1367#endif /* HAVE_GETLOGIN */
1368
1369#if HAVE_CUSERID
1370SCM_DEFINE (scm_cuserid, "cuserid", 0, 0, 0,
1371 (void),
1372 "Return a string containing a user name associated with the\n"
1373 "effective user id of the process. Return @code{#f} if this\n"
1374 "information cannot be obtained.")
1375#define FUNC_NAME s_scm_cuserid
1376{
1377 char * p;
1378
1379 p = cuserid (NULL);
1380 if (!p || !*p)
1381 return SCM_BOOL_F;
1382 return scm_makfrom0str (p);
1383}
1384#undef FUNC_NAME
1385#endif /* HAVE_CUSERID */
1386
1387#if HAVE_GETPRIORITY
1388SCM_DEFINE (scm_getpriority, "getpriority", 2, 0, 0,
1389 (SCM which, SCM who),
1390 "Return the scheduling priority of the process, process group\n"
1391 "or user, as indicated by @var{which} and @var{who}. @var{which}\n"
1392 "is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}\n"
1393 "or @code{PRIO_USER}, and @var{who} is interpreted relative to\n"
1394 "@var{which} (a process identifier for @code{PRIO_PROCESS},\n"
1395 "process group identifier for @code{PRIO_PGRP}, and a user\n"
1396 "identifier for @code{PRIO_USER}. A zero value of @var{who}\n"
1397 "denotes the current process, process group, or user. Return\n"
1398 "the highest priority (lowest numerical value) of any of the\n"
1399 "specified processes.")
1400#define FUNC_NAME s_scm_getpriority
1401{
1402 int cwhich, cwho, ret;
1403
1404 SCM_VALIDATE_INUM_COPY (1, which, cwhich);
1405 SCM_VALIDATE_INUM_COPY (2, who, cwho);
1406
1407 /* We have to clear errno and examine it later, because -1 is a
1408 legal return value for getpriority(). */
1409 errno = 0;
1410 ret = getpriority (cwhich, cwho);
1411 if (errno != 0)
1412 SCM_SYSERROR;
1413 return SCM_MAKINUM (ret);
1414}
1415#undef FUNC_NAME
1416#endif /* HAVE_GETPRIORITY */
1417
1418#if HAVE_SETPRIORITY
1419SCM_DEFINE (scm_setpriority, "setpriority", 3, 0, 0,
1420 (SCM which, SCM who, SCM prio),
1421 "Set the scheduling priority of the process, process group\n"
1422 "or user, as indicated by @var{which} and @var{who}. @var{which}\n"
1423 "is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}\n"
1424 "or @code{PRIO_USER}, and @var{who} is interpreted relative to\n"
1425 "@var{which} (a process identifier for @code{PRIO_PROCESS},\n"
1426 "process group identifier for @code{PRIO_PGRP}, and a user\n"
1427 "identifier for @code{PRIO_USER}. A zero value of @var{who}\n"
1428 "denotes the current process, process group, or user.\n"
1429 "@var{prio} is a value in the range -20 and 20, the default\n"
1430 "priority is 0; lower priorities cause more favorable\n"
1431 "scheduling. Sets the priority of all of the specified\n"
1432 "processes. Only the super-user may lower priorities.\n"
1433 "The return value is not specified.")
1434#define FUNC_NAME s_scm_setpriority
1435{
1436 int cwhich, cwho, cprio;
1437
1438 SCM_VALIDATE_INUM_COPY (1, which, cwhich);
1439 SCM_VALIDATE_INUM_COPY (2, who, cwho);
1440 SCM_VALIDATE_INUM_COPY (3, prio, cprio);
1441
1442 if (setpriority (cwhich, cwho, cprio) == -1)
1443 SCM_SYSERROR;
1444 return SCM_UNSPECIFIED;
1445}
1446#undef FUNC_NAME
1447#endif /* HAVE_SETPRIORITY */
1448
1449#if HAVE_GETPASS
1450SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0,
1451 (SCM prompt),
1452 "Display @var{prompt} to the standard error output and read\n"
1453 "a password from @file{/dev/tty}. If this file is not\n"
1454 "accessible, it reads from standard input. The password may be\n"
1455 "up to 127 characters in length. Additional characters and the\n"
1456 "terminating newline character are discarded. While reading\n"
1457 "the password, echoing and the generation of signals by special\n"
1458 "characters is disabled.")
1459#define FUNC_NAME s_scm_getpass
1460{
1461 char * p;
1462 SCM passwd;
1463
1464 SCM_VALIDATE_STRING (1, prompt);
1465 SCM_STRING_COERCE_0TERMINATION_X (prompt);
1466
1467 p = getpass(SCM_STRING_CHARS (prompt));
1468 passwd = scm_makfrom0str (p);
1469
1470 /* Clear out the password in the static buffer. */
1471 memset (p, 0, strlen (p));
1472
1473 return passwd;
1474}
1475#undef FUNC_NAME
1476#endif /* HAVE_GETPASS */
1477
1478#if HAVE_FLOCK
1479SCM_DEFINE (scm_flock, "flock", 2, 0, 0,
1480 (SCM file, SCM operation),
1481 "Apply or remove an advisory lock on an open file.\n"
1482 "@var{operation} specifies the action to be done:\n"
1483 "@table @code\n"
1484 "@item LOCK_SH\n"
1485 "Shared lock. More than one process may hold a shared lock\n"
1486 "for a given file at a given time.\n"
1487 "@item LOCK_EX\n"
1488 "Exclusive lock. Only one process may hold an exclusive lock\n"
1489 "for a given file at a given time.\n"
1490 "@item LOCK_UN\n"
1491 "Unlock the file.\n"
1492 "@item LOCK_NB\n"
1493 "Don't block when locking. May be specified by bitwise OR'ing\n"
1494 "it to one of the other operations.\n"
1495 "@end table\n"
1496 "The return value is not specified. @var{file} may be an open\n"
1497 "file descriptor or an open file descriptior port.")
1498#define FUNC_NAME s_scm_flock
1499{
1500 int coperation, fdes;
1501
1502 if (SCM_INUMP (file))
1503 fdes = SCM_INUM (file);
1504 else
1505 {
1506 SCM_VALIDATE_OPFPORT (2, file);
1507
1508 fdes = SCM_FPORT_FDES (file);
1509 }
1510 SCM_VALIDATE_INUM_COPY (2, operation, coperation);
1511 if (flock (fdes, coperation) == -1)
1512 SCM_SYSERROR;
1513 return SCM_UNSPECIFIED;
1514}
1515#undef FUNC_NAME
1516#endif /* HAVE_FLOCK */
1517
1518#if HAVE_SETHOSTNAME
1519SCM_DEFINE (scm_sethostname, "sethostname", 1, 0, 0,
1520 (SCM name),
1521 "Set the host name of the current processor to @var{name}. May\n"
1522 "only be used by the superuser. The return value is not\n"
1523 "specified.")
1524#define FUNC_NAME s_scm_sethostname
1525{
1526 SCM_VALIDATE_STRING (1, name);
1527 SCM_STRING_COERCE_0TERMINATION_X (name);
1528
1529 if (sethostname (SCM_STRING_CHARS (name), SCM_STRING_LENGTH (name)) == -1)
1530 SCM_SYSERROR;
1531 return SCM_UNSPECIFIED;
1532}
1533#undef FUNC_NAME
1534#endif /* HAVE_SETHOSTNAME */
1535
1536#if HAVE_GETHOSTNAME
1537SCM_DEFINE (scm_gethostname, "gethostname", 0, 0, 0,
1538 (void),
1539 "Return the host name of the current processor.")
1540#define FUNC_NAME s_scm_gethostname
1541{
a0f9c651
MG
1542 /* 256 is for Solaris, under Linux ENAMETOOLONG is returned if not
1543 large enough. */
1544 int len = 256, res;
94e6d793
MG
1545 char *p = scm_must_malloc (len, "gethostname");
1546 SCM name;
1547
1548 res = gethostname (p, len);
1549 while (res == -1 && errno == ENAMETOOLONG)
1550 {
1551 p = scm_must_realloc (p, len, len * 2, "gethostname");
1552 len *= 2;
1553 res = gethostname (p, len);
1554 }
1555 if (res == -1)
1556 {
1557 scm_must_free (p);
1558 SCM_SYSERROR;
1559 }
1560 name = scm_makfrom0str (p);
1561 scm_must_free (p);
1562 return name;
1563}
1564#undef FUNC_NAME
1565#endif /* HAVE_GETHOSTNAME */
1566
0f2d19dd
JB
1567void
1568scm_init_posix ()
0f2d19dd
JB
1569{
1570 scm_add_feature ("posix");
1571#ifdef HAVE_GETEUID
1572 scm_add_feature ("EIDs");
1573#endif
1574#ifdef WAIT_ANY
86d31dfe 1575 scm_c_define ("WAIT_ANY", SCM_MAKINUM (WAIT_ANY));
0f2d19dd
JB
1576#endif
1577#ifdef WAIT_MYPGRP
86d31dfe 1578 scm_c_define ("WAIT_MYPGRP", SCM_MAKINUM (WAIT_MYPGRP));
0f2d19dd
JB
1579#endif
1580#ifdef WNOHANG
86d31dfe 1581 scm_c_define ("WNOHANG", SCM_MAKINUM (WNOHANG));
0f2d19dd
JB
1582#endif
1583#ifdef WUNTRACED
86d31dfe 1584 scm_c_define ("WUNTRACED", SCM_MAKINUM (WUNTRACED));
0f2d19dd
JB
1585#endif
1586
0f2d19dd 1587 /* access() symbols. */
86d31dfe
MV
1588 scm_c_define ("R_OK", SCM_MAKINUM (R_OK));
1589 scm_c_define ("W_OK", SCM_MAKINUM (W_OK));
1590 scm_c_define ("X_OK", SCM_MAKINUM (X_OK));
1591 scm_c_define ("F_OK", SCM_MAKINUM (F_OK));
0f2d19dd
JB
1592
1593#ifdef LC_COLLATE
86d31dfe 1594 scm_c_define ("LC_COLLATE", SCM_MAKINUM (LC_COLLATE));
0f2d19dd
JB
1595#endif
1596#ifdef LC_CTYPE
86d31dfe 1597 scm_c_define ("LC_CTYPE", SCM_MAKINUM (LC_CTYPE));
0f2d19dd
JB
1598#endif
1599#ifdef LC_MONETARY
86d31dfe 1600 scm_c_define ("LC_MONETARY", SCM_MAKINUM (LC_MONETARY));
0f2d19dd
JB
1601#endif
1602#ifdef LC_NUMERIC
86d31dfe 1603 scm_c_define ("LC_NUMERIC", SCM_MAKINUM (LC_NUMERIC));
0f2d19dd
JB
1604#endif
1605#ifdef LC_TIME
86d31dfe 1606 scm_c_define ("LC_TIME", SCM_MAKINUM (LC_TIME));
0f2d19dd
JB
1607#endif
1608#ifdef LC_MESSAGES
86d31dfe 1609 scm_c_define ("LC_MESSAGES", SCM_MAKINUM (LC_MESSAGES));
0f2d19dd
JB
1610#endif
1611#ifdef LC_ALL
86d31dfe 1612 scm_c_define ("LC_ALL", SCM_MAKINUM (LC_ALL));
0f2d19dd 1613#endif
bd9e24b3 1614#ifdef PIPE_BUF
86d31dfe 1615 scm_c_define ("PIPE_BUF", scm_long2num (PIPE_BUF));
bd9e24b3
GH
1616#endif
1617
94e6d793 1618#ifdef PRIO_PROCESS
86d31dfe 1619 scm_c_define ("PRIO_PROCESS", SCM_MAKINUM (PRIO_PROCESS));
94e6d793
MG
1620#endif
1621#ifdef PRIO_PGRP
86d31dfe 1622 scm_c_define ("PRIO_PGRP", SCM_MAKINUM (PRIO_PGRP));
94e6d793
MG
1623#endif
1624#ifdef PRIO_USER
86d31dfe 1625 scm_c_define ("PRIO_USER", SCM_MAKINUM (PRIO_USER));
94e6d793
MG
1626#endif
1627
1628#ifdef LOCK_SH
86d31dfe 1629 scm_c_define ("LOCK_SH", SCM_MAKINUM (LOCK_SH));
94e6d793
MG
1630#endif
1631#ifdef LOCK_EX
86d31dfe 1632 scm_c_define ("LOCK_EX", SCM_MAKINUM (LOCK_EX));
94e6d793
MG
1633#endif
1634#ifdef LOCK_UN
86d31dfe 1635 scm_c_define ("LOCK_UN", SCM_MAKINUM (LOCK_UN));
94e6d793
MG
1636#endif
1637#ifdef LOCK_NB
86d31dfe 1638 scm_c_define ("LOCK_NB", SCM_MAKINUM (LOCK_NB));
94e6d793
MG
1639#endif
1640
a0599745 1641#include "libguile/cpp_sig_symbols.c"
8dc9439f 1642#ifndef SCM_MAGIC_SNARFER
a0599745 1643#include "libguile/posix.x"
8dc9439f 1644#endif
0f2d19dd 1645}
89e00824
ML
1646
1647/*
1648 Local Variables:
1649 c-file-style: "gnu"
1650 End:
1651*/