diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-27 09:39:05 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-27 09:39:05 -0300 |
commit | 60d11ec31655c6c3f8fda787080e0908ac81b076 (patch) | |
tree | fe70f5ace4802bc7b3596b04f290fd7064dc0911 | |
parent | e1a424e8a35738bf56ecdad01155fb45b3001660 (diff) | |
download | lua-60d11ec31655c6c3f8fda787080e0908ac81b076.tar.gz lua-60d11ec31655c6c3f8fda787080e0908ac81b076.tar.bz2 lua-60d11ec31655c6c3f8fda787080e0908ac81b076.zip |
by default, gcc does not get tmpname
-rw-r--r-- | liolib.c | 46 |
1 files changed, 37 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.31 2003/02/11 15:24:52 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.32 2003/02/11 15:31:50 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 | */ |
@@ -22,20 +22,43 @@ | |||
22 | 22 | ||
23 | 23 | ||
24 | /* | 24 | /* |
25 | ** {====================================================== | 25 | ** by default, gcc does not get `tmpname' |
26 | ** FILE Operations | ||
27 | ** ======================================================= | ||
28 | */ | 26 | */ |
27 | #ifndef LUA_USETMPNAME | ||
28 | #ifdef __GNUC__ | ||
29 | #define LUA_USETMPNAME 0 | ||
30 | #else | ||
31 | #define LUA_USETMPNAME 1 | ||
32 | #endif | ||
33 | #endif | ||
29 | 34 | ||
30 | 35 | ||
36 | /* | ||
37 | ** by default, posix systems get `popen' | ||
38 | */ | ||
39 | #ifndef USE_POPEN | ||
31 | #ifdef _POSIX_C_SOURCE | 40 | #ifdef _POSIX_C_SOURCE |
32 | #if _POSIX_C_SOURCE >= 2 | 41 | #if _POSIX_C_SOURCE >= 2 |
33 | #define USE_POPEN | 42 | #define USE_POPEN 1 |
43 | #endif | ||
34 | #endif | 44 | #endif |
35 | #endif | 45 | #endif |
36 | |||
37 | 46 | ||
38 | #ifndef USE_POPEN | 47 | #ifndef USE_POPEN |
48 | #define USE_POPEN 0 | ||
49 | #endif | ||
50 | |||
51 | |||
52 | |||
53 | |||
54 | /* | ||
55 | ** {====================================================== | ||
56 | ** FILE Operations | ||
57 | ** ======================================================= | ||
58 | */ | ||
59 | |||
60 | |||
61 | #if !USE_POPEN | ||
39 | #define pclose(f) (-1) | 62 | #define pclose(f) (-1) |
40 | #endif | 63 | #endif |
41 | 64 | ||
@@ -180,7 +203,7 @@ static int io_open (lua_State *L) { | |||
180 | 203 | ||
181 | 204 | ||
182 | static int io_popen (lua_State *L) { | 205 | static int io_popen (lua_State *L) { |
183 | #ifndef USE_POPEN | 206 | #if !USE_POPEN |
184 | luaL_error(L, "`popen' not supported"); | 207 | luaL_error(L, "`popen' not supported"); |
185 | return 0; | 208 | return 0; |
186 | #else | 209 | #else |
@@ -247,10 +270,10 @@ static int io_output (lua_State *L) { | |||
247 | static int io_readline (lua_State *L); | 270 | static int io_readline (lua_State *L); |
248 | 271 | ||
249 | 272 | ||
250 | static void aux_lines (lua_State *L, int index, int close) { | 273 | static void aux_lines (lua_State *L, int idx, int close) { |
251 | lua_pushliteral(L, FILEHANDLE); | 274 | lua_pushliteral(L, FILEHANDLE); |
252 | lua_rawget(L, LUA_REGISTRYINDEX); | 275 | lua_rawget(L, LUA_REGISTRYINDEX); |
253 | lua_pushvalue(L, index); | 276 | lua_pushvalue(L, idx); |
254 | lua_pushboolean(L, close); /* close/not close file when finished */ | 277 | lua_pushboolean(L, close); /* close/not close file when finished */ |
255 | lua_pushcclosure(L, io_readline, 3); | 278 | lua_pushcclosure(L, io_readline, 3); |
256 | } | 279 | } |
@@ -546,11 +569,16 @@ static int io_rename (lua_State *L) { | |||
546 | 569 | ||
547 | 570 | ||
548 | static int io_tmpname (lua_State *L) { | 571 | static int io_tmpname (lua_State *L) { |
572 | #if !LUA_USETMPNAME | ||
573 | luaL_error(L, "`tmpname' not supported"); | ||
574 | return 0; | ||
575 | #else | ||
549 | char buff[L_tmpnam]; | 576 | char buff[L_tmpnam]; |
550 | if (tmpnam(buff) != buff) | 577 | if (tmpnam(buff) != buff) |
551 | return luaL_error(L, "unable to generate a unique filename"); | 578 | return luaL_error(L, "unable to generate a unique filename"); |
552 | lua_pushstring(L, buff); | 579 | lua_pushstring(L, buff); |
553 | return 1; | 580 | return 1; |
581 | #endif | ||
554 | } | 582 | } |
555 | 583 | ||
556 | 584 | ||