diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-02-05 13:22:43 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-02-05 13:22:43 -0200 |
commit | b22baf386d40aba5e11bd66f4c69acdf0e9219a1 (patch) | |
tree | 201b8e1d81ced33577626e9b43030f185bcd4288 | |
parent | 8fdd06ba3c92c7ca7fbf25748bfa32635e4c003a (diff) | |
download | lua-b22baf386d40aba5e11bd66f4c69acdf0e9219a1.tar.gz lua-b22baf386d40aba5e11bd66f4c69acdf0e9219a1.tar.bz2 lua-b22baf386d40aba5e11bd66f4c69acdf0e9219a1.zip |
Lua cannot have static variables.
-rw-r--r-- | liolib.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.28 1998/12/28 13:44:54 roberto Exp $ | 2 | ** $Id: liolib.c,v 1.29 1999/01/04 12:41:12 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -40,6 +40,7 @@ | |||
40 | #define FINPUT "_INPUT" | 40 | #define FINPUT "_INPUT" |
41 | #define FOUTPUT "_OUTPUT" | 41 | #define FOUTPUT "_OUTPUT" |
42 | 42 | ||
43 | #define MODESIZE 3 /* string for file mode */ | ||
43 | 44 | ||
44 | #ifdef POPEN | 45 | #ifdef POPEN |
45 | FILE *popen(); | 46 | FILE *popen(); |
@@ -108,15 +109,13 @@ static FILE *getfileparam (char *name, int *arg) { | |||
108 | } | 109 | } |
109 | 110 | ||
110 | 111 | ||
111 | static char *getmode (char mode) { | 112 | static void getmode (char mode, char *m) { |
112 | static char m[3]; | ||
113 | m[0] = mode; | 113 | m[0] = mode; |
114 | if (*luaL_opt_string(FIRSTARG+1, "text") == 'b') { | 114 | if (*luaL_opt_string(FIRSTARG+1, "text") == 'b') { |
115 | m[1] = 'b'; | 115 | m[1] = 'b'; |
116 | m[2] = '\0'; | 116 | m[2] = '\0'; |
117 | } | 117 | } |
118 | else m[1] = '\0'; | 118 | else m[1] = '\0'; |
119 | return m; | ||
120 | } | 119 | } |
121 | 120 | ||
122 | 121 | ||
@@ -154,7 +153,9 @@ static void io_readfrom (void) { | |||
154 | current = lua_getuserdata(f); | 153 | current = lua_getuserdata(f); |
155 | else { | 154 | else { |
156 | char *s = luaL_check_string(FIRSTARG); | 155 | char *s = luaL_check_string(FIRSTARG); |
157 | current = (*s == '|') ? popen(s+1, "r") : fopen(s, getmode('r')); | 156 | char m[MODESIZE]; |
157 | getmode('r', m); | ||
158 | current = (*s == '|') ? popen(s+1, "r") : fopen(s, m); | ||
158 | if (current == NULL) { | 159 | if (current == NULL) { |
159 | pushresult(0); | 160 | pushresult(0); |
160 | return; | 161 | return; |
@@ -175,7 +176,9 @@ static void io_writeto (void) { | |||
175 | current = lua_getuserdata(f); | 176 | current = lua_getuserdata(f); |
176 | else { | 177 | else { |
177 | char *s = luaL_check_string(FIRSTARG); | 178 | char *s = luaL_check_string(FIRSTARG); |
178 | current = (*s == '|') ? popen(s+1,"w") : fopen(s,getmode('w')); | 179 | char m[MODESIZE]; |
180 | getmode('w', m); | ||
181 | current = (*s == '|') ? popen(s+1,"w") : fopen(s, m); | ||
179 | if (current == NULL) { | 182 | if (current == NULL) { |
180 | pushresult(0); | 183 | pushresult(0); |
181 | return; | 184 | return; |
@@ -187,7 +190,10 @@ static void io_writeto (void) { | |||
187 | 190 | ||
188 | static void io_appendto (void) { | 191 | static void io_appendto (void) { |
189 | char *s = luaL_check_string(FIRSTARG); | 192 | char *s = luaL_check_string(FIRSTARG); |
190 | FILE *fp = fopen (s, getmode('a')); | 193 | char m[MODESIZE]; |
194 | FILE *fp; | ||
195 | getmode('a', m); | ||
196 | fp = fopen (s, m); | ||
191 | if (fp != NULL) | 197 | if (fp != NULL) |
192 | setreturn(fp, FOUTPUT); | 198 | setreturn(fp, FOUTPUT); |
193 | else | 199 | else |