diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-04-23 09:43:07 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-04-23 09:43:07 -0300 |
| commit | eadbb9cff4378fa64f81d6944a26c3a216757ad6 (patch) | |
| tree | 555eb642670e2b5df63f9caccc2009e9f0449e46 | |
| parent | 42b947296b82d33b3ad2806eee096a87cf236161 (diff) | |
| download | lua-eadbb9cff4378fa64f81d6944a26c3a216757ad6.tar.gz lua-eadbb9cff4378fa64f81d6944a26c3a216757ad6.tar.bz2 lua-eadbb9cff4378fa64f81d6944a26c3a216757ad6.zip | |
"stat" is not ansi.
| -rw-r--r-- | iolib.c | 10 |
1 files changed, 3 insertions, 7 deletions
| @@ -3,12 +3,11 @@ | |||
| 3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_iolib="$Id: iolib.c,v 1.40 1996/03/19 22:28:37 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.41 1996/04/22 19:28:37 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| 10 | #include <sys/types.h> | 10 | #include <sys/types.h> |
| 11 | #include <sys/stat.h> | ||
| 12 | #include <string.h> | 11 | #include <string.h> |
| 13 | #include <time.h> | 12 | #include <time.h> |
| 14 | #include <stdlib.h> | 13 | #include <stdlib.h> |
| @@ -125,15 +124,12 @@ static void io_writeto (void) | |||
| 125 | ** LUA interface: | 124 | ** LUA interface: |
| 126 | ** status = appendto (filename) | 125 | ** status = appendto (filename) |
| 127 | ** where: | 126 | ** where: |
| 128 | ** status = 2 -> success (already exist) | 127 | ** status = 1 -> success |
| 129 | ** status = 1 -> success (new file) | ||
| 130 | ** status = nil -> error | 128 | ** status = nil -> error |
| 131 | */ | 129 | */ |
| 132 | static void io_appendto (void) | 130 | static void io_appendto (void) |
| 133 | { | 131 | { |
| 134 | char *s = lua_check_string(1, "appendto"); | 132 | char *s = lua_check_string(1, "appendto"); |
| 135 | struct stat st; | ||
| 136 | int r = (stat(s, &st) == -1) ? 1 : 2; | ||
| 137 | FILE *fp = fopen (s, "a"); | 133 | FILE *fp = fopen (s, "a"); |
| 138 | if (fp == NULL) | 134 | if (fp == NULL) |
| 139 | lua_pushnil(); | 135 | lua_pushnil(); |
| @@ -141,7 +137,7 @@ static void io_appendto (void) | |||
| 141 | { | 137 | { |
| 142 | if (out != stdout) fclose (out); | 138 | if (out != stdout) fclose (out); |
| 143 | out = fp; | 139 | out = fp; |
| 144 | lua_pushnumber (r); | 140 | lua_pushnumber(1); |
| 145 | } | 141 | } |
| 146 | } | 142 | } |
| 147 | 143 | ||
