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