📄 file.c
字号:
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writeb)(TCN_STDARGS, jlong file,
jobject buf, jint offset, jint towrite)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)towrite;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
apr_status_t ss = APR_EINVAL;
UNREFERENCED(o);
if (bytes)
ss = apr_file_write(f, bytes + offset, &nbytes);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writeFull)(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;
apr_size_t written = 0;
apr_status_t ss;
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
UNREFERENCED(o);
if (towrite < 0)
towrite = (*e)->GetArrayLength(e, buf);
ss = apr_file_write_full(f, bytes + offset, nbytes, &written);
(*e)->ReleaseByteArrayElements(e, buf, bytes, JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writeFullb)(TCN_STDARGS, jlong file,
jobject buf, jint offset, jint towrite)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)towrite;
apr_size_t written = 0;
apr_status_t ss = APR_EINVAL;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
UNREFERENCED(o);
if (bytes)
ss = apr_file_write_full(f, bytes + offset, nbytes, &written);
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writev)(TCN_STDARGS, jlong file,
jobjectArray bufs)
{
apr_file_t *f = J2P(file, apr_file_t *);
jsize nvec = (*e)->GetArrayLength(e, bufs);
jsize i;
struct iovec vec[APR_MAX_IOVEC_SIZE];
jobject ba[APR_MAX_IOVEC_SIZE];
apr_size_t written = 0;
apr_status_t ss;
UNREFERENCED(o);
if (nvec >= APR_MAX_IOVEC_SIZE) {
/* TODO: Throw something here */
return 0;
}
for (i = 0; i < nvec; i++) {
ba[i] = (*e)->GetObjectArrayElement(e, bufs, i);
vec[i].iov_len = (*e)->GetArrayLength(e, ba[i]);
vec[i].iov_base = (*e)->GetByteArrayElements(e, ba[i], NULL);
}
ss = apr_file_writev(f, vec, nvec, &written);
for (i = 0; i < nvec; i++) {
(*e)->ReleaseByteArrayElements(e, ba[i], vec[i].iov_base, JNI_ABORT);
}
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writevFull)(TCN_STDARGS, jlong file,
jobjectArray bufs)
{
apr_file_t *f = J2P(file, apr_file_t *);
jsize nvec = (*e)->GetArrayLength(e, bufs);
jsize i;
struct iovec vec[APR_MAX_IOVEC_SIZE];
jobject ba[APR_MAX_IOVEC_SIZE];
apr_size_t written = 0;
apr_status_t ss;
UNREFERENCED(o);
if (nvec >= APR_MAX_IOVEC_SIZE) {
/* TODO: Throw something here */
return 0;
}
for (i = 0; i < nvec; i++) {
ba[i] = (*e)->GetObjectArrayElement(e, bufs, i);
vec[i].iov_len = (*e)->GetArrayLength(e, ba[i]);
vec[i].iov_base = (*e)->GetByteArrayElements(e, ba[i], NULL);
}
#if (APR_VERSION_MAJOR >= 1) && (APR_VERSION_MINOR >= 1)
ss = apr_file_writev_full(f, vec, nvec, &written);
#else
ss = apr_file_writev(f, vec, nvec, &written);
#endif
for (i = 0; i < nvec; i++) {
(*e)->ReleaseByteArrayElements(e, ba[i], vec[i].iov_base,
JNI_ABORT);
}
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, read)(TCN_STDARGS, jlong file,
jbyteArray buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
apr_status_t ss;
UNREFERENCED(o);
ss = apr_file_read(f, bytes + offset, &nbytes);
(*e)->ReleaseByteArrayElements(e, buf, bytes,
ss == APR_SUCCESS ? 0 : JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, readb)(TCN_STDARGS, jlong file,
jobject buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
apr_status_t ss = APR_EINVAL;
UNREFERENCED(o);
if (bytes)
ss = apr_file_read(f, bytes + offset, &nbytes);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, readFull)(TCN_STDARGS, jlong file,
jbyteArray buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
apr_size_t nread = 0;
apr_status_t ss;
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
UNREFERENCED(o);
ss = apr_file_read_full(f, bytes + offset, nbytes, &nread);
(*e)->ReleaseByteArrayElements(e, buf, bytes,
ss == APR_SUCCESS ? 0 : JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)nread;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, readFullb)(TCN_STDARGS, jlong file,
jobject buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
apr_size_t nread = 0;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
apr_status_t ss = APR_EINVAL;
UNREFERENCED(o);
if (bytes)
ss = apr_file_read_full(f, bytes + offset, nbytes, &nread);
if (ss == APR_SUCCESS)
return (jint)nread;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, gets)(TCN_STDARGS, jbyteArray buf, jint offset,
jlong file)
{
apr_status_t rv;
apr_file_t *f = J2P(file, apr_file_t *);
jsize nbytes = (*e)->GetArrayLength(e, buf);
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
UNREFERENCED(o);
rv = apr_file_gets((char*)(bytes + offset),nbytes - offset, f);
(*e)->ReleaseByteArrayElements(e, buf, bytes,
rv == APR_SUCCESS ? 0 : JNI_ABORT);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, pipeCreate)(TCN_STDARGS, jlongArray io, jlong pool)
{
apr_status_t rv;
apr_pool_t *p = J2P(pool, apr_pool_t *);
jsize npipes = (*e)->GetArrayLength(e, io);
jlong *pipes = (*e)->GetLongArrayElements(e, io, NULL);
apr_file_t *in;
apr_file_t *out;
UNREFERENCED(o);
if (npipes < 2) {
(*e)->ReleaseLongArrayElements(e, io, pipes, JNI_ABORT);
return APR_EINVAL;
}
rv = apr_file_pipe_create(&in, &out, p);
if (rv == APR_SUCCESS) {
pipes[0] = P2J(in);
pipes[1] = P2J(out);
(*e)->ReleaseLongArrayElements(e, io, pipes, 0);
}
else
(*e)->ReleaseLongArrayElements(e, io, pipes, JNI_ABORT);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, pipeTimeoutSet)(TCN_STDARGS, jlong pipe,
jlong timeout)
{
apr_file_t *f = J2P(pipe, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_pipe_timeout_set(f, J2T(timeout));
}
TCN_IMPLEMENT_CALL(jlong, File, pipeTimeoutGet)(TCN_STDARGS, jlong pipe)
{
apr_file_t *f = J2P(pipe, apr_file_t *);
apr_interval_time_t timeout;
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_file_pipe_timeout_get(f, &timeout), timeout);
cleanup:
return (jlong)timeout;
}
TCN_IMPLEMENT_CALL(jlong, File, dup)(TCN_STDARGS, jlong newf, jlong file,
jlong pool)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *d = J2P(newf, apr_file_t *);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_file_dup(&d, f, p), d);
cleanup:
return P2J(d);
}
TCN_IMPLEMENT_CALL(jint, File, dup2)(TCN_STDARGS, jlong newf, jlong file,
jlong pool)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *d = J2P(newf, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_dup2(d, f, p);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -