Commit | Line | Data |
---|---|---|
36284627 | 1 | /* Copyright (C) 1995,1996,1997,1998,2000,2001 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 | |
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | */ | |
1bbd0b84 | 17 | |
1bbd0b84 | 18 | |
0f2d19dd | 19 | \f |
c3f1a204 RB |
20 | #if HAVE_CONFIG_H |
21 | # include <config.h> | |
22 | #endif | |
0f2d19dd | 23 | |
e6e2e95a | 24 | #include <errno.h> |
6a4d17af | 25 | #include <stdlib.h> /* for getenv */ |
e6e2e95a | 26 | |
a0599745 | 27 | #include "libguile/_scm.h" |
95b88819 | 28 | |
a0599745 MD |
29 | #include "libguile/scmsigs.h" |
30 | #include "libguile/strings.h" | |
1bbd0b84 | 31 | |
a0599745 MD |
32 | #include "libguile/validate.h" |
33 | #include "libguile/simpos.h" | |
20e6290e | 34 | |
95b88819 GH |
35 | #ifdef HAVE_STRING_H |
36 | #include <string.h> | |
37 | #endif | |
0f2d19dd JB |
38 | #ifdef HAVE_UNISTD_H |
39 | #include <unistd.h> | |
40 | #endif | |
41 | ||
42 | \f | |
43 | extern int system(); | |
44 | \f | |
45 | ||
f25f761d | 46 | #ifdef HAVE_SYSTEM |
3b3b36dd | 47 | SCM_DEFINE (scm_system, "system", 0, 1, 0, |
1bbd0b84 | 48 | (SCM cmd), |
1e6808ea MG |
49 | "Execute @var{cmd} using the operating system's \"command\n" |
50 | "processor\". Under Unix this is usually the default shell\n" | |
51 | "@code{sh}. The value returned is @var{cmd}'s exit status as\n" | |
34b6177b KR |
52 | "returned by @code{waitpid}, which can be interpreted using\n" |
53 | "@code{status:exit-val} and friends.\n" | |
1e6808ea MG |
54 | "\n" |
55 | "If @code{system} is called without arguments, return a boolean\n" | |
d3818c29 | 56 | "indicating whether the command processor is available.") |
1bbd0b84 | 57 | #define FUNC_NAME s_scm_system |
0f2d19dd | 58 | { |
341eaef0 GH |
59 | int rv; |
60 | ||
61 | if (SCM_UNBNDP (cmd)) | |
62 | { | |
341eaef0 | 63 | rv = system (NULL); |
1bbd0b84 | 64 | return SCM_BOOL(rv); |
341eaef0 | 65 | } |
a6d9e5ab | 66 | SCM_VALIDATE_STRING (1, cmd); |
341eaef0 GH |
67 | SCM_DEFER_INTS; |
68 | errno = 0; | |
a6d9e5ab | 69 | rv = system (SCM_STRING_CHARS (cmd)); |
341eaef0 | 70 | if (rv == -1 || (rv == 127 && errno != 0)) |
1bbd0b84 | 71 | SCM_SYSERROR; |
341eaef0 GH |
72 | SCM_ALLOW_INTS; |
73 | return SCM_MAKINUM (rv); | |
341eaef0 | 74 | } |
1bbd0b84 | 75 | #undef FUNC_NAME |
f25f761d | 76 | #endif /* HAVE_SYSTEM */ |
0f2d19dd | 77 | |
a1ec6916 | 78 | SCM_DEFINE (scm_getenv, "getenv", 1, 0, 0, |
1bbd0b84 | 79 | (SCM nam), |
d3818c29 MD |
80 | "Looks up the string @var{name} in the current environment. The return\n" |
81 | "value is @code{#f} unless a string of the form @code{NAME=VALUE} is\n" | |
d46e4713 | 82 | "found, in which case the string @code{VALUE} is returned.") |
1bbd0b84 | 83 | #define FUNC_NAME s_scm_getenv |
0f2d19dd JB |
84 | { |
85 | char *val; | |
a6d9e5ab | 86 | SCM_VALIDATE_STRING (1, nam); |
86c991c2 | 87 | val = getenv (SCM_STRING_CHARS (nam)); |
36284627 | 88 | return val ? scm_mem2string (val, strlen (val)) : SCM_BOOL_F; |
0f2d19dd | 89 | } |
1bbd0b84 | 90 | #undef FUNC_NAME |
0f2d19dd | 91 | |
ee149d03 | 92 | /* simple exit, without unwinding the scheme stack or flushing ports. */ |
a1ec6916 | 93 | SCM_DEFINE (scm_primitive_exit, "primitive-exit", 0, 1, 0, |
1bbd0b84 | 94 | (SCM status), |
d3818c29 MD |
95 | "Terminate the current process without unwinding the Scheme stack.\n" |
96 | "This is would typically be useful after a fork. The exit status\n" | |
97 | "is @var{status} if supplied, otherwise zero.") | |
1bbd0b84 | 98 | #define FUNC_NAME s_scm_primitive_exit |
7ad3c1e7 GH |
99 | { |
100 | int cstatus = 0; | |
101 | if (!SCM_UNBNDP (status)) | |
102 | { | |
34d19ef6 | 103 | SCM_VALIDATE_INUM (1, status); |
7ad3c1e7 GH |
104 | cstatus = SCM_INUM (status); |
105 | } | |
106 | exit (cstatus); | |
107 | } | |
1bbd0b84 | 108 | #undef FUNC_NAME |
7ad3c1e7 | 109 | |
1cc91f1b | 110 | |
0f2d19dd JB |
111 | void |
112 | scm_init_simpos () | |
0f2d19dd | 113 | { |
a0599745 | 114 | #include "libguile/simpos.x" |
0f2d19dd JB |
115 | } |
116 | ||
89e00824 ML |
117 | |
118 | /* | |
119 | Local Variables: | |
120 | c-file-style: "gnu" | |
121 | End: | |
122 | */ |