From: Markus Fischer Date: Tue, 11 Jun 2002 21:22:12 +0000 (+0000) Subject: - Fix builtin gets() emulation (hopefully). X-Git-Tag: php5_5_0~64 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17b3ef47f3903fa2dfb0bda9302fcbfb8a012f25;p=php - Fix builtin gets() emulation (hopefully). --- diff --git a/main/streams.c b/main/streams.c index fa1a9f8f15..ea1844871f 100755 --- a/main/streams.c +++ b/main/streams.c @@ -250,21 +250,13 @@ PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRML return NULL; } else { /* unbuffered fgets - poor performance ! */ - size_t n = 1; char *c = buf; /* TODO: look at error returns? */ - while(n < maxlen && stream->ops->read(stream, c, 1 TSRMLS_CC) > 0) { - n++; - if (*c == '\n') { - c++; - break; - } - c++; - } - *c = 0; - return buf; + while (--maxlen > 0 && stream->ops->read(stream, buf, 1 TSRMLS_CC) == 1 && *buf++ != '\n'); + *buf = '\0'; + return c == buf && maxlen > 0 ? NULL : c; } }