summaryrefslogtreecommitdiff
path: root/ext/standard/file.c
diff options
context:
space:
mode:
authorSterling Hughes <sterling@php.net>2001-12-04 19:40:48 +0000
committerSterling Hughes <sterling@php.net>2001-12-04 19:40:48 +0000
commit886ad91adf417b9e4ac1a49a68b8faa13c3ff3ee (patch)
treeff6cbc71031b391310005d00401a262fcd6109a1 /ext/standard/file.c
parent08978fc3f45defb074a5d6c8fe581cf49baf3650 (diff)
downloadphp-git-886ad91adf417b9e4ac1a49a68b8faa13c3ff3ee.tar.gz
Make the length parameter to fgets optional (defaults to 1024)
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r--ext/standard/file.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 50c6c68551..016afd6afa 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -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");