Reimplement Qgets using Qgetc.

This commit is contained in:
Bill Currie 2010-11-28 11:18:07 +09:00
parent 813e2010da
commit 341726afb9

View file

@ -387,24 +387,21 @@ VISIBLE char *
Qgets (QFile *file, char *buf, int count) Qgets (QFile *file, char *buf, int count)
{ {
char *ret = buf; char *ret = buf;
char c;
if (file->c != -1) { while (buf - ret < count - 1) {
*buf++ = file->c; c = Qgetc (file);
count--; if (c < 0)
file->c = -1; break;
if (!count) *buf++ = c;
return ret; if (c == '\n')
break;
} }
if (file->file) if (buf == ret)
buf = fgets (buf, count, file->file);
else {
#ifdef HAVE_ZLIB
buf = gzgets (file->gzfile, buf, count);
#else
return 0; return 0;
#endif
} *buf++ = 0;
return buf ? ret : 0; return ret;
} }
VISIBLE int VISIBLE int
@ -537,7 +534,7 @@ Qeof (QFile *file)
/* /*
Qgetline Qgetline
Dynamic length version of Qgets. DO NOT free the buffer. Dynamic length version of Qgets. Do NOT free the buffer.
*/ */
VISIBLE const char * VISIBLE const char *
Qgetline (QFile *file) Qgetline (QFile *file)