summaryrefslogtreecommitdiff
path: root/iolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
commit2b5bc5d1a81579a76c13e638de2592e2c39c73f0 (patch)
tree8294278f9fbd2565d3a2cd11642fed41982824bd /iolib.c
parent94686ce58554a80374eeff115ee5b87c184ed173 (diff)
downloadlua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.gz
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.bz2
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.zip
new module for memory allocation
Diffstat (limited to 'iolib.c')
-rw-r--r--iolib.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/iolib.c b/iolib.c
index fbb9081e..2cfb8af7 100644
--- a/iolib.c
+++ b/iolib.c
@@ -3,18 +3,16 @@
3** Input/output library to LUA 3** Input/output library to LUA
4*/ 4*/
5 5
6char *rcs_iolib="$Id: iolib.c,v 1.14 1994/10/19 17:02:20 celes Exp roberto $"; 6char *rcs_iolib="$Id: iolib.c,v 1.15 1994/11/13 14:54:18 roberto Exp roberto $";
7 7
8#include <stdlib.h>
9#include <string.h>
10#include <stdio.h> 8#include <stdio.h>
11#include <ctype.h> 9#include <ctype.h>
12#include <time.h>
13#include <sys/stat.h> 10#include <sys/stat.h>
14#ifdef __GNUC__ 11#include <string.h>
15#include <floatingpoint.h> 12#include <time.h>
16#endif 13#include <stdlib.h>
17 14
15#include "mem.h"
18#include "lua.h" 16#include "lua.h"
19#include "lualib.h" 17#include "lualib.h"
20 18
@@ -215,7 +213,6 @@ static void io_read (void)
215 } 213 }
216 else 214 else
217 { 215 {
218 char *ptr;
219 double d; 216 double d;
220 ungetc (c, in); 217 ungetc (c, in);
221 if (fscanf (in, "%s", s) != 1) 218 if (fscanf (in, "%s", s) != 1)
@@ -223,8 +220,7 @@ static void io_read (void)
223 lua_pushnil (); 220 lua_pushnil ();
224 return; 221 return;
225 } 222 }
226 d = strtod (s, &ptr); 223 if (sscanf(s, "%lf %*c", &d) == 1)
227 if (!(*ptr))
228 { 224 {
229 lua_pushnumber (d); 225 lua_pushnumber (d);
230 return; 226 return;
@@ -327,20 +323,20 @@ static void io_readuntil (void)
327 else 323 else
328 d = *lua_getstring(lo); 324 d = *lua_getstring(lo);
329 325
330 s = calloc(n+1, sizeof(char)); 326 s = newvector(n+1, char);
331 while((c = fgetc(in)) != EOF && c != d) 327 while((c = fgetc(in)) != EOF && c != d)
332 { 328 {
333 if (m==n) 329 if (m==n)
334 { 330 {
335 n *= 2; 331 n *= 2;
336 s = realloc(s, (n+1)*sizeof(char)); 332 s = growvector(s, n+1, char);
337 } 333 }
338 s[m++] = c; 334 s[m++] = c;
339 } 335 }
340 if (c != EOF) ungetc(c,in); 336 if (c != EOF) ungetc(c,in);
341 s[m] = 0; 337 s[m] = 0;
342 lua_pushstring(s); 338 lua_pushstring(s);
343 free(s); 339 luaI_free(s);
344} 340}
345 341
346 342