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