Update README on using libraries in non-standard locations
[bpt/guile.git] / libguile / posix.c
CommitLineData
417566eb 1/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
0f2d19dd 2 *
73be1d9e
MV
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
0f2d19dd 7 *
73be1d9e
MV
8 * This library 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 GNU
11 * Lesser General Public License for more details.
0f2d19dd 12 *
73be1d9e
MV
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
92205699 15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73be1d9e 16 */
1bbd0b84 17
1bbd0b84 18
0f2d19dd 19\f
dbb605f5 20#ifdef HAVE_CONFIG_H
2546b5c3
RB
21# include <config.h>
22#endif
0f2d19dd 23
3731192f 24#include <stdlib.h>
0f2d19dd 25#include <stdio.h>
e6e2e95a
MD
26#include <errno.h>
27
a0599745 28#include "libguile/_scm.h"
b28f5b3c 29#include "libguile/dynwind.h"
a0599745
MD
30#include "libguile/fports.h"
31#include "libguile/scmsigs.h"
32#include "libguile/feature.h"
33#include "libguile/strings.h"
c44ca4fe 34#include "libguile/srfi-13.h"
a17d2654 35#include "libguile/srfi-14.h"
a0599745 36#include "libguile/vectors.h"
4ea9429e 37#include "libguile/values.h"
c96d76b8 38#include "libguile/lang.h"
a0599745
MD
39
40#include "libguile/validate.h"
41#include "libguile/posix.h"
b89c4943 42#include "libguile/gettext.h"
9de87eea 43#include "libguile/threads.h"
0f2d19dd
JB
44\f
45
02b754d3
GH
46#ifdef HAVE_STRING_H
47#include <string.h>
48#endif
0f2d19dd
JB
49#ifdef TIME_WITH_SYS_TIME
50# include <sys/time.h>
51# include <time.h>
52#else
53# if HAVE_SYS_TIME_H
54# include <sys/time.h>
55# else
56# include <time.h>
57# endif
58#endif
59
60#ifdef HAVE_UNISTD_H
61#include <unistd.h>
95b88819
GH
62#else
63#ifndef ttyname
64extern char *ttyname();
65#endif
0f2d19dd
JB
66#endif
67
3594582b 68#ifdef LIBC_H_WITH_UNISTD_H
bab0f4e5
JB
69#include <libc.h>
70#endif
71
8cc71382 72#include <sys/types.h>
0f2d19dd
JB
73#include <sys/stat.h>
74#include <fcntl.h>
75
82893676 76#ifdef HAVE_PWD_H
0f2d19dd 77#include <pwd.h>
82893676
MG
78#endif
79#ifdef HAVE_IO_H
80#include <io.h>
81#endif
f87c105a 82#ifdef HAVE_WINSOCK2_H
82893676
MG
83#include <winsock2.h>
84#endif
85
86#ifdef __MINGW32__
87/* Some defines for Windows here. */
7beabedb 88# include <process.h>
82893676
MG
89# define pipe(fd) _pipe (fd, 256, O_BINARY)
90#endif /* __MINGW32__ */
0f2d19dd
JB
91
92#if HAVE_SYS_WAIT_H
93# include <sys/wait.h>
94#endif
95#ifndef WEXITSTATUS
96# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
97#endif
98#ifndef WIFEXITED
99# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
100#endif
101
102#include <signal.h>
103
82893676 104#ifdef HAVE_GRP_H
0f2d19dd 105#include <grp.h>
82893676
MG
106#endif
107#ifdef HAVE_SYS_UTSNAME_H
0f2d19dd 108#include <sys/utsname.h>
82893676 109#endif
0f2d19dd 110
0f2d19dd
JB
111#ifdef HAVE_SETLOCALE
112#include <locale.h>
113#endif
114
b89c4943
LC
115#if (defined HAVE_NEWLOCALE) && (defined HAVE_STRCOLL_L)
116# define USE_GNU_LOCALE_API
117#endif
118
a2f00b9b
LC
119#if (defined USE_GNU_LOCALE_API) && (defined HAVE_XLOCALE_H)
120# include <xlocale.h>
121#endif
122
b9a7b725 123#if HAVE_CRYPT_H
94e6d793
MG
124# include <crypt.h>
125#endif
126
0eaf1055
KR
127#ifdef HAVE_NETDB_H
128#include <netdb.h> /* for MAXHOSTNAMELEN on Solaris */
129#endif
130
131#ifdef HAVE_SYS_PARAM_H
132#include <sys/param.h> /* for MAXHOSTNAMELEN */
133#endif
134
94e6d793
MG
135#if HAVE_SYS_RESOURCE_H
136# include <sys/resource.h>
137#endif
138
837b0ae0 139#include <sys/file.h> /* from Gnulib */
94e6d793 140
bab0f4e5
JB
141/* Some Unix systems don't define these. CPP hair is dangerous, but
142 this seems safe enough... */
143#ifndef R_OK
144#define R_OK 4
145#endif
146
147#ifndef W_OK
148#define W_OK 2
149#endif
150
151#ifndef X_OK
152#define X_OK 1
153#endif
154
155#ifndef F_OK
156#define F_OK 0
157#endif
398609a5 158
8ab3d8a0
KR
159/* No prototype for this on Solaris 10. The man page says it's in
160 <unistd.h> ... but it lies. */
161#if ! HAVE_DECL_SETHOSTNAME
162int sethostname (char *name, size_t namelen);
163#endif
164
398609a5
JB
165/* On NextStep, <utime.h> doesn't define struct utime, unless we
166 #define _POSIX_SOURCE before #including it. I think this is less
167 of a kludge than defining struct utimbuf ourselves. */
168#ifdef UTIMBUF_NEEDS_POSIX
169#define _POSIX_SOURCE
170#endif
171
172#ifdef HAVE_SYS_UTIME_H
173#include <sys/utime.h>
174#endif
175
176#ifdef HAVE_UTIME_H
177#include <utime.h>
178#endif
179
180/* Please don't add any more #includes or #defines here. The hack
181 above means that _POSIX_SOURCE may be #defined, which will
eb7e1603
KR
182 encourage header files to do strange things.
183
184 FIXME: Maybe should undef _POSIX_SOURCE after it's done its job.
185
186 FIXME: Probably should do all the includes first, then all the fallback
187 declarations and defines, in case things are not in the header we
188 imagine. */
189
190
191
192
0f2d19dd 193\f
f015614a
MV
194
195/* Two often used patterns
196 */
197
198#define WITH_STRING(str,cstr,code) \
199 do { \
200 char *cstr = scm_to_locale_string (str); \
201 code; \
202 free (cstr); \
203 } while (0)
204
205#define STRING_SYSCALL(str,cstr,code) \
206 do { \
207 int eno; \
208 char *cstr = scm_to_locale_string (str); \
209 SCM_SYSCALL (code); \
210 eno = errno; free (cstr); errno = eno; \
211 } while (0)
212
213
214\f
bc45012d
JB
215SCM_SYMBOL (sym_read_pipe, "read pipe");
216SCM_SYMBOL (sym_write_pipe, "write pipe");
0f2d19dd 217
a1ec6916 218SCM_DEFINE (scm_pipe, "pipe", 0, 0, 0,
1bbd0b84 219 (),
1e6808ea
MG
220 "Return a newly created pipe: a pair of ports which are linked\n"
221 "together on the local machine. The @emph{car} is the input\n"
222 "port and the @emph{cdr} is the output port. Data written (and\n"
223 "flushed) to the output port can be read from the input port.\n"
224 "Pipes are commonly used for communication with a newly forked\n"
225 "child process. The need to flush the output port can be\n"
226 "avoided by making it unbuffered using @code{setvbuf}.\n"
227 "\n"
228 "Writes occur atomically provided the size of the data in bytes\n"
229 "is not greater than the value of @code{PIPE_BUF}. Note that\n"
230 "the output port is likely to block if too much data (typically\n"
231 "equal to @code{PIPE_BUF}) has been written but not yet read\n"
232 "from the input port.")
1bbd0b84 233#define FUNC_NAME s_scm_pipe
0f2d19dd
JB
234{
235 int fd[2], rv;
0f2d19dd 236 SCM p_rd, p_wt;
02b754d3 237
0f2d19dd
JB
238 rv = pipe (fd);
239 if (rv)
1bbd0b84 240 SCM_SYSERROR;
ee149d03
JB
241
242 p_rd = scm_fdes_to_port (fd[0], "r", sym_read_pipe);
243 p_wt = scm_fdes_to_port (fd[1], "w", sym_write_pipe);
0f2d19dd
JB
244 return scm_cons (p_rd, p_wt);
245}
1bbd0b84 246#undef FUNC_NAME
0f2d19dd
JB
247
248
0e958795 249#ifdef HAVE_GETGROUPS
a1ec6916 250SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
1bbd0b84 251 (),
1e6808ea 252 "Return a vector of integers representing the current\n"
bb2c02f2 253 "supplementary group IDs.")
1bbd0b84 254#define FUNC_NAME s_scm_getgroups
0f2d19dd 255{
1d1559ce 256 SCM result;
66460dfb 257 int ngroups;
1be6b49c 258 size_t size;
66460dfb
DH
259 GETGROUPS_T *groups;
260
261 ngroups = getgroups (0, NULL);
262 if (ngroups <= 0)
1bbd0b84 263 SCM_SYSERROR;
66460dfb
DH
264
265 size = ngroups * sizeof (GETGROUPS_T);
4c9419ac 266 groups = scm_malloc (size);
634aa8de 267 ngroups = getgroups (ngroups, groups);
66460dfb 268
f360a962
MV
269 result = scm_c_make_vector (ngroups, SCM_BOOL_F);
270 while (--ngroups >= 0)
4057a3e0 271 SCM_SIMPLE_VECTOR_SET (result, ngroups, scm_from_ulong (groups[ngroups]));
66460dfb 272
4c9419ac 273 free (groups);
1d1559ce 274 return result;
1bbd0b84
GB
275}
276#undef FUNC_NAME
0e958795 277#endif
0f2d19dd 278
f360a962
MV
279#ifdef HAVE_SETGROUPS
280SCM_DEFINE (scm_setgroups, "setgroups", 1, 0, 0,
281 (SCM group_vec),
fcc3adc2
KR
282 "Set the current set of supplementary group IDs to the integers\n"
283 "in the given vector @var{vec}. The return value is\n"
284 "unspecified.\n"
285 "\n"
286 "Generally only the superuser can set the process group IDs.")
f360a962
MV
287#define FUNC_NAME s_scm_setgroups
288{
289 size_t ngroups;
290 size_t size;
291 size_t i;
292 int result;
293 int save_errno;
294 GETGROUPS_T *groups;
295
296 SCM_VALIDATE_VECTOR (SCM_ARG1, group_vec);
297
4057a3e0 298 ngroups = SCM_SIMPLE_VECTOR_LENGTH (group_vec);
f360a962
MV
299
300 /* validate before allocating, so we don't have to worry about leaks */
301 for (i = 0; i < ngroups; i++)
302 {
303 unsigned long ulong_gid;
304 GETGROUPS_T gid;
4057a3e0
MV
305 SCM_VALIDATE_ULONG_COPY (1, SCM_SIMPLE_VECTOR_REF (group_vec, i),
306 ulong_gid);
f360a962
MV
307 gid = ulong_gid;
308 if (gid != ulong_gid)
4057a3e0 309 SCM_OUT_OF_RANGE (1, SCM_SIMPLE_VECTOR_REF (group_vec, i));
f360a962
MV
310 }
311
312 size = ngroups * sizeof (GETGROUPS_T);
2eb78d06 313 if (size / sizeof (GETGROUPS_T) != ngroups)
e11e83f3 314 SCM_OUT_OF_RANGE (SCM_ARG1, scm_from_int (ngroups));
f360a962
MV
315 groups = scm_malloc (size);
316 for(i = 0; i < ngroups; i++)
4057a3e0 317 groups [i] = SCM_NUM2ULONG (1, SCM_SIMPLE_VECTOR_REF (group_vec, i));
f360a962
MV
318
319 result = setgroups (ngroups, groups);
320 save_errno = errno; /* don't let free() touch errno */
321 free (groups);
322 errno = save_errno;
323 if (result < 0)
324 SCM_SYSERROR;
325 return SCM_UNSPECIFIED;
326}
327#undef FUNC_NAME
328#endif
329
82893676 330#ifdef HAVE_GETPWENT
a1ec6916 331SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
1bbd0b84 332 (SCM user),
b380b885
MD
333 "Look up an entry in the user database. @var{obj} can be an integer,\n"
334 "a string, or omitted, giving the behaviour of getpwuid, getpwnam\n"
335 "or getpwent respectively.")
1bbd0b84 336#define FUNC_NAME s_scm_getpwuid
0f2d19dd 337{
0f2d19dd 338 struct passwd *entry;
0f2d19dd 339
1d1559ce 340 SCM result = scm_c_make_vector (7, SCM_UNSPECIFIED);
7888309b 341 if (SCM_UNBNDP (user) || scm_is_false (user))
0f2d19dd 342 {
0f2d19dd 343 SCM_SYSCALL (entry = getpwent ());
3d781d49
JB
344 if (! entry)
345 {
3d781d49
JB
346 return SCM_BOOL_F;
347 }
0f2d19dd 348 }
e11e83f3 349 else if (scm_is_integer (user))
0f2d19dd 350 {
e11e83f3 351 entry = getpwuid (scm_to_int (user));
0f2d19dd
JB
352 }
353 else
354 {
f015614a
MV
355 WITH_STRING (user, c_user,
356 entry = getpwnam (c_user));
0f2d19dd
JB
357 }
358 if (!entry)
1bbd0b84 359 SCM_MISC_ERROR ("entry not found", SCM_EOL);
02b754d3 360
4057a3e0
MV
361 SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (entry->pw_name));
362 SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (entry->pw_passwd));
363 SCM_SIMPLE_VECTOR_SET(result, 2, scm_from_ulong (entry->pw_uid));
364 SCM_SIMPLE_VECTOR_SET(result, 3, scm_from_ulong (entry->pw_gid));
365 SCM_SIMPLE_VECTOR_SET(result, 4, scm_from_locale_string (entry->pw_gecos));
0f2d19dd 366 if (!entry->pw_dir)
4057a3e0 367 SCM_SIMPLE_VECTOR_SET(result, 5, scm_from_locale_string (""));
0f2d19dd 368 else
4057a3e0 369 SCM_SIMPLE_VECTOR_SET(result, 5, scm_from_locale_string (entry->pw_dir));
0f2d19dd 370 if (!entry->pw_shell)
4057a3e0 371 SCM_SIMPLE_VECTOR_SET(result, 6, scm_from_locale_string (""));
0f2d19dd 372 else
4057a3e0 373 SCM_SIMPLE_VECTOR_SET(result, 6, scm_from_locale_string (entry->pw_shell));
1d1559ce 374 return result;
0f2d19dd 375}
1bbd0b84 376#undef FUNC_NAME
82893676 377#endif /* HAVE_GETPWENT */
0f2d19dd
JB
378
379
0e958795 380#ifdef HAVE_SETPWENT
a1ec6916 381SCM_DEFINE (scm_setpwent, "setpw", 0, 1, 0,
1bbd0b84 382 (SCM arg),
b380b885
MD
383 "If called with a true argument, initialize or reset the password data\n"
384 "stream. Otherwise, close the stream. The @code{setpwent} and\n"
385 "@code{endpwent} procedures are implemented on top of this.")
1bbd0b84 386#define FUNC_NAME s_scm_setpwent
0f2d19dd 387{
7888309b 388 if (SCM_UNBNDP (arg) || scm_is_false (arg))
0f2d19dd
JB
389 endpwent ();
390 else
391 setpwent ();
392 return SCM_UNSPECIFIED;
393}
1bbd0b84 394#undef FUNC_NAME
0e958795 395#endif
0f2d19dd
JB
396
397
82893676 398#ifdef HAVE_GETGRENT
0f2d19dd 399/* Combines getgrgid and getgrnam. */
a1ec6916 400SCM_DEFINE (scm_getgrgid, "getgr", 0, 1, 0,
1bbd0b84 401 (SCM name),
b380b885
MD
402 "Look up an entry in the group database. @var{obj} can be an integer,\n"
403 "a string, or omitted, giving the behaviour of getgrgid, getgrnam\n"
404 "or getgrent respectively.")
1bbd0b84 405#define FUNC_NAME s_scm_getgrgid
0f2d19dd 406{
0f2d19dd 407 struct group *entry;
1d1559ce 408 SCM result = scm_c_make_vector (4, SCM_UNSPECIFIED);
34d19ef6 409
7888309b 410 if (SCM_UNBNDP (name) || scm_is_false (name))
3d781d49
JB
411 {
412 SCM_SYSCALL (entry = getgrent ());
413 if (! entry)
414 {
3d781d49
JB
415 return SCM_BOOL_F;
416 }
417 }
e11e83f3
MV
418 else if (scm_is_integer (name))
419 SCM_SYSCALL (entry = getgrgid (scm_to_int (name)));
0f2d19dd 420 else
f015614a
MV
421 STRING_SYSCALL (name, c_name,
422 entry = getgrnam (c_name));
0f2d19dd 423 if (!entry)
1bbd0b84 424 SCM_SYSERROR;
02b754d3 425
4057a3e0
MV
426 SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (entry->gr_name));
427 SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (entry->gr_passwd));
428 SCM_SIMPLE_VECTOR_SET(result, 2, scm_from_ulong (entry->gr_gid));
429 SCM_SIMPLE_VECTOR_SET(result, 3, scm_makfromstrs (-1, entry->gr_mem));
1d1559ce 430 return result;
0f2d19dd 431}
1bbd0b84 432#undef FUNC_NAME
0f2d19dd
JB
433
434
435
a1ec6916 436SCM_DEFINE (scm_setgrent, "setgr", 0, 1, 0,
1bbd0b84 437 (SCM arg),
b380b885
MD
438 "If called with a true argument, initialize or reset the group data\n"
439 "stream. Otherwise, close the stream. The @code{setgrent} and\n"
440 "@code{endgrent} procedures are implemented on top of this.")
1bbd0b84 441#define FUNC_NAME s_scm_setgrent
0f2d19dd 442{
7888309b 443 if (SCM_UNBNDP (arg) || scm_is_false (arg))
0f2d19dd
JB
444 endgrent ();
445 else
446 setgrent ();
447 return SCM_UNSPECIFIED;
448}
1bbd0b84 449#undef FUNC_NAME
82893676 450#endif /* HAVE_GETGRENT */
0f2d19dd
JB
451
452
4ea9429e
AW
453#ifdef HAVE_GETRLIMIT
454#ifdef RLIMIT_AS
455SCM_SYMBOL (sym_as, "as");
456#endif
457#ifdef RLIMIT_CORE
458SCM_SYMBOL (sym_core, "core");
459#endif
460#ifdef RLIMIT_CPU
461SCM_SYMBOL (sym_cpu, "cpu");
462#endif
463#ifdef RLIMIT_DATA
464SCM_SYMBOL (sym_data, "data");
465#endif
466#ifdef RLIMIT_FSIZE
467SCM_SYMBOL (sym_fsize, "fsize");
468#endif
469#ifdef RLIMIT_MEMLOCK
470SCM_SYMBOL (sym_memlock, "memlock");
471#endif
472#ifdef RLIMIT_MSGQUEUE
473SCM_SYMBOL (sym_msgqueue, "msgqueue");
474#endif
475#ifdef RLIMIT_NICE
476SCM_SYMBOL (sym_nice, "nice");
477#endif
478#ifdef RLIMIT_NOFILE
479SCM_SYMBOL (sym_nofile, "nofile");
480#endif
481#ifdef RLIMIT_NPROC
482SCM_SYMBOL (sym_nproc, "nproc");
483#endif
484#ifdef RLIMIT_RSS
485SCM_SYMBOL (sym_rss, "rss");
486#endif
487#ifdef RLIMIT_RTPRIO
488SCM_SYMBOL (sym_rtprio, "rtprio");
489#endif
490#ifdef RLIMIT_RTPRIO
491SCM_SYMBOL (sym_rttime, "rttime");
492#endif
493#ifdef RLIMIT_SIGPENDING
494SCM_SYMBOL (sym_sigpending, "sigpending");
495#endif
496#ifdef RLIMIT_STACK
497SCM_SYMBOL (sym_stack, "stack");
498#endif
499
500static int
501scm_to_resource (SCM s, const char *func, int pos)
502{
503 if (scm_is_number (s))
504 return scm_to_int (s);
505
506 SCM_ASSERT_TYPE (scm_is_symbol (s), s, pos, func, "symbol");
507
508#ifdef RLIMIT_AS
509 if (s == sym_as)
510 return RLIMIT_AS;
511#endif
512#ifdef RLIMIT_CORE
513 if (s == sym_core)
514 return RLIMIT_CORE;
515#endif
516#ifdef RLIMIT_CPU
517 if (s == sym_cpu)
518 return RLIMIT_CPU;
519#endif
520#ifdef RLIMIT_DATA
521 if (s == sym_data)
522 return RLIMIT_DATA;
523#endif
524#ifdef RLIMIT_FSIZE
525 if (s == sym_fsize)
526 return RLIMIT_FSIZE;
527#endif
528#ifdef RLIMIT_MEMLOCK
529 if (s == sym_memlock)
530 return RLIMIT_MEMLOCK;
531#endif
532#ifdef RLIMIT_MSGQUEUE
533 if (s == sym_msgqueue)
534 return RLIMIT_MSGQUEUE;
535#endif
536#ifdef RLIMIT_NICE
537 if (s == sym_nice)
538 return RLIMIT_NICE;
539#endif
540#ifdef RLIMIT_NOFILE
541 if (s == sym_nofile)
542 return RLIMIT_NOFILE;
543#endif
544#ifdef RLIMIT_NPROC
545 if (s == sym_nproc)
546 return RLIMIT_NPROC;
547#endif
548#ifdef RLIMIT_RSS
549 if (s == sym_rss)
550 return RLIMIT_RSS;
551#endif
552#ifdef RLIMIT_RTPRIO
553 if (s == sym_rtprio)
554 return RLIMIT_RTPRIO;
555#endif
556#ifdef RLIMIT_RTPRIO
557 if (s == sym_rttime)
558 return RLIMIT_RTPRIO;
559#endif
560#ifdef RLIMIT_SIGPENDING
561 if (s == sym_sigpending)
562 return RLIMIT_SIGPENDING;
563#endif
564#ifdef RLIMIT_STACK
565 if (s == sym_stack)
566 return RLIMIT_STACK;
567#endif
568
569 scm_misc_error (func, "invalid rlimit resource ~A", scm_list_1 (s));
570 return 0;
571}
572
573SCM_DEFINE (scm_getrlimit, "getrlimit", 1, 0, 0,
574 (SCM resource),
575 "Get a resource limit for this process. @var{resource} identifies the resource,\n"
576 "either as an integer or as a symbol. For example, @code{(getrlimit 'stack)}\n"
577 "gets the limits associated with @code{RLIMIT_STACK}.\n\n"
578 "@code{getrlimit} returns two values, the soft and the hard limit. If no\n"
579 "limit is set for the resource in question, the returned limit will be @code{#f}.")
580#define FUNC_NAME s_scm_getrlimit
581{
582 int iresource;
583 struct rlimit lim = { 0, 0 };
584
585 iresource = scm_to_resource (resource, FUNC_NAME, 1);
586
587 if (getrlimit (iresource, &lim) != 0)
588 scm_syserror (FUNC_NAME);
589
590 return scm_values (scm_list_2 ((lim.rlim_cur == RLIM_INFINITY) ? SCM_BOOL_F
591 : scm_from_long (lim.rlim_cur),
592 (lim.rlim_max == RLIM_INFINITY) ? SCM_BOOL_F
593 : scm_from_long (lim.rlim_max)));
594}
595#undef FUNC_NAME
596
597
598#ifdef HAVE_SETRLIMIT
599SCM_DEFINE (scm_setrlimit, "setrlimit", 3, 0, 0,
600 (SCM resource, SCM soft, SCM hard),
601 "Set a resource limit for this process. @var{resource} identifies the resource,\n"
602 "either as an integer or as a symbol. @var{soft} and @var{hard} should be integers,\n"
603 "or @code{#f} to indicate no limit (i.e., @code{RLIM_INFINITY}).\n\n"
604 "For example, @code{(setrlimit 'stack 150000 300000)} sets the @code{RLIMIT_STACK}\n"
605 "limit to 150 kilobytes, with a hard limit of 300 kB.")
606#define FUNC_NAME s_scm_setrlimit
607{
608 int iresource;
609 struct rlimit lim = { 0, 0 };
610
611 iresource = scm_to_resource (resource, FUNC_NAME, 1);
612
613 lim.rlim_cur = (soft == SCM_BOOL_F) ? RLIM_INFINITY : scm_to_long (soft);
614 lim.rlim_max = (hard == SCM_BOOL_F) ? RLIM_INFINITY : scm_to_long (hard);
615
616 if (setrlimit (iresource, &lim) != 0)
617 scm_syserror (FUNC_NAME);
618
619 return SCM_UNSPECIFIED;
620}
621#undef FUNC_NAME
622#endif /* HAVE_SETRLIMIT */
623#endif /* HAVE_GETRLIMIT */
624
625
a1ec6916 626SCM_DEFINE (scm_kill, "kill", 2, 0, 0,
1bbd0b84 627 (SCM pid, SCM sig),
b380b885
MD
628 "Sends a signal to the specified process or group of processes.\n\n"
629 "@var{pid} specifies the processes to which the signal is sent:\n\n"
630 "@table @r\n"
631 "@item @var{pid} greater than 0\n"
632 "The process whose identifier is @var{pid}.\n"
633 "@item @var{pid} equal to 0\n"
634 "All processes in the current process group.\n"
635 "@item @var{pid} less than -1\n"
636 "The process group whose identifier is -@var{pid}\n"
637 "@item @var{pid} equal to -1\n"
638 "If the process is privileged, all processes except for some special\n"
639 "system processes. Otherwise, all processes with the current effective\n"
640 "user ID.\n"
641 "@end table\n\n"
642 "@var{sig} should be specified using a variable corresponding to\n"
643 "the Unix symbolic name, e.g.,\n\n"
644 "@defvar SIGHUP\n"
645 "Hang-up signal.\n"
646 "@end defvar\n\n"
647 "@defvar SIGINT\n"
648 "Interrupt signal.\n"
649 "@end defvar")
1bbd0b84 650#define FUNC_NAME s_scm_kill
0f2d19dd 651{
0f2d19dd 652 /* Signal values are interned in scm_init_posix(). */
82893676 653#ifdef HAVE_KILL
a55c2b68 654 if (kill (scm_to_int (pid), scm_to_int (sig)) != 0)
23d72566 655 SCM_SYSERROR;
82893676 656#else
23d72566
KR
657 /* Mingw has raise(), but not kill(). (Other raw DOS environments might
658 be similar.) Use raise() when the requested pid is our own process,
659 otherwise bomb. */
a55c2b68 660 if (scm_to_int (pid) == getpid ())
23d72566
KR
661 {
662 if (raise (scm_to_int (sig)) != 0)
663 {
664 err:
665 SCM_SYSERROR;
666 }
667 else
668 {
669 errno = ENOSYS;
670 goto err;
671 }
672 }
82893676 673#endif
02b754d3 674 return SCM_UNSPECIFIED;
0f2d19dd 675}
1bbd0b84 676#undef FUNC_NAME
0f2d19dd 677
d00ae47e 678#ifdef HAVE_WAITPID
a1ec6916 679SCM_DEFINE (scm_waitpid, "waitpid", 1, 1, 0,
1bbd0b84 680 (SCM pid, SCM options),
b380b885
MD
681 "This procedure collects status information from a child process which\n"
682 "has terminated or (optionally) stopped. Normally it will\n"
683 "suspend the calling process until this can be done. If more than one\n"
684 "child process is eligible then one will be chosen by the operating system.\n\n"
685 "The value of @var{pid} determines the behaviour:\n\n"
686 "@table @r\n"
687 "@item @var{pid} greater than 0\n"
688 "Request status information from the specified child process.\n"
689 "@item @var{pid} equal to -1 or WAIT_ANY\n"
690 "Request status information for any child process.\n"
691 "@item @var{pid} equal to 0 or WAIT_MYPGRP\n"
692 "Request status information for any child process in the current process\n"
693 "group.\n"
694 "@item @var{pid} less than -1\n"
695 "Request status information for any child process whose process group ID\n"
696 "is -@var{PID}.\n"
697 "@end table\n\n"
698 "The @var{options} argument, if supplied, should be the bitwise OR of the\n"
699 "values of zero or more of the following variables:\n\n"
700 "@defvar WNOHANG\n"
701 "Return immediately even if there are no child processes to be collected.\n"
702 "@end defvar\n\n"
703 "@defvar WUNTRACED\n"
704 "Report status information for stopped processes as well as terminated\n"
705 "processes.\n"
706 "@end defvar\n\n"
707 "The return value is a pair containing:\n\n"
708 "@enumerate\n"
709 "@item\n"
710 "The process ID of the child process, or 0 if @code{WNOHANG} was\n"
711 "specified and no process was collected.\n"
712 "@item\n"
713 "The integer status value.\n"
714 "@end enumerate")
1bbd0b84 715#define FUNC_NAME s_scm_waitpid
0f2d19dd
JB
716{
717 int i;
718 int status;
719 int ioptions;
0f2d19dd
JB
720 if (SCM_UNBNDP (options))
721 ioptions = 0;
722 else
723 {
0f2d19dd 724 /* Flags are interned in scm_init_posix. */
a55c2b68 725 ioptions = scm_to_int (options);
0f2d19dd 726 }
a55c2b68 727 SCM_SYSCALL (i = waitpid (scm_to_int (pid), &status, ioptions));
02b754d3 728 if (i == -1)
1bbd0b84 729 SCM_SYSERROR;
a55c2b68 730 return scm_cons (scm_from_int (i), scm_from_int (status));
0f2d19dd 731}
1bbd0b84 732#undef FUNC_NAME
d00ae47e 733#endif /* HAVE_WAITPID */
0f2d19dd 734
82893676 735#ifndef __MINGW32__
a1ec6916 736SCM_DEFINE (scm_status_exit_val, "status:exit-val", 1, 0, 0,
1bbd0b84 737 (SCM status),
1e6808ea
MG
738 "Return the exit status value, as would be set if a process\n"
739 "ended normally through a call to @code{exit} or @code{_exit},\n"
740 "if any, otherwise @code{#f}.")
1bbd0b84 741#define FUNC_NAME s_scm_status_exit_val
67ec3667 742{
e67dc2be
JB
743 int lstatus;
744
e67dc2be 745 /* On Ultrix, the WIF... macros assume their argument is an lvalue;
e11e83f3 746 go figure. */
a55c2b68 747 lstatus = scm_to_int (status);
e67dc2be 748 if (WIFEXITED (lstatus))
a55c2b68 749 return (scm_from_int (WEXITSTATUS (lstatus)));
67ec3667
GH
750 else
751 return SCM_BOOL_F;
752}
1bbd0b84 753#undef FUNC_NAME
e67dc2be 754
a1ec6916 755SCM_DEFINE (scm_status_term_sig, "status:term-sig", 1, 0, 0,
1bbd0b84 756 (SCM status),
1e6808ea
MG
757 "Return the signal number which terminated the process, if any,\n"
758 "otherwise @code{#f}.")
1bbd0b84 759#define FUNC_NAME s_scm_status_term_sig
67ec3667 760{
e67dc2be
JB
761 int lstatus;
762
a55c2b68 763 lstatus = scm_to_int (status);
e67dc2be 764 if (WIFSIGNALED (lstatus))
a55c2b68 765 return scm_from_int (WTERMSIG (lstatus));
67ec3667
GH
766 else
767 return SCM_BOOL_F;
768}
1bbd0b84 769#undef FUNC_NAME
0f2d19dd 770
a1ec6916 771SCM_DEFINE (scm_status_stop_sig, "status:stop-sig", 1, 0, 0,
1bbd0b84 772 (SCM status),
1e6808ea
MG
773 "Return the signal number which stopped the process, if any,\n"
774 "otherwise @code{#f}.")
1bbd0b84 775#define FUNC_NAME s_scm_status_stop_sig
67ec3667 776{
e67dc2be
JB
777 int lstatus;
778
a55c2b68 779 lstatus = scm_to_int (status);
e67dc2be 780 if (WIFSTOPPED (lstatus))
a55c2b68 781 return scm_from_int (WSTOPSIG (lstatus));
67ec3667
GH
782 else
783 return SCM_BOOL_F;
784}
1bbd0b84 785#undef FUNC_NAME
82893676 786#endif /* __MINGW32__ */
0f2d19dd 787
82893676 788#ifdef HAVE_GETPPID
a1ec6916 789SCM_DEFINE (scm_getppid, "getppid", 0, 0, 0,
1bbd0b84 790 (),
1e6808ea
MG
791 "Return an integer representing the process ID of the parent\n"
792 "process.")
1bbd0b84 793#define FUNC_NAME s_scm_getppid
0f2d19dd 794{
e11e83f3 795 return scm_from_int (getppid ());
0f2d19dd 796}
1bbd0b84 797#undef FUNC_NAME
82893676 798#endif /* HAVE_GETPPID */
0f2d19dd
JB
799
800
82893676 801#ifndef __MINGW32__
a1ec6916 802SCM_DEFINE (scm_getuid, "getuid", 0, 0, 0,
1bbd0b84 803 (),
1e6808ea 804 "Return an integer representing the current real user ID.")
1bbd0b84 805#define FUNC_NAME s_scm_getuid
0f2d19dd 806{
e11e83f3 807 return scm_from_int (getuid ());
0f2d19dd 808}
1bbd0b84 809#undef FUNC_NAME
0f2d19dd
JB
810
811
812
a1ec6916 813SCM_DEFINE (scm_getgid, "getgid", 0, 0, 0,
1bbd0b84 814 (),
1e6808ea 815 "Return an integer representing the current real group ID.")
1bbd0b84 816#define FUNC_NAME s_scm_getgid
0f2d19dd 817{
e11e83f3 818 return scm_from_int (getgid ());
0f2d19dd 819}
1bbd0b84 820#undef FUNC_NAME
0f2d19dd
JB
821
822
823
a1ec6916 824SCM_DEFINE (scm_geteuid, "geteuid", 0, 0, 0,
1bbd0b84 825 (),
1e6808ea 826 "Return an integer representing the current effective user ID.\n"
b380b885 827 "If the system does not support effective IDs, then the real ID\n"
480fa28d 828 "is returned. @code{(provided? 'EIDs)} reports whether the\n"
1e6808ea 829 "system supports effective IDs.")
1bbd0b84 830#define FUNC_NAME s_scm_geteuid
0f2d19dd
JB
831{
832#ifdef HAVE_GETEUID
e11e83f3 833 return scm_from_int (geteuid ());
0f2d19dd 834#else
e11e83f3 835 return scm_from_int (getuid ());
0f2d19dd
JB
836#endif
837}
1bbd0b84 838#undef FUNC_NAME
0f2d19dd
JB
839
840
a1ec6916 841SCM_DEFINE (scm_getegid, "getegid", 0, 0, 0,
1bbd0b84 842 (),
1e6808ea 843 "Return an integer representing the current effective group ID.\n"
b380b885 844 "If the system does not support effective IDs, then the real ID\n"
480fa28d 845 "is returned. @code{(provided? 'EIDs)} reports whether the\n"
1e6808ea 846 "system supports effective IDs.")
1bbd0b84 847#define FUNC_NAME s_scm_getegid
0f2d19dd
JB
848{
849#ifdef HAVE_GETEUID
e11e83f3 850 return scm_from_int (getegid ());
0f2d19dd 851#else
e11e83f3 852 return scm_from_int (getgid ());
0f2d19dd
JB
853#endif
854}
1bbd0b84 855#undef FUNC_NAME
0f2d19dd
JB
856
857
a1ec6916 858SCM_DEFINE (scm_setuid, "setuid", 1, 0, 0,
1bbd0b84 859 (SCM id),
b380b885
MD
860 "Sets both the real and effective user IDs to the integer @var{id}, provided\n"
861 "the process has appropriate privileges.\n"
862 "The return value is unspecified.")
1bbd0b84 863#define FUNC_NAME s_scm_setuid
0f2d19dd 864{
a55c2b68 865 if (setuid (scm_to_int (id)) != 0)
1bbd0b84 866 SCM_SYSERROR;
02b754d3 867 return SCM_UNSPECIFIED;
0f2d19dd 868}
1bbd0b84 869#undef FUNC_NAME
0f2d19dd 870
a1ec6916 871SCM_DEFINE (scm_setgid, "setgid", 1, 0, 0,
1bbd0b84 872 (SCM id),
b380b885
MD
873 "Sets both the real and effective group IDs to the integer @var{id}, provided\n"
874 "the process has appropriate privileges.\n"
875 "The return value is unspecified.")
1bbd0b84 876#define FUNC_NAME s_scm_setgid
0f2d19dd 877{
a55c2b68 878 if (setgid (scm_to_int (id)) != 0)
1bbd0b84 879 SCM_SYSERROR;
02b754d3 880 return SCM_UNSPECIFIED;
0f2d19dd 881}
1bbd0b84 882#undef FUNC_NAME
0f2d19dd 883
a1ec6916 884SCM_DEFINE (scm_seteuid, "seteuid", 1, 0, 0,
1bbd0b84 885 (SCM id),
b380b885
MD
886 "Sets the effective user ID to the integer @var{id}, provided the process\n"
887 "has appropriate privileges. If effective IDs are not supported, the\n"
480fa28d 888 "real ID is set instead -- @code{(provided? 'EIDs)} reports whether the\n"
b380b885
MD
889 "system supports effective IDs.\n"
890 "The return value is unspecified.")
1bbd0b84 891#define FUNC_NAME s_scm_seteuid
0f2d19dd 892{
02b754d3
GH
893 int rv;
894
0f2d19dd 895#ifdef HAVE_SETEUID
a55c2b68 896 rv = seteuid (scm_to_int (id));
0f2d19dd 897#else
a55c2b68 898 rv = setuid (scm_to_int (id));
0f2d19dd 899#endif
02b754d3 900 if (rv != 0)
1bbd0b84 901 SCM_SYSERROR;
02b754d3 902 return SCM_UNSPECIFIED;
0f2d19dd 903}
1bbd0b84 904#undef FUNC_NAME
7beabedb
MG
905#endif /* __MINGW32__ */
906
0f2d19dd 907
0e958795 908#ifdef HAVE_SETEGID
a1ec6916 909SCM_DEFINE (scm_setegid, "setegid", 1, 0, 0,
1bbd0b84 910 (SCM id),
b380b885
MD
911 "Sets the effective group ID to the integer @var{id}, provided the process\n"
912 "has appropriate privileges. If effective IDs are not supported, the\n"
480fa28d 913 "real ID is set instead -- @code{(provided? 'EIDs)} reports whether the\n"
b380b885
MD
914 "system supports effective IDs.\n"
915 "The return value is unspecified.")
1bbd0b84 916#define FUNC_NAME s_scm_setegid
0f2d19dd 917{
02b754d3
GH
918 int rv;
919
0f2d19dd 920#ifdef HAVE_SETEUID
a55c2b68 921 rv = setegid (scm_to_int (id));
0f2d19dd 922#else
a55c2b68 923 rv = setgid (scm_to_int (id));
0f2d19dd 924#endif
02b754d3 925 if (rv != 0)
1bbd0b84 926 SCM_SYSERROR;
02b754d3
GH
927 return SCM_UNSPECIFIED;
928
0f2d19dd 929}
1bbd0b84 930#undef FUNC_NAME
0e958795 931#endif
0f2d19dd 932
82893676
MG
933
934#ifdef HAVE_GETPGRP
a1ec6916 935SCM_DEFINE (scm_getpgrp, "getpgrp", 0, 0, 0,
1bbd0b84 936 (),
1e6808ea 937 "Return an integer representing the current process group ID.\n"
b380b885 938 "This is the POSIX definition, not BSD.")
1bbd0b84 939#define FUNC_NAME s_scm_getpgrp
0f2d19dd
JB
940{
941 int (*fn)();
4625e44f 942 fn = (int (*) ()) getpgrp;
e11e83f3 943 return scm_from_int (fn (0));
0f2d19dd 944}
1bbd0b84 945#undef FUNC_NAME
82893676
MG
946#endif /* HAVE_GETPGRP */
947
0f2d19dd 948
f25f761d 949#ifdef HAVE_SETPGID
a1ec6916 950SCM_DEFINE (scm_setpgid, "setpgid", 2, 0, 0,
1bbd0b84 951 (SCM pid, SCM pgid),
b380b885
MD
952 "Move the process @var{pid} into the process group @var{pgid}. @var{pid} or\n"
953 "@var{pgid} must be integers: they can be zero to indicate the ID of the\n"
954 "current process.\n"
955 "Fails on systems that do not support job control.\n"
956 "The return value is unspecified.")
1bbd0b84 957#define FUNC_NAME s_scm_setpgid
0f2d19dd 958{
02b754d3 959 /* FIXME(?): may be known as setpgrp. */
a55c2b68 960 if (setpgid (scm_to_int (pid), scm_to_int (pgid)) != 0)
1bbd0b84 961 SCM_SYSERROR;
02b754d3 962 return SCM_UNSPECIFIED;
0f2d19dd 963}
1bbd0b84 964#undef FUNC_NAME
f25f761d 965#endif /* HAVE_SETPGID */
0f2d19dd 966
f25f761d 967#ifdef HAVE_SETSID
a1ec6916 968SCM_DEFINE (scm_setsid, "setsid", 0, 0, 0,
1bbd0b84 969 (),
b380b885
MD
970 "Creates a new session. The current process becomes the session leader\n"
971 "and is put in a new process group. The process will be detached\n"
972 "from its controlling terminal if it has one.\n"
973 "The return value is an integer representing the new process group ID.")
1bbd0b84 974#define FUNC_NAME s_scm_setsid
0f2d19dd
JB
975{
976 pid_t sid = setsid ();
02b754d3 977 if (sid == -1)
1bbd0b84 978 SCM_SYSERROR;
02b754d3 979 return SCM_UNSPECIFIED;
0f2d19dd 980}
1bbd0b84 981#undef FUNC_NAME
f25f761d 982#endif /* HAVE_SETSID */
0f2d19dd 983
e8a59063
KR
984
985/* ttyname returns its result in a single static buffer, hence
986 scm_i_misc_mutex for thread safety. In glibc 2.3.2 two threads
987 continuously calling ttyname will otherwise get an overwrite quite
988 easily.
989
990 ttyname_r (when available) could be used instead of scm_i_misc_mutex, but
991 there's probably little to be gained in either speed or parallelism. */
992
82893676 993#ifdef HAVE_TTYNAME
a1ec6916 994SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
1bbd0b84 995 (SCM port),
1e6808ea
MG
996 "Return a string with the name of the serial terminal device\n"
997 "underlying @var{port}.")
1bbd0b84 998#define FUNC_NAME s_scm_ttyname
0f2d19dd 999{
1d1559ce 1000 char *result;
e8a59063 1001 int fd, err;
a1ef7406 1002 SCM ret = SCM_BOOL_F;
78446828
MV
1003
1004 port = SCM_COERCE_OUTPORT (port);
34d19ef6 1005 SCM_VALIDATE_OPPORT (1, port);
a98bddfd 1006 if (!SCM_FPORTP (port))
0f2d19dd 1007 return SCM_BOOL_F;
ee149d03 1008 fd = SCM_FPORT_FDES (port);
e8a59063 1009
9de87eea 1010 scm_i_scm_pthread_mutex_lock (&scm_i_misc_mutex);
a1ef7406 1011
1d1559ce 1012 SCM_SYSCALL (result = ttyname (fd));
e8a59063 1013 err = errno;
a1ef7406
LC
1014 if (result != NULL)
1015 result = strdup (result);
1016
9de87eea 1017 scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
e8a59063 1018
1d1559ce 1019 if (!result)
e8a59063
KR
1020 {
1021 errno = err;
1022 SCM_SYSERROR;
1023 }
a1ef7406
LC
1024 else
1025 ret = scm_take_locale_string (result);
1026
e8a59063 1027 return ret;
0f2d19dd 1028}
1bbd0b84 1029#undef FUNC_NAME
82893676 1030#endif /* HAVE_TTYNAME */
0f2d19dd 1031
e8a59063 1032
0a9d83b0
KR
1033/* For thread safety "buf" is used instead of NULL for the ctermid static
1034 buffer. Actually it's unlikely the controlling terminal will change
1035 during program execution, and indeed on glibc (2.3.2) it's always just
1036 "/dev/tty", but L_ctermid on the stack is easy and fast and guarantees
1037 safety everywhere. */
f25f761d 1038#ifdef HAVE_CTERMID
a1ec6916 1039SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
1bbd0b84 1040 (),
1e6808ea
MG
1041 "Return a string containing the file name of the controlling\n"
1042 "terminal for the current process.")
1bbd0b84 1043#define FUNC_NAME s_scm_ctermid
0f2d19dd 1044{
0a9d83b0
KR
1045 char buf[L_ctermid];
1046 char *result = ctermid (buf);
02b754d3 1047 if (*result == '\0')
1bbd0b84 1048 SCM_SYSERROR;
cc95e00a 1049 return scm_from_locale_string (result);
0f2d19dd 1050}
1bbd0b84 1051#undef FUNC_NAME
f25f761d 1052#endif /* HAVE_CTERMID */
0f2d19dd 1053
f25f761d 1054#ifdef HAVE_TCGETPGRP
a1ec6916 1055SCM_DEFINE (scm_tcgetpgrp, "tcgetpgrp", 1, 0, 0,
1bbd0b84 1056 (SCM port),
1e6808ea
MG
1057 "Return the process group ID of the foreground process group\n"
1058 "associated with the terminal open on the file descriptor\n"
1059 "underlying @var{port}.\n"
1060 "\n"
b380b885
MD
1061 "If there is no foreground process group, the return value is a\n"
1062 "number greater than 1 that does not match the process group ID\n"
1063 "of any existing process group. This can happen if all of the\n"
1064 "processes in the job that was formerly the foreground job have\n"
1065 "terminated, and no other job has yet been moved into the\n"
1066 "foreground.")
1bbd0b84 1067#define FUNC_NAME s_scm_tcgetpgrp
0f2d19dd
JB
1068{
1069 int fd;
1070 pid_t pgid;
78446828
MV
1071
1072 port = SCM_COERCE_OUTPORT (port);
1073
34d19ef6 1074 SCM_VALIDATE_OPFPORT (1, port);
ee149d03
JB
1075 fd = SCM_FPORT_FDES (port);
1076 if ((pgid = tcgetpgrp (fd)) == -1)
1bbd0b84 1077 SCM_SYSERROR;
e11e83f3 1078 return scm_from_int (pgid);
1bbd0b84
GB
1079}
1080#undef FUNC_NAME
f25f761d 1081#endif /* HAVE_TCGETPGRP */
0f2d19dd 1082
f25f761d 1083#ifdef HAVE_TCSETPGRP
a1ec6916 1084SCM_DEFINE (scm_tcsetpgrp, "tcsetpgrp", 2, 0, 0,
1bbd0b84 1085 (SCM port, SCM pgid),
b380b885
MD
1086 "Set the foreground process group ID for the terminal used by the file\n"
1087 "descriptor underlying @var{port} to the integer @var{pgid}.\n"
1088 "The calling process\n"
1089 "must be a member of the same session as @var{pgid} and must have the same\n"
1090 "controlling terminal. The return value is unspecified.")
1bbd0b84 1091#define FUNC_NAME s_scm_tcsetpgrp
0f2d19dd
JB
1092{
1093 int fd;
78446828
MV
1094
1095 port = SCM_COERCE_OUTPORT (port);
1096
34d19ef6 1097 SCM_VALIDATE_OPFPORT (1, port);
ee149d03 1098 fd = SCM_FPORT_FDES (port);
a55c2b68 1099 if (tcsetpgrp (fd, scm_to_int (pgid)) == -1)
1bbd0b84 1100 SCM_SYSERROR;
02b754d3 1101 return SCM_UNSPECIFIED;
1bbd0b84
GB
1102}
1103#undef FUNC_NAME
f25f761d 1104#endif /* HAVE_TCSETPGRP */
0f2d19dd 1105
7f03f970
MV
1106static void
1107free_string_pointers (void *data)
0f2d19dd 1108{
7f03f970 1109 scm_i_free_string_pointers ((char **)data);
0f2d19dd
JB
1110}
1111
a1ec6916 1112SCM_DEFINE (scm_execl, "execl", 1, 0, 1,
1bbd0b84 1113 (SCM filename, SCM args),
b380b885
MD
1114 "Executes the file named by @var{path} as a new process image.\n"
1115 "The remaining arguments are supplied to the process; from a C program\n"
bb2c02f2 1116 "they are accessible as the @code{argv} argument to @code{main}.\n"
b380b885 1117 "Conventionally the first @var{arg} is the same as @var{path}.\n"
8f85c0c6 1118 "All arguments must be strings.\n\n"
b380b885
MD
1119 "If @var{arg} is missing, @var{path} is executed with a null\n"
1120 "argument list, which may have system-dependent side-effects.\n\n"
1121 "This procedure is currently implemented using the @code{execv} system\n"
1122 "call, but we call it @code{execl} because of its Scheme calling interface.")
1bbd0b84 1123#define FUNC_NAME s_scm_execl
0f2d19dd 1124{
7f03f970
MV
1125 char *exec_file;
1126 char **exec_argv;
1127
661ae7ab 1128 scm_dynwind_begin (0);
7f03f970
MV
1129
1130 exec_file = scm_to_locale_string (filename);
661ae7ab 1131 scm_dynwind_free (exec_file);
7f03f970
MV
1132
1133 exec_argv = scm_i_allocate_string_pointers (args);
661ae7ab 1134 scm_dynwind_unwind_handler (free_string_pointers, exec_argv,
7f03f970
MV
1135 SCM_F_WIND_EXPLICITLY);
1136
8ab3d8a0
KR
1137 execv (exec_file,
1138#ifdef __MINGW32__
1139 /* extra "const" in mingw formals, provokes warning from gcc */
1140 (const char * const *)
1141#endif
1142 exec_argv);
1bbd0b84 1143 SCM_SYSERROR;
7f03f970 1144
02b754d3 1145 /* not reached. */
661ae7ab 1146 scm_dynwind_end ();
02b754d3 1147 return SCM_BOOL_F;
0f2d19dd 1148}
1bbd0b84 1149#undef FUNC_NAME
0f2d19dd 1150
a1ec6916 1151SCM_DEFINE (scm_execlp, "execlp", 1, 0, 1,
1bbd0b84 1152 (SCM filename, SCM args),
b380b885
MD
1153 "Similar to @code{execl}, however if\n"
1154 "@var{filename} does not contain a slash\n"
1155 "then the file to execute will be located by searching the\n"
1156 "directories listed in the @code{PATH} environment variable.\n\n"
6bcd01fc 1157 "This procedure is currently implemented using the @code{execvp} system\n"
b380b885 1158 "call, but we call it @code{execlp} because of its Scheme calling interface.")
1bbd0b84 1159#define FUNC_NAME s_scm_execlp
0f2d19dd 1160{
7f03f970
MV
1161 char *exec_file;
1162 char **exec_argv;
1163
661ae7ab 1164 scm_dynwind_begin (0);
7f03f970
MV
1165
1166 exec_file = scm_to_locale_string (filename);
661ae7ab 1167 scm_dynwind_free (exec_file);
7f03f970
MV
1168
1169 exec_argv = scm_i_allocate_string_pointers (args);
661ae7ab 1170 scm_dynwind_unwind_handler (free_string_pointers, exec_argv,
7f03f970
MV
1171 SCM_F_WIND_EXPLICITLY);
1172
8ab3d8a0
KR
1173 execvp (exec_file,
1174#ifdef __MINGW32__
1175 /* extra "const" in mingw formals, provokes warning from gcc */
1176 (const char * const *)
1177#endif
1178 exec_argv);
1bbd0b84 1179 SCM_SYSERROR;
7f03f970 1180
02b754d3 1181 /* not reached. */
661ae7ab 1182 scm_dynwind_end ();
02b754d3 1183 return SCM_BOOL_F;
0f2d19dd 1184}
1bbd0b84 1185#undef FUNC_NAME
0f2d19dd 1186
6afcd3b2 1187
807f353f
KR
1188/* OPTIMIZE-ME: scm_execle doesn't need malloced copies of the environment
1189 list strings the way environ_list_to_c gives. */
1190
a1ec6916 1191SCM_DEFINE (scm_execle, "execle", 2, 0, 1,
1bbd0b84 1192 (SCM filename, SCM env, SCM args),
b380b885
MD
1193 "Similar to @code{execl}, but the environment of the new process is\n"
1194 "specified by @var{env}, which must be a list of strings as returned by the\n"
1195 "@code{environ} procedure.\n\n"
1196 "This procedure is currently implemented using the @code{execve} system\n"
1197 "call, but we call it @code{execle} because of its Scheme calling interface.")
1bbd0b84 1198#define FUNC_NAME s_scm_execle
6afcd3b2 1199{
7f03f970 1200 char **exec_argv;
6afcd3b2 1201 char **exec_env;
7f03f970 1202 char *exec_file;
6afcd3b2 1203
661ae7ab 1204 scm_dynwind_begin (0);
7f03f970
MV
1205
1206 exec_file = scm_to_locale_string (filename);
661ae7ab 1207 scm_dynwind_free (exec_file);
7f03f970
MV
1208
1209 exec_argv = scm_i_allocate_string_pointers (args);
661ae7ab 1210 scm_dynwind_unwind_handler (free_string_pointers, exec_argv,
7f03f970
MV
1211 SCM_F_WIND_EXPLICITLY);
1212
1213 exec_env = scm_i_allocate_string_pointers (env);
661ae7ab 1214 scm_dynwind_unwind_handler (free_string_pointers, exec_env,
7f03f970
MV
1215 SCM_F_WIND_EXPLICITLY);
1216
8ab3d8a0
KR
1217 execve (exec_file,
1218#ifdef __MINGW32__
1219 /* extra "const" in mingw formals, provokes warning from gcc */
1220 (const char * const *)
1221#endif
1222 exec_argv,
1223#ifdef __MINGW32__
1224 /* extra "const" in mingw formals, provokes warning from gcc */
1225 (const char * const *)
1226#endif
1227 exec_env);
1bbd0b84 1228 SCM_SYSERROR;
7f03f970 1229
6afcd3b2 1230 /* not reached. */
661ae7ab 1231 scm_dynwind_end ();
6afcd3b2
GH
1232 return SCM_BOOL_F;
1233}
1bbd0b84 1234#undef FUNC_NAME
6afcd3b2 1235
82893676 1236#ifdef HAVE_FORK
a1ec6916 1237SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
1bbd0b84 1238 (),
b380b885
MD
1239 "Creates a new \"child\" process by duplicating the current \"parent\" process.\n"
1240 "In the child the return value is 0. In the parent the return value is\n"
1241 "the integer process ID of the child.\n\n"
1242 "This procedure has been renamed from @code{fork} to avoid a naming conflict\n"
1243 "with the scsh fork.")
1bbd0b84 1244#define FUNC_NAME s_scm_fork
0f2d19dd 1245{
bab0f4e5 1246 int pid;
0f2d19dd
JB
1247 pid = fork ();
1248 if (pid == -1)
1bbd0b84 1249 SCM_SYSERROR;
e11e83f3 1250 return scm_from_int (pid);
0f2d19dd 1251}
1bbd0b84 1252#undef FUNC_NAME
82893676 1253#endif /* HAVE_FORK */
0f2d19dd 1254
4f68365d
MV
1255#ifdef __MINGW32__
1256# include "win32-uname.h"
1257#endif
1258
1259#if defined (HAVE_UNAME) || defined (__MINGW32__)
a1ec6916 1260SCM_DEFINE (scm_uname, "uname", 0, 0, 0,
1bbd0b84 1261 (),
1e6808ea
MG
1262 "Return an object with some information about the computer\n"
1263 "system the program is running on.")
1bbd0b84 1264#define FUNC_NAME s_scm_uname
0f2d19dd 1265{
0f2d19dd 1266 struct utsname buf;
1d1559ce 1267 SCM result = scm_c_make_vector (5, SCM_UNSPECIFIED);
e1a191a8 1268 if (uname (&buf) < 0)
1bbd0b84 1269 SCM_SYSERROR;
4057a3e0
MV
1270 SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (buf.sysname));
1271 SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (buf.nodename));
1272 SCM_SIMPLE_VECTOR_SET(result, 2, scm_from_locale_string (buf.release));
1273 SCM_SIMPLE_VECTOR_SET(result, 3, scm_from_locale_string (buf.version));
1274 SCM_SIMPLE_VECTOR_SET(result, 4, scm_from_locale_string (buf.machine));
0f2d19dd 1275/*
02b754d3 1276 a linux special?
4057a3e0 1277 SCM_SIMPLE_VECTOR_SET(result, 5, scm_from_locale_string (buf.domainname));
0f2d19dd 1278*/
1d1559ce 1279 return result;
0f2d19dd 1280}
1bbd0b84 1281#undef FUNC_NAME
f25f761d 1282#endif /* HAVE_UNAME */
0f2d19dd 1283
a1ec6916 1284SCM_DEFINE (scm_environ, "environ", 0, 1, 0,
1bbd0b84 1285 (SCM env),
1e6808ea
MG
1286 "If @var{env} is omitted, return the current environment (in the\n"
1287 "Unix sense) as a list of strings. Otherwise set the current\n"
1288 "environment, which is also the default environment for child\n"
1289 "processes, to the supplied list of strings. Each member of\n"
1290 "@var{env} should be of the form @code{NAME=VALUE} and values of\n"
1291 "@code{NAME} should not be duplicated. If @var{env} is supplied\n"
1292 "then the return value is unspecified.")
1bbd0b84 1293#define FUNC_NAME s_scm_environ
0f2d19dd
JB
1294{
1295 if (SCM_UNBNDP (env))
1296 return scm_makfromstrs (-1, environ);
1297 else
1298 {
0f2d19dd 1299 char **new_environ;
6afcd3b2 1300
7f03f970 1301 new_environ = scm_i_allocate_string_pointers (env);
0f2d19dd
JB
1302 /* Free the old environment, except when called for the first
1303 * time.
1304 */
1305 {
0f2d19dd
JB
1306 static int first = 1;
1307 if (!first)
7f03f970 1308 scm_i_free_string_pointers (environ);
0f2d19dd
JB
1309 first = 0;
1310 }
1311 environ = new_environ;
1312 return SCM_UNSPECIFIED;
1313 }
1314}
1bbd0b84 1315#undef FUNC_NAME
0f2d19dd 1316
9ee5fce4
MD
1317#ifdef L_tmpnam
1318
a1ec6916 1319SCM_DEFINE (scm_tmpnam, "tmpnam", 0, 0, 0,
1bbd0b84 1320 (),
1e6808ea
MG
1321 "Return a name in the file system that does not match any\n"
1322 "existing file. However there is no guarantee that another\n"
1323 "process will not create the file after @code{tmpnam} is called.\n"
1324 "Care should be taken if opening the file, e.g., use the\n"
1325 "@code{O_EXCL} open flag or use @code{mkstemp!} instead.")
1bbd0b84 1326#define FUNC_NAME s_scm_tmpnam
9ee5fce4
MD
1327{
1328 char name[L_tmpnam];
6d163216
GH
1329 char *rv;
1330
1331 SCM_SYSCALL (rv = tmpnam (name));
1332 if (rv == NULL)
1333 /* not SCM_SYSERROR since errno probably not set. */
1334 SCM_MISC_ERROR ("tmpnam failed", SCM_EOL);
cc95e00a 1335 return scm_from_locale_string (name);
9ee5fce4 1336}
0f981281 1337#undef FUNC_NAME
0f2d19dd 1338
1bbd0b84 1339#endif
1cc91f1b 1340
4f68365d
MV
1341#ifndef HAVE_MKSTEMP
1342extern int mkstemp (char *);
1343#endif
1344
6d163216
GH
1345SCM_DEFINE (scm_mkstemp, "mkstemp!", 1, 0, 0,
1346 (SCM tmpl),
23f2b9a3 1347 "Create a new unique file in the file system and return a new\n"
1e6808ea 1348 "buffered port open for reading and writing to the file.\n"
2c4cdcb0 1349 "\n"
1e6808ea 1350 "@var{tmpl} is a string specifying where the file should be\n"
23f2b9a3
KR
1351 "created: it must end with @samp{XXXXXX} and those @samp{X}s\n"
1352 "will be changed in the string to return the name of the file.\n"
1353 "(@code{port-filename} on the port also gives the name.)\n"
2c4cdcb0 1354 "\n"
23f2b9a3
KR
1355 "POSIX doesn't specify the permissions mode of the file, on GNU\n"
1356 "and most systems it's @code{#o600}. An application can use\n"
1357 "@code{chmod} to relax that if desired. For example\n"
1358 "@code{#o666} less @code{umask}, which is usual for ordinary\n"
1359 "file creation,\n"
1360 "\n"
1361 "@example\n"
1362 "(let ((port (mkstemp! (string-copy \"/tmp/myfile-XXXXXX\"))))\n"
1363 " (chmod port (logand #o666 (lognot (umask))))\n"
1364 " ...)\n"
1365 "@end example")
6d163216
GH
1366#define FUNC_NAME s_scm_mkstemp
1367{
1368 char *c_tmpl;
71978ac9 1369 int rv;
6d163216 1370
661ae7ab 1371 scm_dynwind_begin (0);
892065da
MV
1372
1373 c_tmpl = scm_to_locale_string (tmpl);
661ae7ab 1374 scm_dynwind_free (c_tmpl);
892065da 1375
6d163216
GH
1376 SCM_SYSCALL (rv = mkstemp (c_tmpl));
1377 if (rv == -1)
1378 SCM_SYSERROR;
892065da
MV
1379
1380 scm_substring_move_x (scm_from_locale_string (c_tmpl),
1381 SCM_INUM0, scm_string_length (tmpl),
1382 tmpl, SCM_INUM0);
1383
661ae7ab 1384 scm_dynwind_end ();
6d163216
GH
1385 return scm_fdes_to_port (rv, "w+", tmpl);
1386}
1387#undef FUNC_NAME
1388
a1ec6916 1389SCM_DEFINE (scm_utime, "utime", 1, 2, 0,
1bbd0b84 1390 (SCM pathname, SCM actime, SCM modtime),
1e6808ea
MG
1391 "@code{utime} sets the access and modification times for the\n"
1392 "file named by @var{path}. If @var{actime} or @var{modtime} is\n"
1393 "not supplied, then the current time is used. @var{actime} and\n"
1394 "@var{modtime} must be integer time values as returned by the\n"
1395 "@code{current-time} procedure.\n"
1396 "@lisp\n"
b380b885 1397 "(utime \"foo\" (- (current-time) 3600))\n"
1e6808ea
MG
1398 "@end lisp\n"
1399 "will set the access time to one hour in the past and the\n"
1400 "modification time to the current time.")
1bbd0b84 1401#define FUNC_NAME s_scm_utime
0f2d19dd
JB
1402{
1403 int rv;
1404 struct utimbuf utm_tmp;
1405
0f2d19dd
JB
1406 if (SCM_UNBNDP (actime))
1407 SCM_SYSCALL (time (&utm_tmp.actime));
1408 else
e4b265d8 1409 utm_tmp.actime = SCM_NUM2ULONG (2, actime);
0f2d19dd
JB
1410
1411 if (SCM_UNBNDP (modtime))
1412 SCM_SYSCALL (time (&utm_tmp.modtime));
1413 else
e4b265d8 1414 utm_tmp.modtime = SCM_NUM2ULONG (3, modtime);
0f2d19dd 1415
f015614a
MV
1416 STRING_SYSCALL (pathname, c_pathname,
1417 rv = utime (c_pathname, &utm_tmp));
02b754d3 1418 if (rv != 0)
1bbd0b84 1419 SCM_SYSERROR;
02b754d3 1420 return SCM_UNSPECIFIED;
0f2d19dd 1421}
1bbd0b84 1422#undef FUNC_NAME
0f2d19dd 1423
a1ec6916 1424SCM_DEFINE (scm_access, "access?", 2, 0, 0,
1bbd0b84 1425 (SCM path, SCM how),
20e0b166
KR
1426 "Test accessibility of a file under the real UID and GID of the\n"
1427 "calling process. The return is @code{#t} if @var{path} exists\n"
1428 "and the permissions requested by @var{how} are all allowed, or\n"
1429 "@code{#f} if not.\n"
1e6808ea 1430 "\n"
20e0b166
KR
1431 "@var{how} is an integer which is one of the following values,\n"
1432 "or a bitwise-OR (@code{logior}) of multiple values.\n"
1e6808ea 1433 "\n"
b380b885 1434 "@defvar R_OK\n"
20e0b166 1435 "Test for read permission.\n"
b380b885
MD
1436 "@end defvar\n"
1437 "@defvar W_OK\n"
20e0b166 1438 "Test for write permission.\n"
b380b885
MD
1439 "@end defvar\n"
1440 "@defvar X_OK\n"
20e0b166 1441 "Test for execute permission.\n"
b380b885
MD
1442 "@end defvar\n"
1443 "@defvar F_OK\n"
20e0b166
KR
1444 "Test for existence of the file. This is implied by each of the\n"
1445 "other tests, so there's no need to combine it with them.\n"
1446 "@end defvar\n"
1447 "\n"
1448 "It's important to note that @code{access?} does not simply\n"
1449 "indicate what will happen on attempting to read or write a\n"
1450 "file. In normal circumstances it does, but in a set-UID or\n"
1451 "set-GID program it doesn't because @code{access?} tests the\n"
1452 "real ID, whereas an open or execute attempt uses the effective\n"
1453 "ID.\n"
1454 "\n"
1455 "A program which will never run set-UID/GID can ignore the\n"
1456 "difference between real and effective IDs, but for maximum\n"
1457 "generality, especially in library functions, it's best not to\n"
1458 "use @code{access?} to predict the result of an open or execute,\n"
1459 "instead simply attempt that and catch any exception.\n"
1460 "\n"
1461 "The main use for @code{access?} is to let a set-UID/GID program\n"
1462 "determine what the invoking user would have been allowed to do,\n"
1463 "without the greater (or perhaps lesser) privileges afforded by\n"
1464 "the effective ID. For more on this, see ``Testing File\n"
1465 "Access'' in The GNU C Library Reference Manual.")
1bbd0b84 1466#define FUNC_NAME s_scm_access
0f2d19dd
JB
1467{
1468 int rv;
1469
f015614a
MV
1470 WITH_STRING (path, c_path,
1471 rv = access (c_path, scm_to_int (how)));
7888309b 1472 return scm_from_bool (!rv);
0f2d19dd 1473}
1bbd0b84 1474#undef FUNC_NAME
0f2d19dd 1475
a1ec6916 1476SCM_DEFINE (scm_getpid, "getpid", 0, 0, 0,
1bbd0b84 1477 (),
1e6808ea 1478 "Return an integer representing the current process ID.")
1bbd0b84 1479#define FUNC_NAME s_scm_getpid
0f2d19dd 1480{
e11e83f3 1481 return scm_from_ulong (getpid ());
0f2d19dd 1482}
1bbd0b84 1483#undef FUNC_NAME
0f2d19dd 1484
a1ec6916 1485SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
1bbd0b84 1486 (SCM str),
b380b885
MD
1487 "Modifies the environment of the current process, which is\n"
1488 "also the default environment inherited by child processes.\n\n"
1489 "If @var{string} is of the form @code{NAME=VALUE} then it will be written\n"
1490 "directly into the environment, replacing any existing environment string\n"
1491 "with\n"
1492 "name matching @code{NAME}. If @var{string} does not contain an equal\n"
1493 "sign, then any existing string with name matching @var{string} will\n"
1494 "be removed.\n\n"
1495 "The return value is unspecified.")
1bbd0b84 1496#define FUNC_NAME s_scm_putenv
0f2d19dd 1497{
f158788f 1498 int rv;
f015614a 1499 char *c_str = scm_to_locale_string (str);
002409fe 1500
3731192f 1501 /* Leave C_STR in the environment. */
f015614a 1502
3731192f
LC
1503 /* Gnulib's `putenv' module honors the semantics described above. */
1504 rv = putenv (c_str);
1505 if (rv < 0)
1506 SCM_SYSERROR;
f015614a 1507
f93ddd39 1508 return SCM_UNSPECIFIED;
0f2d19dd 1509}
1bbd0b84 1510#undef FUNC_NAME
0f2d19dd 1511
b89c4943 1512/* This mutex is used to serialize invocations of `setlocale ()' on non-GNU
a2f00b9b
LC
1513 systems (i.e., systems where a reentrant locale API is not available). It
1514 is also acquired before calls to `nl_langinfo ()'. See `i18n.c' for
1515 details. */
1516scm_i_pthread_mutex_t scm_i_locale_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER;
b89c4943 1517
f25f761d 1518#ifdef HAVE_SETLOCALE
b89c4943 1519
a1ec6916 1520SCM_DEFINE (scm_setlocale, "setlocale", 1, 1, 0,
1bbd0b84 1521 (SCM category, SCM locale),
1e6808ea
MG
1522 "If @var{locale} is omitted, return the current value of the\n"
1523 "specified locale category as a system-dependent string.\n"
1524 "@var{category} should be specified using the values\n"
1525 "@code{LC_COLLATE}, @code{LC_ALL} etc.\n"
1526 "\n"
1527 "Otherwise the specified locale category is set to the string\n"
1528 "@var{locale} and the new value is returned as a\n"
1529 "system-dependent string. If @var{locale} is an empty string,\n"
bb2c02f2 1530 "the locale will be set using environment variables.")
1bbd0b84 1531#define FUNC_NAME s_scm_setlocale
0f2d19dd 1532{
a2f00b9b 1533 int c_category;
0f2d19dd
JB
1534 char *clocale;
1535 char *rv;
1536
661ae7ab 1537 scm_dynwind_begin (0);
f015614a 1538
0f2d19dd
JB
1539 if (SCM_UNBNDP (locale))
1540 {
1541 clocale = NULL;
1542 }
1543 else
1544 {
f015614a 1545 clocale = scm_to_locale_string (locale);
661ae7ab 1546 scm_dynwind_free (clocale);
0f2d19dd
JB
1547 }
1548
a2f00b9b
LC
1549 c_category = scm_i_to_lc_category (category, 1);
1550
b89c4943 1551 scm_i_pthread_mutex_lock (&scm_i_locale_mutex);
a2f00b9b 1552 rv = setlocale (c_category, clocale);
b89c4943 1553 scm_i_pthread_mutex_unlock (&scm_i_locale_mutex);
b89c4943 1554
02b754d3 1555 if (rv == NULL)
41b74b7d
KR
1556 {
1557 /* POSIX and C99 don't say anything about setlocale setting errno, so
1558 force a sensible value here. glibc leaves ENOENT, which would be
1559 fine, but it's not a documented feature. */
1560 errno = EINVAL;
1561 SCM_SYSERROR;
1562 }
f015614a 1563
a17d2654
LC
1564 /* Recompute the standard SRFI-14 character sets in a locale-dependent
1565 (actually charset-dependent) way. */
1566 scm_srfi_14_compute_char_sets ();
1567
661ae7ab 1568 scm_dynwind_end ();
f015614a 1569 return scm_from_locale_string (rv);
0f2d19dd 1570}
1bbd0b84 1571#undef FUNC_NAME
f25f761d 1572#endif /* HAVE_SETLOCALE */
0f2d19dd 1573
f25f761d 1574#ifdef HAVE_MKNOD
a1ec6916 1575SCM_DEFINE (scm_mknod, "mknod", 4, 0, 0,
1bbd0b84 1576 (SCM path, SCM type, SCM perms, SCM dev),
b380b885
MD
1577 "Creates a new special file, such as a file corresponding to a device.\n"
1578 "@var{path} specifies the name of the file. @var{type} should\n"
1579 "be one of the following symbols:\n"
1580 "regular, directory, symlink, block-special, char-special,\n"
1581 "fifo, or socket. @var{perms} (an integer) specifies the file permissions.\n"
1582 "@var{dev} (an integer) specifies which device the special file refers\n"
1583 "to. Its exact interpretation depends on the kind of special file\n"
1584 "being created.\n\n"
1585 "E.g.,\n"
1e6808ea 1586 "@lisp\n"
09831f94 1587 "(mknod \"/dev/fd0\" 'block-special #o660 (+ (* 2 256) 2))\n"
1e6808ea 1588 "@end lisp\n\n"
a3c8b9fc 1589 "The return value is unspecified.")
1bbd0b84 1590#define FUNC_NAME s_scm_mknod
0f2d19dd 1591{
0f2d19dd 1592 int val;
cc95e00a 1593 const char *p;
82a76bdf 1594 int ctype = 0;
19468eff 1595
a6d9e5ab 1596 SCM_VALIDATE_STRING (1, path);
34d19ef6 1597 SCM_VALIDATE_SYMBOL (2, type);
19468eff 1598
cc95e00a 1599 p = scm_i_symbol_chars (type);
19468eff
GH
1600 if (strcmp (p, "regular") == 0)
1601 ctype = S_IFREG;
1602 else if (strcmp (p, "directory") == 0)
1603 ctype = S_IFDIR;
23f2b9a3
KR
1604#ifdef S_IFLNK
1605 /* systems without symlinks probably don't have S_IFLNK defined */
19468eff
GH
1606 else if (strcmp (p, "symlink") == 0)
1607 ctype = S_IFLNK;
23f2b9a3 1608#endif
19468eff
GH
1609 else if (strcmp (p, "block-special") == 0)
1610 ctype = S_IFBLK;
1611 else if (strcmp (p, "char-special") == 0)
1612 ctype = S_IFCHR;
1613 else if (strcmp (p, "fifo") == 0)
1614 ctype = S_IFIFO;
e655d034 1615#ifdef S_IFSOCK
19468eff
GH
1616 else if (strcmp (p, "socket") == 0)
1617 ctype = S_IFSOCK;
e655d034 1618#endif
19468eff 1619 else
34d19ef6 1620 SCM_OUT_OF_RANGE (2, type);
19468eff 1621
f015614a
MV
1622 STRING_SYSCALL (path, c_path,
1623 val = mknod (c_path,
1624 ctype | scm_to_int (perms),
1625 scm_to_int (dev)));
02b754d3 1626 if (val != 0)
1bbd0b84 1627 SCM_SYSERROR;
02b754d3 1628 return SCM_UNSPECIFIED;
0f2d19dd 1629}
1bbd0b84 1630#undef FUNC_NAME
f25f761d 1631#endif /* HAVE_MKNOD */
0f2d19dd 1632
f25f761d 1633#ifdef HAVE_NICE
a1ec6916 1634SCM_DEFINE (scm_nice, "nice", 1, 0, 0,
1bbd0b84 1635 (SCM incr),
b380b885
MD
1636 "Increment the priority of the current process by @var{incr}. A higher\n"
1637 "priority value means that the process runs less often.\n"
1638 "The return value is unspecified.")
1bbd0b84 1639#define FUNC_NAME s_scm_nice
0f2d19dd 1640{
634aa8de
LC
1641 int nice_value;
1642
f1c82f55
KR
1643 /* nice() returns "prio-NZERO" on success or -1 on error, but -1 can arise
1644 from "prio-NZERO", so an error must be detected from errno changed */
1645 errno = 0;
634aa8de 1646 nice_value = nice (scm_to_int (incr));
f1c82f55 1647 if (errno != 0)
1bbd0b84 1648 SCM_SYSERROR;
634aa8de 1649
02b754d3 1650 return SCM_UNSPECIFIED;
0f2d19dd 1651}
1bbd0b84 1652#undef FUNC_NAME
f25f761d 1653#endif /* HAVE_NICE */
0f2d19dd 1654
f25f761d 1655#ifdef HAVE_SYNC
a1ec6916 1656SCM_DEFINE (scm_sync, "sync", 0, 0, 0,
1bbd0b84 1657 (),
b380b885
MD
1658 "Flush the operating system disk buffers.\n"
1659 "The return value is unspecified.")
1bbd0b84 1660#define FUNC_NAME s_scm_sync
0f2d19dd 1661{
0f2d19dd 1662 sync();
127ec750 1663 return SCM_UNSPECIFIED;
0f2d19dd 1664}
1bbd0b84 1665#undef FUNC_NAME
f25f761d 1666#endif /* HAVE_SYNC */
0f2d19dd 1667
33bea692
KR
1668
1669/* crypt() returns a pointer to a static buffer, so we use scm_i_misc_mutex
1670 to avoid another thread overwriting it. A test program running crypt
1671 continuously in two threads can be quickly seen tripping this problem.
1672 crypt() is pretty slow normally, so a mutex shouldn't add much overhead.
1673
1674 glibc has a thread-safe crypt_r, but (in version 2.3.2) it runs a lot
1675 slower (about 5x) than plain crypt if you pass an uninitialized data
1676 block each time. Presumably there's some one-time setups. The best way
1677 to use crypt_r for parallel execution in multiple threads would probably
1678 be to maintain a little pool of initialized crypt_data structures, take
1679 one and use it, then return it to the pool. That pool could be garbage
1680 collected so it didn't add permanently to memory use if only a few crypt
1681 calls are made. But we expect crypt will be used rarely, and even more
1682 rarely will there be any desire for lots of parallel execution on
1683 multiple cpus. So for now we don't bother with anything fancy, just
1684 ensure it works. */
1685
b9a7b725 1686#if HAVE_CRYPT
33bea692 1687SCM_DEFINE (scm_crypt, "crypt", 2, 0, 0,
94e6d793
MG
1688 (SCM key, SCM salt),
1689 "Encrypt @var{key} using @var{salt} as the salt value to the\n"
9401323e 1690 "crypt(3) library call.")
94e6d793
MG
1691#define FUNC_NAME s_scm_crypt
1692{
33bea692 1693 SCM ret;
23d72566 1694 char *c_key, *c_salt, *c_ret;
94e6d793 1695
661ae7ab
MV
1696 scm_dynwind_begin (0);
1697 scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex);
33bea692 1698
f015614a 1699 c_key = scm_to_locale_string (key);
661ae7ab 1700 scm_dynwind_free (c_key);
f015614a 1701 c_salt = scm_to_locale_string (salt);
661ae7ab 1702 scm_dynwind_free (c_salt);
f015614a 1703
23d72566
KR
1704 /* The Linux crypt(3) man page says crypt will return NULL and set errno
1705 on error. (Eg. ENOSYS if legal restrictions mean it cannot be
1706 implemented). */
1707 c_ret = crypt (c_key, c_salt);
1708 if (c_ret == NULL)
1709 SCM_SYSERROR;
33bea692 1710
23d72566 1711 ret = scm_from_locale_string (c_ret);
661ae7ab 1712 scm_dynwind_end ();
33bea692 1713 return ret;
94e6d793
MG
1714}
1715#undef FUNC_NAME
b9a7b725 1716#endif /* HAVE_CRYPT */
94e6d793
MG
1717
1718#if HAVE_CHROOT
1719SCM_DEFINE (scm_chroot, "chroot", 1, 0, 0,
1720 (SCM path),
1721 "Change the root directory to that specified in @var{path}.\n"
1722 "This directory will be used for path names beginning with\n"
1723 "@file{/}. The root directory is inherited by all children\n"
1724 "of the current process. Only the superuser may change the\n"
1725 "root directory.")
1726#define FUNC_NAME s_scm_chroot
1727{
f015614a 1728 int rv;
94e6d793 1729
f015614a
MV
1730 WITH_STRING (path, c_path,
1731 rv = chroot (c_path));
1732 if (rv == -1)
94e6d793
MG
1733 SCM_SYSERROR;
1734 return SCM_UNSPECIFIED;
1735}
1736#undef FUNC_NAME
1737#endif /* HAVE_CHROOT */
1738
7beabedb
MG
1739
1740#ifdef __MINGW32__
1741/* Wrapper function to supplying `getlogin()' under Windows. */
1742static char * getlogin (void)
1743{
1744 static char user[256];
1745 static unsigned long len = 256;
1746
1747 if (!GetUserName (user, &len))
1748 return NULL;
1749 return user;
1750}
1751#endif /* __MINGW32__ */
1752
1753
4f68365d 1754#if defined (HAVE_GETLOGIN) || defined (__MINGW32__)
94e6d793
MG
1755SCM_DEFINE (scm_getlogin, "getlogin", 0, 0, 0,
1756 (void),
1757 "Return a string containing the name of the user logged in on\n"
1758 "the controlling terminal of the process, or @code{#f} if this\n"
1759 "information cannot be obtained.")
1760#define FUNC_NAME s_scm_getlogin
1761{
1762 char * p;
1763
1764 p = getlogin ();
1765 if (!p || !*p)
1766 return SCM_BOOL_F;
cc95e00a 1767 return scm_from_locale_string (p);
94e6d793
MG
1768}
1769#undef FUNC_NAME
1770#endif /* HAVE_GETLOGIN */
1771
1772#if HAVE_CUSERID
5f380d71
LC
1773
1774# if !HAVE_DECL_CUSERID
1775extern char *cuserid (char *);
1776# endif
1777
94e6d793
MG
1778SCM_DEFINE (scm_cuserid, "cuserid", 0, 0, 0,
1779 (void),
1780 "Return a string containing a user name associated with the\n"
1781 "effective user id of the process. Return @code{#f} if this\n"
1782 "information cannot be obtained.")
1783#define FUNC_NAME s_scm_cuserid
1784{
1b317eb1 1785 char buf[L_cuserid];
94e6d793
MG
1786 char * p;
1787
1b317eb1 1788 p = cuserid (buf);
94e6d793
MG
1789 if (!p || !*p)
1790 return SCM_BOOL_F;
cc95e00a 1791 return scm_from_locale_string (p);
94e6d793
MG
1792}
1793#undef FUNC_NAME
1794#endif /* HAVE_CUSERID */
1795
1796#if HAVE_GETPRIORITY
1797SCM_DEFINE (scm_getpriority, "getpriority", 2, 0, 0,
1798 (SCM which, SCM who),
1799 "Return the scheduling priority of the process, process group\n"
1800 "or user, as indicated by @var{which} and @var{who}. @var{which}\n"
1801 "is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}\n"
1802 "or @code{PRIO_USER}, and @var{who} is interpreted relative to\n"
1803 "@var{which} (a process identifier for @code{PRIO_PROCESS},\n"
1804 "process group identifier for @code{PRIO_PGRP}, and a user\n"
1805 "identifier for @code{PRIO_USER}. A zero value of @var{who}\n"
1806 "denotes the current process, process group, or user. Return\n"
1807 "the highest priority (lowest numerical value) of any of the\n"
1808 "specified processes.")
1809#define FUNC_NAME s_scm_getpriority
1810{
1811 int cwhich, cwho, ret;
1812
a55c2b68
MV
1813 cwhich = scm_to_int (which);
1814 cwho = scm_to_int (who);
94e6d793
MG
1815
1816 /* We have to clear errno and examine it later, because -1 is a
1817 legal return value for getpriority(). */
1818 errno = 0;
1819 ret = getpriority (cwhich, cwho);
1820 if (errno != 0)
1821 SCM_SYSERROR;
a55c2b68 1822 return scm_from_int (ret);
94e6d793
MG
1823}
1824#undef FUNC_NAME
1825#endif /* HAVE_GETPRIORITY */
1826
1827#if HAVE_SETPRIORITY
1828SCM_DEFINE (scm_setpriority, "setpriority", 3, 0, 0,
1829 (SCM which, SCM who, SCM prio),
1830 "Set the scheduling priority of the process, process group\n"
1831 "or user, as indicated by @var{which} and @var{who}. @var{which}\n"
1832 "is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}\n"
1833 "or @code{PRIO_USER}, and @var{who} is interpreted relative to\n"
1834 "@var{which} (a process identifier for @code{PRIO_PROCESS},\n"
1835 "process group identifier for @code{PRIO_PGRP}, and a user\n"
1836 "identifier for @code{PRIO_USER}. A zero value of @var{who}\n"
1837 "denotes the current process, process group, or user.\n"
1838 "@var{prio} is a value in the range -20 and 20, the default\n"
1839 "priority is 0; lower priorities cause more favorable\n"
1840 "scheduling. Sets the priority of all of the specified\n"
1841 "processes. Only the super-user may lower priorities.\n"
1842 "The return value is not specified.")
1843#define FUNC_NAME s_scm_setpriority
1844{
1845 int cwhich, cwho, cprio;
1846
a55c2b68
MV
1847 cwhich = scm_to_int (which);
1848 cwho = scm_to_int (who);
1849 cprio = scm_to_int (prio);
94e6d793
MG
1850
1851 if (setpriority (cwhich, cwho, cprio) == -1)
1852 SCM_SYSERROR;
1853 return SCM_UNSPECIFIED;
1854}
1855#undef FUNC_NAME
1856#endif /* HAVE_SETPRIORITY */
1857
1858#if HAVE_GETPASS
1859SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0,
1860 (SCM prompt),
1861 "Display @var{prompt} to the standard error output and read\n"
1862 "a password from @file{/dev/tty}. If this file is not\n"
1863 "accessible, it reads from standard input. The password may be\n"
1864 "up to 127 characters in length. Additional characters and the\n"
1865 "terminating newline character are discarded. While reading\n"
1866 "the password, echoing and the generation of signals by special\n"
1867 "characters is disabled.")
1868#define FUNC_NAME s_scm_getpass
1869{
1870 char * p;
1871 SCM passwd;
1872
1873 SCM_VALIDATE_STRING (1, prompt);
94e6d793 1874
f015614a
MV
1875 WITH_STRING (prompt, c_prompt,
1876 p = getpass(c_prompt));
1877 passwd = scm_from_locale_string (p);
94e6d793
MG
1878
1879 /* Clear out the password in the static buffer. */
1880 memset (p, 0, strlen (p));
1881
1882 return passwd;
1883}
1884#undef FUNC_NAME
1885#endif /* HAVE_GETPASS */
1886
94e6d793
MG
1887SCM_DEFINE (scm_flock, "flock", 2, 0, 0,
1888 (SCM file, SCM operation),
1889 "Apply or remove an advisory lock on an open file.\n"
1890 "@var{operation} specifies the action to be done:\n"
0b91f1db
KR
1891 "\n"
1892 "@defvar LOCK_SH\n"
94e6d793
MG
1893 "Shared lock. More than one process may hold a shared lock\n"
1894 "for a given file at a given time.\n"
0b91f1db
KR
1895 "@end defvar\n"
1896 "@defvar LOCK_EX\n"
94e6d793
MG
1897 "Exclusive lock. Only one process may hold an exclusive lock\n"
1898 "for a given file at a given time.\n"
0b91f1db
KR
1899 "@end defvar\n"
1900 "@defvar LOCK_UN\n"
94e6d793 1901 "Unlock the file.\n"
0b91f1db
KR
1902 "@end defvar\n"
1903 "@defvar LOCK_NB\n"
1904 "Don't block when locking. This is combined with one of the\n"
1905 "other operations using @code{logior}. If @code{flock} would\n"
1906 "block an @code{EWOULDBLOCK} error is thrown.\n"
1907 "@end defvar\n"
1908 "\n"
94e6d793 1909 "The return value is not specified. @var{file} may be an open\n"
0b91f1db
KR
1910 "file descriptor or an open file descriptor port.\n"
1911 "\n"
1912 "Note that @code{flock} does not lock files across NFS.")
94e6d793
MG
1913#define FUNC_NAME s_scm_flock
1914{
a55c2b68 1915 int fdes;
94e6d793 1916
a55c2b68
MV
1917 if (scm_is_integer (file))
1918 fdes = scm_to_int (file);
94e6d793
MG
1919 else
1920 {
1921 SCM_VALIDATE_OPFPORT (2, file);
1922
1923 fdes = SCM_FPORT_FDES (file);
1924 }
a55c2b68 1925 if (flock (fdes, scm_to_int (operation)) == -1)
94e6d793
MG
1926 SCM_SYSERROR;
1927 return SCM_UNSPECIFIED;
1928}
1929#undef FUNC_NAME
94e6d793
MG
1930
1931#if HAVE_SETHOSTNAME
1932SCM_DEFINE (scm_sethostname, "sethostname", 1, 0, 0,
1933 (SCM name),
1934 "Set the host name of the current processor to @var{name}. May\n"
1935 "only be used by the superuser. The return value is not\n"
1936 "specified.")
1937#define FUNC_NAME s_scm_sethostname
1938{
f015614a 1939 int rv;
94e6d793 1940
f015614a
MV
1941 WITH_STRING (name, c_name,
1942 rv = sethostname (c_name, strlen(c_name)));
1943 if (rv == -1)
94e6d793
MG
1944 SCM_SYSERROR;
1945 return SCM_UNSPECIFIED;
1946}
1947#undef FUNC_NAME
1948#endif /* HAVE_SETHOSTNAME */
1949
b28f5b3c 1950
94e6d793
MG
1951#if HAVE_GETHOSTNAME
1952SCM_DEFINE (scm_gethostname, "gethostname", 0, 0, 0,
1953 (void),
1954 "Return the host name of the current processor.")
1955#define FUNC_NAME s_scm_gethostname
1956{
b28f5b3c
DH
1957#ifdef MAXHOSTNAMELEN
1958
1959 /* Various systems define MAXHOSTNAMELEN (including Solaris in fact).
1960 * On GNU/Linux this doesn't include the terminating '\0', hence "+ 1". */
1961 const int len = MAXHOSTNAMELEN + 1;
1962 char *const p = scm_malloc (len);
1963 const int res = gethostname (p, len);
1964
661ae7ab
MV
1965 scm_dynwind_begin (0);
1966 scm_dynwind_unwind_handler (free, p, 0);
b28f5b3c
DH
1967
1968#else
94e6d793 1969
0eaf1055 1970 /* Default 256 is for Solaris, under Linux ENAMETOOLONG is returned if not
b28f5b3c
DH
1971 * large enough. SUSv2 specifies 255 maximum too, apparently. */
1972 int len = 256;
1973 int res;
1974 char *p;
0eaf1055 1975
b28f5b3c 1976# if HAVE_SYSCONF && defined (_SC_HOST_NAME_MAX)
0eaf1055
KR
1977
1978 /* POSIX specifies the HOST_NAME_MAX system parameter for the max size,
b28f5b3c
DH
1979 * which may reflect a particular kernel configuration.
1980 * Must watch out for this existing but giving -1, as happens for instance
1981 * in gnu/linux glibc 2.3.2. */
0eaf1055 1982 {
b28f5b3c 1983 const long int n = sysconf (_SC_HOST_NAME_MAX);
0eaf1055
KR
1984 if (n != -1L)
1985 len = n;
1986 }
b28f5b3c
DH
1987
1988# endif
1989
1990 p = scm_malloc (len);
1991
661ae7ab
MV
1992 scm_dynwind_begin (0);
1993 scm_dynwind_unwind_handler (free, p, 0);
0eaf1055 1994
94e6d793
MG
1995 res = gethostname (p, len);
1996 while (res == -1 && errno == ENAMETOOLONG)
1997 {
94e6d793 1998 len *= 2;
b28f5b3c
DH
1999
2000 /* scm_realloc may throw an exception. */
2001 p = scm_realloc (p, len);
94e6d793
MG
2002 res = gethostname (p, len);
2003 }
b28f5b3c
DH
2004
2005#endif
2006
94e6d793
MG
2007 if (res == -1)
2008 {
b28f5b3c
DH
2009 const int save_errno = errno;
2010
2b829bbb 2011 /* No guile exceptions can occur before we have freed p's memory. */
661ae7ab 2012 scm_dynwind_end ();
4c9419ac 2013 free (p);
b28f5b3c 2014
22865124 2015 errno = save_errno;
94e6d793
MG
2016 SCM_SYSERROR;
2017 }
b28f5b3c
DH
2018 else
2019 {
cc95e00a
MV
2020 /* scm_from_locale_string may throw an exception. */
2021 const SCM name = scm_from_locale_string (p);
b28f5b3c 2022
2b829bbb 2023 /* No guile exceptions can occur before we have freed p's memory. */
661ae7ab 2024 scm_dynwind_end ();
b28f5b3c
DH
2025 free (p);
2026
2027 return name;
2028 }
94e6d793
MG
2029}
2030#undef FUNC_NAME
2031#endif /* HAVE_GETHOSTNAME */
2032
b28f5b3c 2033
b89c4943 2034void
0f2d19dd 2035scm_init_posix ()
0f2d19dd
JB
2036{
2037 scm_add_feature ("posix");
2038#ifdef HAVE_GETEUID
2039 scm_add_feature ("EIDs");
2040#endif
2041#ifdef WAIT_ANY
e11e83f3 2042 scm_c_define ("WAIT_ANY", scm_from_int (WAIT_ANY));
0f2d19dd
JB
2043#endif
2044#ifdef WAIT_MYPGRP
e11e83f3 2045 scm_c_define ("WAIT_MYPGRP", scm_from_int (WAIT_MYPGRP));
0f2d19dd
JB
2046#endif
2047#ifdef WNOHANG
e11e83f3 2048 scm_c_define ("WNOHANG", scm_from_int (WNOHANG));
0f2d19dd
JB
2049#endif
2050#ifdef WUNTRACED
e11e83f3 2051 scm_c_define ("WUNTRACED", scm_from_int (WUNTRACED));
0f2d19dd
JB
2052#endif
2053
0f2d19dd 2054 /* access() symbols. */
e11e83f3
MV
2055 scm_c_define ("R_OK", scm_from_int (R_OK));
2056 scm_c_define ("W_OK", scm_from_int (W_OK));
2057 scm_c_define ("X_OK", scm_from_int (X_OK));
2058 scm_c_define ("F_OK", scm_from_int (F_OK));
0f2d19dd
JB
2059
2060#ifdef LC_COLLATE
e11e83f3 2061 scm_c_define ("LC_COLLATE", scm_from_int (LC_COLLATE));
0f2d19dd
JB
2062#endif
2063#ifdef LC_CTYPE
e11e83f3 2064 scm_c_define ("LC_CTYPE", scm_from_int (LC_CTYPE));
0f2d19dd
JB
2065#endif
2066#ifdef LC_MONETARY
e11e83f3 2067 scm_c_define ("LC_MONETARY", scm_from_int (LC_MONETARY));
0f2d19dd
JB
2068#endif
2069#ifdef LC_NUMERIC
e11e83f3 2070 scm_c_define ("LC_NUMERIC", scm_from_int (LC_NUMERIC));
0f2d19dd
JB
2071#endif
2072#ifdef LC_TIME
e11e83f3 2073 scm_c_define ("LC_TIME", scm_from_int (LC_TIME));
0f2d19dd
JB
2074#endif
2075#ifdef LC_MESSAGES
e11e83f3 2076 scm_c_define ("LC_MESSAGES", scm_from_int (LC_MESSAGES));
0f2d19dd
JB
2077#endif
2078#ifdef LC_ALL
e11e83f3 2079 scm_c_define ("LC_ALL", scm_from_int (LC_ALL));
0f2d19dd 2080#endif
9361f762
MV
2081#ifdef LC_PAPER
2082 scm_c_define ("LC_PAPER", scm_from_int (LC_PAPER));
2083#endif
2084#ifdef LC_NAME
2085 scm_c_define ("LC_NAME", scm_from_int (LC_NAME));
2086#endif
2087#ifdef LC_ADDRESS
2088 scm_c_define ("LC_ADDRESS", scm_from_int (LC_ADDRESS));
2089#endif
2090#ifdef LC_TELEPHONE
2091 scm_c_define ("LC_TELEPHONE", scm_from_int (LC_TELEPHONE));
2092#endif
2093#ifdef LC_MEASUREMENT
2094 scm_c_define ("LC_MEASUREMENT", scm_from_int (LC_MEASUREMENT));
2095#endif
2096#ifdef LC_IDENTIFICATION
2097 scm_c_define ("LC_IDENTIFICATION", scm_from_int (LC_IDENTIFICATION));
2098#endif
bd9e24b3 2099#ifdef PIPE_BUF
b9bd8526 2100 scm_c_define ("PIPE_BUF", scm_from_long (PIPE_BUF));
bd9e24b3
GH
2101#endif
2102
94e6d793 2103#ifdef PRIO_PROCESS
e11e83f3 2104 scm_c_define ("PRIO_PROCESS", scm_from_int (PRIO_PROCESS));
94e6d793
MG
2105#endif
2106#ifdef PRIO_PGRP
e11e83f3 2107 scm_c_define ("PRIO_PGRP", scm_from_int (PRIO_PGRP));
94e6d793
MG
2108#endif
2109#ifdef PRIO_USER
e11e83f3 2110 scm_c_define ("PRIO_USER", scm_from_int (PRIO_USER));
94e6d793
MG
2111#endif
2112
2113#ifdef LOCK_SH
e11e83f3 2114 scm_c_define ("LOCK_SH", scm_from_int (LOCK_SH));
94e6d793
MG
2115#endif
2116#ifdef LOCK_EX
e11e83f3 2117 scm_c_define ("LOCK_EX", scm_from_int (LOCK_EX));
94e6d793
MG
2118#endif
2119#ifdef LOCK_UN
e11e83f3 2120 scm_c_define ("LOCK_UN", scm_from_int (LOCK_UN));
94e6d793
MG
2121#endif
2122#ifdef LOCK_NB
e11e83f3 2123 scm_c_define ("LOCK_NB", scm_from_int (LOCK_NB));
94e6d793
MG
2124#endif
2125
a0599745
MD
2126#include "libguile/cpp_sig_symbols.c"
2127#include "libguile/posix.x"
0f2d19dd 2128}
89e00824
ML
2129
2130/*
2131 Local Variables:
2132 c-file-style: "gnu"
2133 End:
2134*/