You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/11/27 11:16:26 UTC
svn commit: r884817 - in /commons/sandbox/runtime/trunk/src/main/native/os:
unix/fsysio.c win32/fsysio.c
Author: mturk
Date: Fri Nov 27 10:16:25 2009
New Revision: 884817
URL: http://svn.apache.org/viewvc?rev=884817&view=rev
Log:
Implement dup1
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=884817&r1=884816&r2=884817&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Fri Nov 27 10:16:25 2009
@@ -239,6 +239,8 @@
x_free(fp->name);
x_free(fp);
}
+ if (fo >= 0)
+ acr_ioh_free(fo);
}
return rc;
@@ -337,6 +339,7 @@
descriptor_cleanup);
if (!fdo) {
rc = ACR_GET_OS_ERROR();
+ acr_ioh_free(fo);
x_free(fp);
ACR_THROW_IO_IF_ERR(rc);
return NULL;
@@ -667,3 +670,61 @@
return 0;
}
+ACR_IO_EXPORT_DECLARE(jobject, FileSystemIo, dup1)(ACR_JNISTDARGS,
+ jint file)
+{
+ int df;
+ int rc = 0;
+ jobject fd = NULL;
+ acr_file_t *d = NULL;
+ acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+ if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+ ACR_THROW_IO_IF_ERR(ACR_EFTYPE);
+ return NULL;
+ }
+ if (IS_INVALID_HANDLE(f)) {
+ ACR_THROW_IO_IF_ERR(ACR_EBADF);
+ return NULL;
+ }
+ df = dup(f->fd);
+ if (df == -1) {
+ ACR_THROW_IO_ERRNO();
+ return NULL;
+ }
+ d = ACR_CALLOC(acr_file_t, 1);
+ if (!d) {
+ close(df);
+ ACR_THROW_IO_IF_ERR(ACR_ENOMEM);
+ return NULL;
+ }
+ d->fd = df;
+ d->flags = f->flags & ~(ACR_FOPEN_NOCLEANUP);
+ d->type = f->type;
+ d->blocking = f->blocking;
+ d->timeout = f->timeout;
+ d->name = x_strdup(f->name);
+
+ df = acr_ioh_open(d, ACR_DT_FILE, 0, file_cleanup);
+ if (df < 0) {
+ rc = ACR_GET_OS_ERROR();
+ file_cleanup(d, ACR_DT_FILE, ACR_IOH_CLEAR);
+ ACR_THROW_IO_IF_ERR(rc);
+ return NULL;
+ }
+ /* Create File Descriptor Object */
+ fd = ACR_DescriptorCreate(_E, ACR_DT_FILE, df, NULL,
+ descriptor_cleanup);
+ if (!fd) {
+ rc = ACR_GET_OS_ERROR();
+ goto finally;
+ }
+ d->descriptor = (*_E)->NewWeakGlobalRef(_E, fd);
+
+finally:
+ if (rc) {
+ acr_ioh_clear(df);
+ ACR_THROW_IO_IF_ERR(rc);
+ }
+ return fd;
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=884817&r1=884816&r2=884817&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Fri Nov 27 10:16:25 2009
@@ -387,8 +387,8 @@
descriptor_cleanup);
if (!fdo) {
rc = ACR_GET_OS_ERROR();
- x_free(fp);
acr_ioh_free(fo);
+ x_free(fp);
ACR_THROW_IO_IF_ERR(rc);
return NULL;
}
@@ -696,3 +696,68 @@
else
return 0;
}
+
+ACR_IO_EXPORT_DECLARE(jobject, FileSystemIo, dup1)(ACR_JNISTDARGS,
+ jint file)
+{
+ int df;
+ int rc = 0;
+ HANDLE dh = INVALID_HANDLE_VALUE;
+ jobject fd = NULL;
+ acr_file_t *d = NULL;
+ acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+ if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+ ACR_THROW_IO_IF_ERR(ACR_EFTYPE);
+ return NULL;
+ }
+ if (IS_INVALID_HANDLE(f)) {
+ ACR_THROW_IO_IF_ERR(ACR_EBADF);
+ return NULL;
+ }
+ if (!DuplicateHandle(GetCurrentProcess(),
+ f->fd,
+ GetCurrentProcess(),
+ &df,
+ 0,
+ TRUE,
+ DUPLICATE_SAME_ACCESS)) {
+ ACR_THROW_IO_ERRNO();
+ return NULL;
+ }
+ d = ACR_CALLOC(acr_file_t, 1);
+ if (!d) {
+ CloseHandle(dh);
+ ACR_THROW_IO_IF_ERR(ACR_ENOMEM);
+ return NULL;
+ }
+ d->fd = dh;
+ d->flags = f->flags & ~(ACR_FOPEN_NOCLEANUP);
+ d->type = f->type;
+ d->blocking = f->blocking;
+ d->timeout = f->timeout;
+ d->name = x_wcsdup(f->name);
+
+ df = acr_ioh_open(d, ACR_DT_FILE, 0, file_cleanup);
+ if (df < 0) {
+ rc = ACR_GET_OS_ERROR();
+ file_cleanup(d, ACR_DT_FILE, ACR_IOH_CLEAR);
+ ACR_THROW_IO_IF_ERR(rc);
+ return NULL;
+ }
+ /* Create File Descriptor Object */
+ fd = ACR_DescriptorCreate(_E, ACR_DT_FILE, df, NULL,
+ descriptor_cleanup);
+ if (!fd) {
+ rc = ACR_GET_OS_ERROR();
+ goto finally;
+ }
+ d->descriptor = (*_E)->NewWeakGlobalRef(_E, fd);
+
+finally:
+ if (rc) {
+ acr_ioh_clear(df);
+ ACR_THROW_IO_IF_ERR(rc);
+ }
+ return fd;
+}