Mercurial > cpython-lru_cache-weakref
annotate Modules/environment.c @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | 3cf896d24e50 |
| children |
| rev | line source |
|---|---|
|
2737
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /* |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 # Copyright 1995, InfoSeek Corporation |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 # All rights reserved. |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 # Written by Andy Bensky |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 # |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 # Permission to use, copy, modify, and distribute this Python software |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 # and its associated documentation for any purpose (subject to the |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 # restriction in the following sentence) without fee is hereby granted, |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 # provided that the above copyright notice appears in all copies, and |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 # that both that copyright notice and this permission notice appear in |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 # supporting documentation, and that the name of InfoSeek not be used in |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 # advertising or publicity pertaining to distribution of the software |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 # without specific, prior written permission. This permission is |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 # explicitly restricted to the copying and modification of the software |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 # to remain in Python, compiled Python, or other languages (such as C) |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 # wherein the modified or derived code is exclusively imported into a |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 # Python module. |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 # |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 # INFOSEEK CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 # SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 # FITNESS. IN NO EVENT SHALL INFOSEEK CORPORATION BE LIABLE FOR ANY |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 # DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 # EVEN IF INFOSEEK SHALL HAVE BEEN MADE AWARE OF THE POSSIBILITY OF SUCH |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 # DAMAGES. |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 */ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 /* Hooks to call the Unix putenv() to modify the environment |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 */ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 #include "allobjects.h" |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 #include <stdlib.h> |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 #include <assert.h> |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 #include <string.h> |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 /* Error conditions that can be raised */ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 /* Headers for functions accessible from Python as module methods */ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 static object *put_environ( object *self, object *args ); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 static struct methodlist environ_methods[] = { |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 {"putenv", put_environ}, |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 {NULL, NULL} |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 }; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 /* |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 * Name: initenvironment |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 * Description: |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 * Initialzation function that Python will use to establish callbacks to |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 * the methods of this module. |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 * |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 * Returns: |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 * void - |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 * |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 * Notes: |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 */ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 void initenvironment() |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 { |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 object *m, *d; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 m = initmodule("environment", environ_methods); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 d = getmoduledict(m); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 } |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 /* |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 * Name: put_environ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 * Description: |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 * accepts 2 string objects as arguments and forms a string of the |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 * form string1=string2 that can be passed to the putenv() system call. |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 * |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 * Returns: |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 * None object if successfull, otherwise raises a SystemError exception |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 * |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 * |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 * Notes: |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 */ |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 static object *put_environ( object *self, object *args ) |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 { |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 char *string1, *string2; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 char *set_str; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 object *return_object = None; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 if (args && getargs(args, "(ss)", &string1, &string2)) |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 { |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 set_str = malloc(strlen(string1) + strlen(string2) + 2); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 assert( set_str ); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 (void) sprintf(set_str, "%s=%s", string1, string2); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 if ( putenv( set_str ) ) |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 { |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 err_setstr(SystemError, "Error in system putenv call."); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 return_object = 0; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 } |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 } |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 else |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 { |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 err_setstr(TypeError, "Usage: putenv(string1, string2)"); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 return_object = 0; |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 } |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 return( return_object ); |
|
3cf896d24e50
new modules soundex.c and environment.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 } |
