/**
* Seek the file
*
* Note: the return value is different to that of fseek
*
* @param integer $offset Offset to use when seeking.
* @param integer $whence Seek mode to use.
*
* @return boolean True on success, false on failure
*
* @link https://www.php.net/manual/en/function.fseek.php
* @since 1.7.0
*/
public function seek($offset, $whence = SEEK_SET)
{
if (!$this->fh) {
$this->setError(Text::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN'));
return false;
}
$retval = false;
// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
switch ($this->processingmethod) {
case 'gz':
$res = gzseek($this->fh, $offset, $whence);
break;
case 'bz':
case 'f':
default:
$res = fseek($this->fh, $offset, $whence);
break;
}
// Seek, interestingly, returns 0 on success or -1 on failure.
if ($res == -1) {
$this->setError($php_errormsg);
} else {
$retval = true;
}
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Return the result
return $retval;
}