commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r812059 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_file.h os/linux/selinux.c os/unix/temps.c os/win32/temps.c test/testsuite.c
Date Mon, 07 Sep 2009 09:34:58 GMT
Author: mturk
Date: Mon Sep  7 09:34:58 2009
New Revision: 812059

URL: http://svn.apache.org/viewvc?rev=812059&view=rev
Log:
Extent temporary path getter

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
    commons/sandbox/runtime/trunk/src/main/native/os/linux/selinux.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
    commons/sandbox/runtime/trunk/src/main/native/test/testsuite.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=812059&r1=812058&r2=812059&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 Mon Sep  7 09:34:58 2009
@@ -224,9 +224,16 @@
 /** Get system temporary directory.
  * @param env JNI environment to use. If NULL no exception will be thrown
  *            if temprary directory cannot be found.
+ * @param path Optional platform path char separated list of directories
+ *        to use as temporary directory. Firts one that is accessible will
+ *        be used.
  * @return Temporary directory.
+ * @note After first infocation temporary directory will be stored internally
+ * and future invocations will return the same path. However if the path
+ * param is not null the scan will be repeated.
  */
-ACR_DECLARE(const acr_pchar_t *) ACR_TempPathGet(JNIEnv *env);
+ACR_DECLARE(const acr_pchar_t *) ACR_TempPathGet(JNIEnv *env,
+                                                 const acr_pchar_t *path);
 
 
 /** Get Filename from file descriptor.

Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/selinux.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/selinux.c?rev=812059&r1=812058&r2=812059&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/selinux.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/selinux.c Mon Sep  7 09:34:58 2009
@@ -20,6 +20,7 @@
 #include "acr_error.h"
 #include "acr_string.h"
 
+#if HAVE_SELINUX_H
 #include <selinux/selinux.h>
 
 ACR_JNI_PLATFORM_DECLARE(jboolean, SELinux, enabled0)(ACR_JNISTDARGS)
@@ -35,3 +36,11 @@
         return V2Z(rc);
     }
 }
+#else
+
+ACR_JNI_PLATFORM_DECLARE(jboolean, SELinux, enabled0)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+    return JNI_FALSE;
+}
+#endif

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=812059&r1=812058&r2=812059&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 Sep  7 09:34:58 2009
@@ -183,11 +183,37 @@
         return 0;
 }
 
-ACR_DECLARE(const char *) ACR_TempPathGet(JNIEnv *_E)
+ACR_DECLARE(const char *) ACR_TempPathGet(JNIEnv *_E, const char *srch)
 {
     static char _temp_path[TMP_PATH_MAX] = "";
     int i = 0;
 
+    if (srch) {
+        char *p = strchr(srch, ':');
+        if (p == NULL)
+            p = (char *)(srch + strlen(srch));
+        while (p) {
+            size_t part = p - srch + 1;
+            if (part >= TMP_PATH_MAX)
+                break;
+            strlcpy(_temp_path, srch, part);
+            if (_temp_path[0] && _temp_test(_temp_path)) {
+                ACR_NO_END_SLASHA(_temp_path);
+                break;
+            }
+            _temp_path[0] = '\0';
+            if (*p != ':') {
+                /* No more path components */
+                break;
+            }
+            else {
+                srch = p + 1;
+                p = strchr(srch, ':');
+                if (p == NULL)
+                    p = (char *)(srch + strlen(srch));
+            }
+        }
+    }
     if (_temp_path[0])
         return _temp_path;
     while (_try_envs[i]) {

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=812059&r1=812058&r2=812059&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 Mon Sep  7 09:34:58 2009
@@ -327,11 +327,37 @@
     return ACR_StrdupW(_E, THROW_NMARK, name);
 }
 
-ACR_DECLARE(const wchar_t *) ACR_TempPathGet(JNIEnv *_E)
+ACR_DECLARE(const wchar_t *) ACR_TempPathGet(JNIEnv *_E, const wchar_t *srch)
 {
     static wchar_t _temp_path[TMP_PATH_MAX] = L"";
     int i = 0;
 
+    if (srch) {
+        wchar_t *p = wcschr(srch, L';');
+        if (p == NULL)
+            p = (wchar_t *)(srch + wcslen(srch));
+        while (p) {
+            size_t part = p - srch + 1;
+            if (part >= TMP_PATH_MAX)
+                break;
+            wcslcpy(_temp_path, srch, part);
+            if (_temp_path[0] && _temp_test(_temp_path)) {
+                ACR_NO_END_SLASHW(_temp_path);
+                break;
+            }
+            _temp_path[0] = L'\0';
+            if (*p != L';') {
+                /* No more path components */
+                break;
+            }
+            else {
+                srch = p + 1;
+                p = wcschr(srch, L';');
+                if (p == NULL)
+                    p = (wchar_t *)(srch + wcslen(srch));
+            }
+        }
+    }
     if (_temp_path[0])
         return _temp_path;
     while (_try_envs[i]) {

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=812059&r1=812058&r2=812059&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Mon Sep  7 09:34:58 2009
@@ -99,9 +99,12 @@
     int   fd;
     acr_pchar_t *fn;
     fprintf(stdout, "Using Temporary Directory : `" PRINT_PSTR "\'\n",
-            ACR_TempPathGet(NULL));
-
-    fd = ACR_TempFileMake(NULL, ACR_TempPathGet(NULL),
+#if defined(WIN32)
+            ACR_TempPathGet(NULL, "\\foo;.\\bar;;"));
+#else
+            ACR_TempPathGet(NULL, "/foo:./bar::"));
+#endif
+    fd = ACR_TempFileMake(NULL, ACR_TempPathGet(NULL, NULL),
                           STD_PREFIX, 0);
     if (fd < 0)
         failed++;
@@ -112,7 +115,7 @@
             failed++;
     }
 
-    fd = ACR_TempFileMake(NULL, ACR_TempPathGet(NULL),
+    fd = ACR_TempFileMake(NULL, ACR_TempPathGet(NULL, NULL),
                           STD_PREFIX, 1);
     if (fd < 0)
         failed++;
@@ -122,7 +125,7 @@
         if (ACR_IoClose(NULL, fd))
             failed++;
     }
-    fn = ACR_TempDirMake(NULL, ACR_TempPathGet(NULL),
+    fn = ACR_TempDirMake(NULL, ACR_TempPathGet(NULL, NULL),
                          STD_PREFIX);
     if (fn == NULL)
         failed++;



Mime
View raw message