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:
@@ -143,7 +143,7 @@ static naRef f_open(naContext c, naRef me, int argc, naRef* args)
|
||||
// frees buffer before tossing an error
|
||||
static int getcguard(naContext ctx, FILE* f, void* buf)
|
||||
{
|
||||
char c;
|
||||
int c;
|
||||
naModUnlock(); c = fgetc(f); naModLock();
|
||||
if(ferror(f)) {
|
||||
naFree(buf);
|
||||
@@ -159,8 +159,8 @@ static naRef f_readln(naContext ctx, naRef me, int argc, naRef* args)
|
||||
{
|
||||
naRef result;
|
||||
struct naIOGhost* g = argc==1 ? ioghost(args[0]) : 0;
|
||||
int i=0, sz = 128;
|
||||
char c, *buf;
|
||||
int i=0, sz = 128, c, c2;
|
||||
char *buf;
|
||||
if(!g || g->type != &naStdIOType)
|
||||
naRuntimeError(ctx, "bad argument to readln()");
|
||||
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);
|
||||
if(c == EOF || c == '\n') break;
|
||||
if(c == '\r') {
|
||||
char c2 = getcguard(ctx, g->handle, buf);
|
||||
c2 = getcguard(ctx, g->handle, buf);
|
||||
if(c2 != EOF && c2 != '\n')
|
||||
if(EOF == ungetc(c2, g->handle))
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user