Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 86231 invoked from network); 6 Oct 2009 06:19:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Oct 2009 06:19:15 -0000 Received: (qmail 71226 invoked by uid 500); 6 Oct 2009 06:19:14 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 71132 invoked by uid 500); 6 Oct 2009 06:19:14 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 71123 invoked by uid 99); 6 Oct 2009 06:19:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Oct 2009 06:19:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Oct 2009 06:19:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B1C4623888E7; Tue, 6 Oct 2009 06:18:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r822143 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_file.h include/arch/unix/acr_arch.h os/unix/fsysio.c os/unix/uutils.c os/win32/fsysio.c os/win32/temps.c shared/fsysio.c Date: Tue, 06 Oct 2009 06:18:19 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091006061819.B1C4623888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Tue Oct 6 06:18:18 2009 New Revision: 822143 URL: http://svn.apache.org/viewvc?rev=822143&view=rev Log: Precalc platform specific timeout values Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=822143&r1=822142&r2=822143&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Tue Oct 6 06:18:18 2009 @@ -190,7 +190,6 @@ int type; /**< File type. see ACR_FT */ int eof; /**< Non zero if file hit EOF */ acr_uint32_t flags; /**< File flags */ - acr_time_t timeout; /**< I/O timeout */ acr_off_t pos; /**< Current file pointer */ enum { BLK_UNKNOWN, @@ -199,12 +198,17 @@ } blocking; /**< Blocking mode */ jobject descriptor; /**< File Descriptor object. + This is WeakReference so any + operation requres getting local + reference. */ /* The rest of the structure is platform specific. */ #if defined(WIN32) + DWORD timeout; CRITICAL_SECTION lock; #else + int timeout; pthread_mutex_t lock; #endif 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=822143&r1=822142&r2=822143&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 Tue Oct 6 06:18:18 2009 @@ -239,8 +239,14 @@ * deallocate the buffer when done. * If the file cannot be read, function returns NULL. */ -char *ACR_FileReadTxt(const char *name); +char *acr_FileReadTxt(const char *name); +/** + * Get the absolute path by merging the current + * working directory in case of relative paths. + * Function doesn't resolve symbolic links. + */ +char *acr_GetAbsolutePath(JNIEnv *env, const char *path); #ifdef __cplusplus } 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=822143&r1=822142&r2=822143&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 Tue Oct 6 06:18:18 2009 @@ -230,7 +230,7 @@ goto finally; } fp->fd = fd; - fp->name = ACR_StrdupA(_E, THROW_NMARK, fname); + fp->name = acr_GetAbsolutePath(_E, fname); fp->flags = flags; fp->type = ACR_FT_REG; /* Presume it's a regular file */ if (flags & ACR_FOPEN_NONBLOCK) { @@ -378,12 +378,12 @@ static int wait_for_io_or_timeout(acr_file_t *f, int for_read) { - int rc, timeout = f->timeout < 0 ? -1 : (int)(f->timeout / 1000); + int rc; f->ppoll.fd = f->fd; f->ppoll.events = for_read ? POLLIN : POLLOUT; do { - rc = poll(&f->ppoll, 1, timeout); + rc = poll(&f->ppoll, 1, f->timeout); } while (rc == -1 && errno == EINTR); if (rc == 0) return ACR_TIMEUP; @@ -395,12 +395,12 @@ static int wait_for_io(acr_file_t *f, int for_read) { - int rc, timeout = f->timeout > 0 ? (int)(f->timeout / 1000) : -1; + int rc; f->ppoll.fd = f->fd; f->ppoll.events = for_read ? POLLIN : POLLOUT; do { - rc = poll(&f->ppoll, 1, timeout); + rc = poll(&f->ppoll, 1, -1); } while (rc == -1 && errno == EINTR); if (rc == 0) return ACR_TIMEUP; 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=822143&r1=822142&r2=822143&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 Tue Oct 6 06:18:18 2009 @@ -18,10 +18,12 @@ #include "acr_private.h" #include "acr_arch.h" #include "acr_error.h" +#include "acr_memory.h" +#include "acr_port.h" #include "acr_string.h" #include "acr_file.h" -char *ACR_FileReadTxt(const char *name) +char *acr_FileReadTxt(const char *name) { FILE *f; size_t rd = ACR_MIN_FREAD_LEN; @@ -73,3 +75,70 @@ errno = rc; return NULL; } + +#define IS_PATH_SEP(C) ((C) == '/' || (C) == '\0') +/* Calculate the absolute path by merging the current + * working directory in case of relative paths. + * Function doesn't resolve symbolic links. + */ +char *acr_GetAbsolutePath(JNIEnv *_E, const char *path) +{ + char pcopy[PATH_MAX * 2]; + char *cp; + int ch = '/'; + + if (*path == '/' && !strstr(path, "./")) { + /* Already an absolute path + */ + return ACR_StrdupA(_E, THROW_FMARK, path); + } + if (!IS_PATH_SEP(*path)) { + if (!getcwd(pcopy, PATH_MAX)) { + ACR_THROW_IO_ERRNO(); + return NULL; + } + strlcat(pcopy, "/", PATH_MAX * 2); + strlcat(pcopy, path, PATH_MAX * 2); + } + else + strlcpy(pcopy, path, PATH_MAX * 2); + + path = cp = pcopy; + while (*path) { + if (IS_PATH_SEP(ch) && *path == '.') { + size_t nd = 0; + while (path[nd] == '.') + nd++; + if (nd > 2) { + ACR_THROW_IO_IF_ERR(ACR_EINVAL); + return NULL; + } + if (IS_PATH_SEP(path[nd])) { + path += nd; + if (*path) + path++; + while (nd > 1) { + if (cp > pcopy + 1) { + cp--; + while (cp > pcopy) { + if (IS_PATH_SEP(*(cp - 1))) + break; + cp--; + } + } + else + break; + nd--; + } + } + else + ch = *cp++ = *path++; + } + else + ch = *cp++ = *path++; + } + *cp = '\0'; + /* Duplicate the final path + */ + return ACR_StrdupA(_E, THROW_FMARK, pcopy); +} 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=822143&r1=822142&r2=822143&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 Tue Oct 6 06:18:18 2009 @@ -245,7 +245,7 @@ } else { fp->blocking = BLK_ON; - fp->timeout = -1; + fp->timeout = INFINITE; } if (flags & ACR_FOPEN_NOCLEANUP) fo = acr_ioh_open(fp, ACR_DT_FILE, 0, file_cclose); @@ -412,7 +412,7 @@ fp->flags = flags; fp->type = ACR_FT_PIPE; fp->blocking = BLK_ON; - fp->timeout = -1; + fp->timeout = INFINITE; fo = acr_ioh_open(fp, ACR_DT_FILE, 0, NULL); if (fo < 0) { rc = ACR_GET_OS_ERROR(); @@ -697,10 +697,10 @@ { DWORD ws; DWORD rc = 0; - DWORD tv = f->timeout < 0 ? INFINITE : (DWORD)(f->timeout / 1000); do { - switch (ws = ACR_WaitForObjectOrSignal(f->overlap.hEvent, tv)) { + switch (ws = ACR_WaitForObjectOrSignal(f->overlap.hEvent, + f->timeout)) { case WAIT_IO_COMPLETION: case WAIT_ABANDONED_0: case WAIT_ABANDONED_1: @@ -751,12 +751,9 @@ { DWORD ws; DWORD rc = 0; - DWORD tv = f->timeout > 0 ? (DWORD)(f->timeout / 1000) : INFINITE; - if (f->timeout > 0) - tv = (DWORD)(f->timeout / 1000); do { - switch (ws = ACR_WaitForObjectOrSignal(f->overlap.hEvent, tv)) { + switch (ws = ACR_WaitForObjectOrSignal(f->overlap.hEvent, INFINITE)) { case WAIT_IO_COMPLETION: case WAIT_ABANDONED_0: case WAIT_ABANDONED_1: Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c?rev=822143&r1=822142&r2=822143&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c Tue Oct 6 06:18:18 2009 @@ -308,7 +308,7 @@ fp->type = ACR_FT_REG; fp->name = ACR_StrdupW(_E, THROW_NMARK, name); fp->blocking = BLK_ON; - fp->timeout = -1; + fp->timeout = INFINITE; fp->flags = ACR_FOPEN_READ | ACR_FOPEN_WRITE | ACR_FOPEN_CREATE; rc = acr_ioh_open(fp, ACR_DT_FILE, 0, tmp_file_cleanup); return rc; Modified: commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c?rev=822143&r1=822142&r2=822143&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Tue Oct 6 06:18:18 2009 @@ -75,7 +75,7 @@ ACR_IO_EXPORT_DECLARE(jint, FileWrapper, tmset0)(ACR_JNISTDARGS, jint file, - jlong timeout) + jint timeout) { acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file); @@ -88,7 +88,7 @@ */ return ACR_EPERM; } - f->timeout = (acr_time_t)timeout; + f->timeout = timeout; return 0; } @@ -105,7 +105,7 @@ ACR_THROW_IO_IF_ERR(ACR_EBADF); return 0; } - return (jlong)f->timeout; + return (jlong)(f->timeout * 1000); } ACR_IO_EXPORT_DECLARE(jstring, FileWrapper, name0)(ACR_JNISTDARGS,