php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #6090 fseek() returns -1 (not false) if an error occurs.
Submitted: 2000-08-10 21:45 UTC Modified: 2002-10-27 19:30 UTC
From: sagawa at sohgoh dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.1pl2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sagawa at sohgoh dot net
New email:
PHP Version: OS:

 

 [2000-08-10 21:45 UTC] sagawa at sohgoh dot 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-10 21:53 UTC] stas@php.net
PHP functions return false on error. So I reclassify it to change request.
 [2000-08-10 22:25 UTC] sagawa at sohgoh dot 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 22:43 UTC] 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.
 [2002-04-01 19:20 UTC] 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'. 

 [2002-10-27 19:30 UTC] sterling@php.net
whole thing changed now with streams...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC