|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-03 11:26 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
Description: ------------ multiple calls of fwrite() do not store data in the file, except last call, when opened large files (about 16mb) with fopen(filename, 'a+b') This error does not appear when files opened with fopen(filename, 'r+b'); Reproduce code: --------------- define(BUFFER_SIZE, 65536); function fCut($f, $pos, $size) { $fst = fstat($f); $fs = $fst["size"]; if (($pos < 0) || ($pos >= $fs) || ($size <= 0)) return false; $ps = $pos; $sz = $fs - $ps - $size; while ($sz > 0) { $s = $sz; if ($s > BUFFER_SIZE) { $s = BUFFER_SIZE; } fseek($f, $ps + $size); $buf = fread($f, $s); fseek($f, $ps); $l = fwrite($f, $buf); $sz -= $s; $ps += $s; } ftruncate($f, max($fs - $size, $pos)); return true; } // fCut - cutting $size bites in $f, from $pos $f = fopen(filename, 'a+b'); flock($f, 2); fcut($f, 0, 123456); flock($f, 3); fclose($f); Expected result: ---------------- 123456 bites of file 'filename' must be deleted from position 0; Actual result: -------------- all data still the same, except block that transfered with last calls of fread/fwrite. Note: this bug appears only in 'a+b' mode, but in 'r+b' all works fine.