#6090 [Opn->Csd]: fseek() returns -1 (not false) if an error occurs.

From: Date: Mon, 28 Oct 2002 01:31:00 +0000
Subject: #6090 [Opn->Csd]: fseek() returns -1 (not false) if an error occurs.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23503@lists.php.net to get a copy of this message
ID: 6090 Updated by: sterling@php.net Reported By: sagawa@sohgoh.net -Status: Open +Status: Closed Bug Type: Feature/Change Request Operating System: Linux PHP Version: 4.0.1pl2 New Comment: whole thing changed now with streams... Previous Comments: ------------------------------------------------------------------------ [2002-04-01 19:20:36] sniper@php.net Changed the subject since ftell() was fixed a while ago. fseek() still returns 0 on success and -1 on error which is not really the 'PHP way'. ------------------------------------------------------------------------ [2000-08-10 22:43:23] stas@php.net On the second thought, it is - it should detect -1 return and return false, but I'm not sure if it won't break something... So documentation is right, code is wrong, I guess. ------------------------------------------------------------------------ [2000-08-10 22:25:46] sagawa@sohgoh.net Umm... what I want to say, PHP's ftell function returns directly C's ftell(). So, this is "Documentation problem", isn't it? Please see below... (Quote from /ext/standerd/file.c ) ----------------------------------- /* {{{ proto int fseek(int fp, int offset [, int whence]) Seek on a file pointer */ PHP_FUNCTION(fseek) { zval **arg1, **arg2, **arg3; int argcount = ARG_COUNT(ht), whence = SEEK_SET; void *what; if (argcount < 2 || argcount > 3 || zend_get_parameters_ex(argcount, &arg1, &arg2, &arg3) == FAILURE) { WRONG_PARAM_COUNT; } what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen); ZEND_VERIFY_RESOURCE(what); convert_to_long_ex(arg2); if (argcount > 2) { convert_to_long_ex(arg3); whence = (*arg3)->value.lval; } RETURN_LONG(fseek((FILE*)what, (*arg2)->value.lval, whence)); } /* }}} */ ----------------------------------- ------------------------------------------------------------------------ [2000-08-10 21:53:48] stas@php.net PHP functions return false on error. So I reclassify it to change request. ------------------------------------------------------------------------ [2000-08-10 21:45:33] sagawa@sohgoh.net Quote from Linux Programmer's Manual fseek(3)... >RETURN VALUES > The rewind function returns no value. Upon successful > completion, fgetpos, fseek, fsetpos return 0, and ftell > returns the current offset. Otherwise, -1 is returned and > the global variable errno is set to indicate the error. So, we get 0(=false) if file position is begining of file. But that's not error. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=6090&edit=1

« previous php.bugs (#23503) next »