removed unused functionality to load a subset of lines from a file in

Smarty::_read_file()

additionally removed a warning that is emitted since php-4.3.5 when
fread() is called on an empty file (with filesize()==0). thanks to
Andreas Streichardt who pointed this out.
This commit is contained in:
messju
2004-04-12 12:38:36 +00:00
parent 0af74476bc
commit 91549d3dba
3 changed files with 8 additions and 31 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- removed unused functionality to load a subset of lines from a file (messju)
- fix is_secure() should only check if a file is_readable, not if
the directory where it is in is readable (sagi, messju)
- fix problem displaying debug console when $default_resource_type

View File

@@ -240,7 +240,7 @@ class Config_File {
return false;
}
$contents = fread($fp, filesize($config_file));
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
fclose($fp);
$this->_config_data[$config_file] = $this->parse_contents($contents);

View File

@@ -1702,39 +1702,15 @@ class Smarty
* @param integer $lines
* @return string
*/
function _read_file($filename, $start=null, $lines=null)
function _read_file($filename)
{
if (!($fd = @fopen($filename, 'r'))) {
if ($fd = @fopen($filename, 'rb')) {
$contents = ($size = filesize($filename)) ? fread($fd, $size) : '';
fclose($fd);
return $contents;
} else {
return false;
}
flock($fd, LOCK_SH);
if ($start == null && $lines == null) {
// read the entire file
$contents = fread($fd, filesize($filename));
} else {
if ( $start > 1 ) {
// skip the first lines before $start
for ($loop=1; $loop < $start; $loop++) {
fgets($fd, 65536);
}
}
if ( $lines == null ) {
// read the rest of the file
while (!feof($fd)) {
$contents .= fgets($fd, 65536);
}
} else {
// read up to $lines lines
for ($loop=0; $loop < $lines; $loop++) {
$contents .= fgets($fd, 65536);
if (feof($fd)) {
break;
}
}
}
}
fclose($fd);
return $contents;
}
/**