⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.c

📁 业界著名的tomcat服务器的最新6.0的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 *
 * @author Mladen Turk
 * @version $Revision: 466609 $, $Date: 2006-10-22 01:30:39 +0200 (dim., 22 oct. 2006) $
 */
 
#include "tcn.h"
#include "apr_file_io.h"


TCN_IMPLEMENT_CALL(jint, File, close)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_close(f);
}

TCN_IMPLEMENT_CALL(jint, File, eof)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_eof(f);
}

TCN_IMPLEMENT_CALL(jint, File, flush)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_flush(f);
}

TCN_IMPLEMENT_CALL(jint, File, unlock)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_unlock(f);
}

TCN_IMPLEMENT_CALL(jint, File, flagsGet)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_flags_get(f);
}

TCN_IMPLEMENT_CALL(jint, File, lock)(TCN_STDARGS, jlong file, jint flags)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_lock(f, (int)flags);
}

TCN_IMPLEMENT_CALL(jint, File, trunc)(TCN_STDARGS, jlong file, jlong off)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_trunc(f, (apr_off_t)off);
}

TCN_IMPLEMENT_CALL(jlong, File, open)(TCN_STDARGS, jstring fname,
                                      jint flag, jint perm,
                                      jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    apr_file_t *f = NULL;
    TCN_ALLOC_CSTRING(fname);

    UNREFERENCED(o);
    TCN_THROW_IF_ERR(apr_file_open(&f, J2S(fname), (apr_int32_t)flag,
                     (apr_fileperms_t)perm, p), f);

cleanup:
    TCN_FREE_CSTRING(fname);
    return P2J(f);
}

TCN_IMPLEMENT_CALL(jlong, File, mktemp)(TCN_STDARGS, jstring templ,
                                      jint flags,
                                      jint pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    apr_file_t *f = NULL;
    char *ctempl = tcn_strdup(e, templ);

    UNREFERENCED(o);
    if (!ctempl) {
       TCN_THROW_OS_ERROR(e);
       return 0;
    }
    TCN_THROW_IF_ERR(apr_file_mktemp(&f, ctempl,
                     (apr_int32_t)flags, p), f);

cleanup:
    free(ctempl);
    return P2J(f);
}

TCN_IMPLEMENT_CALL(jint, File, remove)(TCN_STDARGS, jstring path, jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    TCN_ALLOC_CSTRING(path);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_remove(J2S(path), p);
    TCN_FREE_CSTRING(path);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jint, File, rename)(TCN_STDARGS, jstring from,
                                       jstring to, jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    TCN_ALLOC_CSTRING(from);
    TCN_ALLOC_CSTRING(to);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_rename(J2S(from), J2S(to), p);
    TCN_FREE_CSTRING(from);
    TCN_FREE_CSTRING(to);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jint, File, copy)(TCN_STDARGS, jstring from,
                                     jstring to, jint perms, jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    TCN_ALLOC_CSTRING(from);
    TCN_ALLOC_CSTRING(to);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_copy(J2S(from), J2S(to), (apr_fileperms_t)perms, p);
    TCN_FREE_CSTRING(from);
    TCN_FREE_CSTRING(to);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jint, File, append)(TCN_STDARGS, jstring from,
                                       jstring to, jint perms, jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    TCN_ALLOC_CSTRING(from);
    TCN_ALLOC_CSTRING(to);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_append(J2S(from), J2S(to), (apr_fileperms_t)perms, p);
    TCN_FREE_CSTRING(from);
    TCN_FREE_CSTRING(to);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jstring, File, nameGet)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    jstring name = NULL;
    const char *fname;

    UNREFERENCED(o);
    if (apr_file_name_get(&fname, f) == APR_SUCCESS)
        name = AJP_TO_JSTRING(fname);

    return name;
}

TCN_IMPLEMENT_CALL(jint, File, permsSet)(TCN_STDARGS, jstring file, jint perms)
{
    TCN_ALLOC_CSTRING(file);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_perms_set(J2S(file), (apr_fileperms_t)perms);
    TCN_FREE_CSTRING(file);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jint, File, attrsSet)(TCN_STDARGS, jstring file, jint attrs,
                                          jint mask, jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    TCN_ALLOC_CSTRING(file);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_attrs_set(J2S(file), (apr_fileattrs_t)attrs,
                            (apr_fileattrs_t)mask, p);
    TCN_FREE_CSTRING(file);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jint, File, mtimeSet)(TCN_STDARGS, jstring file, jlong mtime,
                                          jlong pool)
{
    apr_pool_t *p = J2P(pool, apr_pool_t *);
    TCN_ALLOC_CSTRING(file);
    apr_status_t rv;

    UNREFERENCED(o);
    rv = apr_file_mtime_set(J2S(file), J2T(mtime), p);
    TCN_FREE_CSTRING(file);
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jlong, File, seek)(TCN_STDARGS, jlong file,
                                      jint where, jlong offset)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    apr_off_t pos = (apr_off_t)offset;
    apr_seek_where_t w;
    UNREFERENCED(o);
    switch (where) {
        case 1:
            w = APR_CUR;
            break;
        case 2:
            w = APR_END;
            break;
        default:
            w = APR_SET;
            break;
    }
    TCN_THROW_IF_ERR(apr_file_seek(f, w, &pos), pos);

cleanup:
    return (jlong)pos;
}

TCN_IMPLEMENT_CALL(jint, File, putc)(TCN_STDARGS, jbyte c, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_putc((char)c, f);
}

TCN_IMPLEMENT_CALL(jint, File, getc)(TCN_STDARGS, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    char ch;

    UNREFERENCED_STDARGS;
    TCN_THROW_IF_ERR(apr_file_getc(&ch, f), ch);

cleanup:
    return (jint)ch;
}

TCN_IMPLEMENT_CALL(jint, File, ungetc)(TCN_STDARGS, jbyte c, jlong file)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    UNREFERENCED_STDARGS;
    return (jint)apr_file_ungetc((char)c, f);
}

TCN_IMPLEMENT_CALL(jint, File, puts)(TCN_STDARGS, jbyteArray str, jlong file)
{
    apr_status_t rv = APR_EINVAL;
    apr_file_t *f = J2P(file, apr_file_t *);
    jbyte *bytes = (*e)->GetPrimitiveArrayCritical(e, str, NULL);

    UNREFERENCED(o);
    if (bytes) {
        rv = apr_file_puts((const char *)bytes, f);
        (*e)->ReleasePrimitiveArrayCritical(e, str, bytes, JNI_ABORT);
    }
    return (jint)rv;
}

TCN_IMPLEMENT_CALL(jint, File, write)(TCN_STDARGS, jlong file,
                                      jbyteArray buf, jint offset, jint towrite)
{
    apr_file_t *f = J2P(file, apr_file_t *);
    apr_size_t nbytes = (apr_size_t)towrite;
    jbyte *bytes = (*e)->GetPrimitiveArrayCritical(e, buf, NULL);
    apr_status_t ss;

    UNREFERENCED(o);
    if (towrite < 0)
        towrite = (*e)->GetArrayLength(e, buf);
    ss = apr_file_write(f, bytes + offset, &nbytes);

    (*e)->ReleasePrimitiveArrayCritical(e, buf, bytes, JNI_ABORT);
    if (ss == APR_SUCCESS)
        return (jint)nbytes;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -