]> granicus.if.org Git - php/commitdiff
Make the length parameter to fgets optional (defaults to 1024)
authorSterling Hughes <sterling@php.net>
Tue, 4 Dec 2001 19:40:48 +0000 (19:40 +0000)
committerSterling Hughes <sterling@php.net>
Tue, 4 Dec 2001 19:40:48 +0000 (19:40 +0000)
ext/standard/file.c

index 50c6c6855197e5622c85e6c95347d42dfcbef71c..016afd6afa4b331e2c9dc12dc366ba6d8b275b50 100644 (file)
@@ -966,26 +966,29 @@ PHP_FUNCTION(socket_get_status)
 /* }}} */
 
 
-/* {{{ proto string fgets(resource fp, int length)
+/* {{{ proto string fgets(resource fp[, int length])
    Get a line from file pointer */
 PHP_FUNCTION(fgets)
 {
        zval **arg1, **arg2;
-       int len, type;
+       int len = 1024, type;
        char *buf;
        int issock=0;
        int socketd=0;
        void *what;
+       int argc = ZEND_NUM_ARGS();
 
-       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
+       if (argc<1 || argc>2 || zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
 
        what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
        ZEND_VERIFY_RESOURCE(what);
 
-       convert_to_long_ex(arg2);
-       len = Z_LVAL_PP(arg2);
+       if (argc>1) {
+               convert_to_long_ex(arg2);
+               len = Z_LVAL_PP(arg2);
+       }
 
        if (len < 0) {
                php_error(E_WARNING, "length parameter to fgets() may not be negative");