Fix typing error with fgetc in readln(). On most boxes, this would

cause a spurious EOF when there was a 0xff in the stream.  But on PPC,
char is unsigned (for reasons known only to IBM) and it would loop
forever.
This commit is contained in:
andy
2008-08-25 16:53:34 +00:00
parent 29aad066f0
commit e55f55cd3e
+4 -4
View File
@@ -143,7 +143,7 @@ static naRef f_open(naContext c, naRef me, int argc, naRef* args)
// frees buffer before tossing an error // frees buffer before tossing an error
static int getcguard(naContext ctx, FILE* f, void* buf) static int getcguard(naContext ctx, FILE* f, void* buf)
{ {
char c; int c;
naModUnlock(); c = fgetc(f); naModLock(); naModUnlock(); c = fgetc(f); naModLock();
if(ferror(f)) { if(ferror(f)) {
naFree(buf); naFree(buf);
@@ -159,8 +159,8 @@ static naRef f_readln(naContext ctx, naRef me, int argc, naRef* args)
{ {
naRef result; naRef result;
struct naIOGhost* g = argc==1 ? ioghost(args[0]) : 0; struct naIOGhost* g = argc==1 ? ioghost(args[0]) : 0;
int i=0, sz = 128; int i=0, sz = 128, c, c2;
char c, *buf; char *buf;
if(!g || g->type != &naStdIOType) if(!g || g->type != &naStdIOType)
naRuntimeError(ctx, "bad argument to readln()"); naRuntimeError(ctx, "bad argument to readln()");
buf = naAlloc(sz); buf = naAlloc(sz);
@@ -168,7 +168,7 @@ static naRef f_readln(naContext ctx, naRef me, int argc, naRef* args)
c = getcguard(ctx, g->handle, buf); c = getcguard(ctx, g->handle, buf);
if(c == EOF || c == '\n') break; if(c == EOF || c == '\n') break;
if(c == '\r') { if(c == '\r') {
char c2 = getcguard(ctx, g->handle, buf); c2 = getcguard(ctx, g->handle, buf);
if(c2 != EOF && c2 != '\n') if(c2 != EOF && c2 != '\n')
if(EOF == ungetc(c2, g->handle)) if(EOF == ungetc(c2, g->handle))
break; break;