function bbc_write_entry() { global $BBC_CACHE_PATH; $file = $this->filename; $base = basename($file); if (!is_readable($file)) { return array($base, "r"); } if (!is_writable($file)) { return array($base, "w"); } $fp = defined("_BBC_DIO") ? dio_open($file, O_RDWR | O_APPEND) : fopen($file, "ab+"); if (defined("_BBC_DIO") && dio_fcntl($fp, F_SETLK, 1) !== -1) { dio_write($fp, $this->string); dio_fcntl($fp, F_SETLK, 0); $ok = 1; } else { if (defined("_BBC_SEM") ? $id = bbc_semlock($file) : flock($fp, LOCK_EX)) { fputs($fp, $this->string); fflush($fp); defined("_BBC_SEM") ? sem_release($id) : flock($fp, LOCK_UN); $ok = 1; } } defined("_BBC_DIO") ? dio_close($fp) : fclose($fp); return isset($ok) ? array($base, "o") : array($base, "l"); }
function bbc_begin_write($file, $data) { $fp = defined("_BBC_DIO") ? dio_open($file, O_RDWR | O_APPEND) : fopen($file, "rb+"); if (defined("_BBC_DIO") && dio_fcntl($fp, F_SETLK, 1) !== -1) { dio_seek($fp, 0); dio_truncate($fp, 0); dio_write($fp, $data); return $fp; } elseif (defined("_BBC_SEM") ? $id = bbc_semlock($file) : flock($fp, LOCK_EX)) { rewind($fp); fwrite($fp, $data); fflush($fp); ftruncate($fp, ftell($fp)); return defined("_BBC_SEM") ? array($fp, $id) : $fp; } else { defined("_BBC_DIO") ? dio_close($fp) : fclose($fp); return false; } }