From aa08686c8531baccc3e2860ba71f960e6496ee86 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Fri, 8 Dec 2006 01:02:49 +0000 Subject: [PATCH] More BC bodges for fgets/fgetss --- ext/standard/file.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index a9a6acd07c..6903538d62 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1129,13 +1129,15 @@ PHPAPI PHP_FUNCTION(fgets) RETURN_NULL(); } - php_stream_from_zval(stream, &zstream); - - if (length > 0) { + if (length == 1) { /* For BC reasons, fgets() should only return length-1 bytes. */ + RETURN_FALSE; + } else if (length > 1) { length--; } + php_stream_from_zval(stream, &zstream); + buf.v = php_stream_get_line_ex(stream, stream->readbuf_type, NULL_ZSTR, 0, length, &retlen); if (!buf.v) { RETURN_FALSE; @@ -1180,7 +1182,7 @@ PHPAPI PHP_FUNCTION(fgetc) } /* }}} */ -/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags]) U +/* {{{ proto string fgetss(resource fp [, int lengthish, string allowable_tags]) U Get a line from file pointer and strip HTML tags */ PHPAPI PHP_FUNCTION(fgetss) { @@ -1194,6 +1196,13 @@ PHPAPI PHP_FUNCTION(fgetss) return; } + if (length == 1) { + /* For BC reasons, fgetss() should only return length-1 bytes. */ + RETURN_FALSE; + } else if (length > 1) { + length--; + } + php_stream_from_zval(stream, &zstream); if (length > 0) { -- 2.50.1