Author: mturk
Date: Mon Nov 23 07:44:39 2009
New Revision: 883263
URL: http://svn.apache.org/viewvc?rev=883263&view=rev
Log:
Some fixes
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=883263&r1=883262&r2=883263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
Mon Nov 23 07:44:39 2009
@@ -70,6 +70,12 @@
#endif
#endif
+/**
+ * Common unix utils
+ */
+int acr_nonblock(int, int);
+int acr_cloexec(int);
+
/** Common large file replacement macros
*/
#if defined(DARWIN) && DARWIN >= 1000
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c?rev=883263&r1=883262&r2=883263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c Mon Nov 23
07:44:39 2009
@@ -197,13 +197,17 @@
return 0;
if (rc == ACR_ENOENT) { /* Missing an intermediate dir */
char *pos;
- char *dir = ACR_StrdupA(INVALID_HANDLE_VALUE, THROW_NMARK, name);
+ char *dir = ACR_strdup(name);
if (!dir)
return ACR_ENOMEM;
if ((pos = strrchr(dir, '/'))) {
*pos = '\0';
if (*dir) {
- rc = _mkdir1(dir, perms);
+ if (!(rc = _mkdir1(dir, perms))) {
+ /* Try again, now with parents created
+ */
+ rc = _mkdir0(name, perms);
+ }
}
}
x_free(dir);
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=883263&r1=883262&r2=883263&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 Mon Nov 23
07:44:39 2009
@@ -38,7 +38,7 @@
if (type != ACR_DT_FILE) {
return ACR_EBADF;
}
- if (fp->fd >= 0) {
+ if (fp->fd != -1) {
if (close(fp->fd))
rc = ACR_GET_OS_ERROR();
else
@@ -186,42 +186,17 @@
fd = open(fname, oflags, 0666);
else
fd = open(fname, oflags, ACR_UnixPermsToMode(prot));
- if (fd < 0) {
+ if (fd == -1) {
return ACR_GET_OS_ERROR();
}
if (!(flags & ACR_FOPEN_NOCLEANUP)) {
- int mode;
- if ((mode = fcntl(fd, F_GETFD)) == -1) {
- rc = ACR_GET_OS_ERROR();
- goto finally;
- }
- mode |= FD_CLOEXEC;
- if (fcntl(fd, F_SETFD, mode) == -1) {
- rc = ACR_GET_OS_ERROR();
+ if ((rc = acr_cloexec(fd)))
goto finally;
- }
}
if (flags & ACR_FOPEN_NONBLOCK) {
-#ifdef O_NONBLOCK
- /* Use non-blocking I/O
- */
- int mode;
- if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
- rc = ACR_GET_OS_ERROR();
+ if ((rc = acr_nonblock(fd, 1)))
goto finally;
- }
- mode |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, mode) == -1) {
- rc = ACR_GET_OS_ERROR();
- goto finally;
- }
-#else
- /* Non blocking files are unsupported.
- */
- rc = ACR_ENOTIMPL;
- goto finally;
-#endif
}
fp = ACR_CALLOC(acr_file_t, 1);
if (!fp) {
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c?rev=883263&r1=883262&r2=883263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c Mon Nov 23
07:44:39 2009
@@ -157,31 +157,6 @@
return rc;
}
-static int pipeblock(int fd, int on)
-{
- int rc = 0;
-#ifdef O_NONBLOCK
- /* Use non-blocking I/O
- */
- int mode;
- if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
- return ACR_GET_OS_ERROR();
- }
- if (on)
- mode &= ~O_NONBLOCK;
- else
- mode |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, mode) == -1) {
- return ACR_GET_OS_ERROR();
- }
-#else
- /* Non blocking files are unsupported.
- */
- rc = ACR_ENOTIMPL;
-#endif
- return rc;
-}
-
static int do_popen(JNIEnv *_E, int fd, int flags,
jobject *fdo)
{
@@ -191,7 +166,7 @@
acr_file_t *fp = NULL;
if ((flags & 0xFF) == ACR_PIPE_FULL_NONBLOCK) {
- if ((rc = pipeblock(fd, 0)))
+ if ((rc = acr_nonblock(fd, 1)))
goto finally;
}
fp = ACR_CALLOC(acr_file_t, 1);
@@ -317,7 +292,7 @@
if (f->blocking != BLK_OFF) {
/* Pipe is in the blocking state
*/
- if ((rc = pipeblock(f->fd, 0)) == 0)
+ if ((rc = acr_nonblock(f->fd, 1)) == 0)
f->blocking = BLK_OFF;
return rc;
}
@@ -326,7 +301,7 @@
if (f->blocking != BLK_ON) {
/* Pipe is non-blocking
*/
- if ((rc = pipeblock(f->fd, 1)) == 0)
+ if ((rc = acr_nonblock(f->fd, 0)) == 0)
f->blocking = BLK_ON;
return rc;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c?rev=883263&r1=883262&r2=883263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c Mon Nov 23
07:44:39 2009
@@ -49,7 +49,7 @@
if (type != ACR_DT_FILE) {
return ACR_EBADF;
}
- if (fp->fd > 0) {
+ if (fp->fd != -1) {
if (close(fp->fd))
rc = ACR_GET_OS_ERROR();
else
@@ -97,20 +97,11 @@
sigfillset(&bset);
sigprocmask(SIG_BLOCK, &bset, &oset);
fd = mkstemp(name);
- if (fd > 0) {
+ if (fd != -1) {
/* Set close on exec flag */
- int flags;
if (preserve == 0)
unlink(name);
- if ((flags = fcntl(fd, F_GETFD)) < 0) {
- rc = errno;
- }
- else {
- flags |= FD_CLOEXEC;
- if (fcntl(fd, F_SETFD, flags) < 0) {
- rc = errno;
- }
- }
+ rc = acr_cloexec(fd);
}
else
rc = errno;
@@ -135,7 +126,7 @@
rc = ACR_GET_OS_ERROR();
finally:
unlink(name);
- if (fd > 0)
+ if (fd != -1)
close(fd);
ACR_THROW_IO_IF_ERR(rc);
return -1;
@@ -165,7 +156,7 @@
return NULL;
}
fd = mkstemp(name);
- if (fd < 0) {
+ if (fd == -1) {
ACR_THROW_IO_ERRNO();
return NULL;
}
@@ -195,7 +186,7 @@
ACR_NO_END_SLASHA(tp);
strlcat(tp, "/.acrXXXXXX", PATH_MAX);
f = mkstemp(tp);
- if (f > 0) {
+ if (f != -1) {
unlink(tp);
close(f);
return 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c?rev=883263&r1=883262&r2=883263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Mon Nov 23
07:44:39 2009
@@ -206,3 +206,52 @@
arr[i] = NULL;
return arr;
}
+
+int acr_nonblock(int fd, int on)
+{
+ int rc = 0;
+#ifdef O_NONBLOCK
+ /* Use non-blocking I/O
+ */
+ int mode, forg;
+ if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
+ return ACR_GET_OS_ERROR();
+ }
+ forg = mode;
+ if (on)
+ mode |= O_NONBLOCK;
+ else
+ mode &= ~O_NONBLOCK;
+ if (forg != mode && fcntl(fd, F_SETFL, mode) == -1) {
+ return ACR_GET_OS_ERROR();
+ }
+#else
+ /* Non blocking I/O is unsupported.
+ */
+ rc = ACR_ENOTIMPL;
+#endif
+ return rc;
+}
+
+int acr_cloexec(int fd)
+{
+ int rc = 0;
+#ifdef FD_CLOEXEC
+ /* Close on exec
+ */
+ int mode, forg;
+ if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
+ return ACR_GET_OS_ERROR();
+ }
+ forg = mode;
+ mode |= FD_CLOEXEC;
+ if (forg != mode && fcntl(fd, F_SETFL, mode) == -1) {
+ return ACR_GET_OS_ERROR();
+ }
+#else
+ /* Flag is unsupported.
+ */
+ rc = ACR_ENOTIMPL;
+#endif
+ return rc;
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c?rev=883263&r1=883262&r2=883263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c Mon Nov 23
07:44:39 2009
@@ -192,7 +192,11 @@
if ((pos = wcsrchr(dir, L'\\'))) {
*pos = L'\0';
if (*dir) {
- rc = _mkdir1(dir, perms);
+ if (!(rc = _mkdir1(dir, perms))) {
+ /* Try again, now with parents created
+ */
+ rc = _mkdir0(name, perms);
+ }
}
}
x_free(dir);