]> granicus.if.org Git - php/commitdiff
Change fgets() behavior back to BC version
authorSara Golemon <pollita@php.net>
Thu, 7 Dec 2006 09:51:36 +0000 (09:51 +0000)
committerSara Golemon <pollita@php.net>
Thu, 7 Dec 2006 09:51:36 +0000 (09:51 +0000)
ext/standard/file.c

index 83c26994e89732a15b39a8c3c8b9d50ed750a732..457f1f24752a02f96f2b46ee49ecd08154ea1fa0 100644 (file)
@@ -1114,7 +1114,7 @@ PHPAPI PHP_FUNCTION(feof)
 }
 /* }}} */
 
-/* {{{ proto string fgets(resource fp[, int length]) U
+/* {{{ proto string fgets(resource fp[, int lengthish]) U
    Get a line from file pointer */
 PHPAPI PHP_FUNCTION(fgets)
 {
@@ -1131,6 +1131,11 @@ PHPAPI PHP_FUNCTION(fgets)
 
        php_stream_from_zval(stream, &zstream);
 
+       if (length > 0) {
+               /* For BC reasons, fgets() should only return length-1 bytes. */
+               length--;
+       }
+
        buf.v = php_stream_get_line_ex(stream, stream->readbuf_type, NULL_ZSTR, 0, length, &retlen);
        if (!buf.v) {
                RETURN_FALSE;