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