function write_body_c($data, $i, &$len, &$offset)
{
    $MAX_FILE_SIZE = 2147483647;
    $len = strlen($data);
    if (!isset($GLOBALS['__FUD_TMP_F__'])) {
        $GLOBALS['__FUD_TMP_F__'][$i][0] = fopen($GLOBALS['MSG_STORE_DIR'] . 'tmp_msg_' . $i, 'ab');
        flock($GLOBALS['__FUD_TMP_F__'][$i][0], LOCK_EX);
        $GLOBALS['__FUD_TMP_F__'][$i][1] = __ffilesize($GLOBALS['__FUD_TMP_F__'][$i][0]);
    }
    while ($GLOBALS['__FUD_TMP_F__'][$i][1] + $len > $MAX_FILE_SIZE) {
        $i++;
        $GLOBALS['__FUD_TMP_F__'][$i][0] = fopen($GLOBALS['MSG_STORE_DIR'] . 'tmp_msg_' . $i, 'ab');
        flock($GLOBALS['__FUD_TMP_F__'][$i][0], LOCK_EX);
        $GLOBALS['__FUD_TMP_F__'][$i][1] = __ffilesize($GLOBALS['__FUD_TMP_F__'][$i][0]);
    }
    if (fwrite($GLOBALS['__FUD_TMP_F__'][$i][0], $data) != $len || !fflush($GLOBALS['__FUD_TMP_F__'][$i][0])) {
        exit("FATAL ERROR: system has ran out of disk space<br>\n");
    }
    $offset = $GLOBALS['__FUD_TMP_F__'][$i][1];
    $GLOBALS['__FUD_TMP_F__'][$i][1] += $len;
    return $i;
}
function write_pmsg_body($text)
{
    if (!db_locked()) {
        $ll = 1;
        db_lock('phpgw_fud_pmsg WRITE');
    }
    $fp = fopen($GLOBALS['MSG_STORE_DIR'] . 'private', 'ab');
    fseek($fp, 0, SEEK_END);
    if (!($s = ftell($fp))) {
        $s = __ffilesize($fp);
    }
    if (($len = fwrite($fp, $text)) !== strlen($text)) {
        exit("FATAL ERROR: system has ran out of disk space<br>\n");
    }
    fclose($fp);
    if (isset($ll)) {
        db_unlock();
    }
    if (!$s) {
        chmod($GLOBALS['MSG_STORE_DIR'] . 'private', $GLOBALS['FUD_OPT_2'] & 8388608 ? 0600 : 0666);
    }
    return array($s, $len);
}
function write_body($data, &$len, &$offset)
{
    $MAX_FILE_SIZE = 2147483647;
    $len = strlen($data);
    $i = 1;
    while ($i < 100) {
        $fp = fopen($GLOBALS['MSG_STORE_DIR'] . 'msg_' . $i, 'ab');
        fseek($fp, 0, SEEK_END);
        if (!($off = ftell($fp))) {
            $off = __ffilesize($fp);
        }
        if (!$off || $off + $len < $MAX_FILE_SIZE) {
            break;
        }
        fclose($fp);
        $i++;
    }
    if (fwrite($fp, $data) !== $len) {
        exit("FATAL ERROR: system has ran out of disk space<br>\n");
    }
    fclose($fp);
    if (!$off) {
        @chmod('msg_' . $i, $GLOBALS['FUD_OPT_2'] & 8388608 ? 0600 : 0666);
    }
    $offset = $off;
    return $i;
}