commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r810440 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
Date Wed, 02 Sep 2009 09:56:45 GMT
Author: mturk
Date: Wed Sep  2 09:56:45 2009
New Revision: 810440

URL: http://svn.apache.org/viewvc?rev=810440&view=rev
Log:
Check rv from lock init

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c

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=810440&r1=810439&r2=810440&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 Wed Sep  2 09:56:45 2009
@@ -70,6 +70,7 @@
     HANDLE   fh;
     DWORD    rc;
     int      randnum;
+    SECURITY_ATTRIBUTES sa;
 
     if (randseed == 0) {
         randseed = GetTickCount();
@@ -113,11 +114,14 @@
         }
     }
 
+    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+    sa.lpSecurityDescriptor = NULL;
+    sa.bInheritHandle       = FALSE;
     for (;;) {
         fh = CreateFileW(path,
                          GENERIC_READ | GENERIC_WRITE,
                          0,
-                         NULL,
+                         &sa,
                          CREATE_NEW,
                          flags,
                          NULL);
@@ -244,13 +248,77 @@
 ACR_DECLARE(int) ACR_TempFileMake(JNIEnv *_E, const wchar_t *tmpath,
                                   const wchar_t *prefix, int preserve)
 {
+    int     rc;
+    DWORD   ff = preserve ? FILE_ATTRIBUTE_NORMAL : FILE_FLAG_DELETE_ON_CLOSE;
+    HANDLE  fd;
+    wchar_t name[ACR_MBUFF_SIZ] = L"";
+    acr_file_t *fp;
+
+    if (tmpath) {
+        if (wcslcpy(name, tmpath, TMP_PATH_MAX) >= TMP_PATH_MAX) {
+            ACR_THROW_IO_IF_ERR(ACR_E2BIG);
+            return -1;
+        }
+        wcslcat(name, L"\\", ACR_MBUFF_SIZ);
+    }
+    wcslcat(name, prefix, ACR_MBUFF_SIZ);
+    if (wcslcat(name, L"XXXXXX", ACR_MBUFF_SIZ) >= ACR_MBUFF_SIZ) {
+        /* Truncation occurred. We dont have enough space
+         * to create temp file template
+         */
+        ACR_THROW_IO_IF_ERR(ACR_E2BIG);
+        return -1;
+    }
+
+    fd = getftemp(name, ff);
+    if (IS_INVALID_HANDLE(fd)) {
+        ACR_THROW_IO_ERRNO();
+        return -1;
+    }
+    fp = ACR_Calloc(_E, THROW_NMARK, sizeof(acr_file_t));
+    if (!fp) {
+        goto cleanup;
+    }
+    fp->fd   = fd;
+    fp->name = ACR_StrdupW(_E, THROW_NMARK, name);
+    rc = acr_ioh_open(fp, ACR_DT_FILE, 0, tmp_file_cleanup);
+    return rc;
+
+cleanup:
+    rc = ACR_GET_OS_ERROR();
+    CloseHandle(fd);
+    DeleteFileW(name);
+    ACR_THROW_IO_IF_ERR(rc);
     return -1;
 }
 
 ACR_DECLARE(wchar_t *) ACR_TempDirMake(JNIEnv *_E, const wchar_t *tmpath,
                                        const wchar_t *prefix)
 {
-    return NULL;
+    int     rc;
+    wchar_t name[ACR_MBUFF_SIZ] = L"";
+
+    if (tmpath) {
+        if (wcslcpy(name, tmpath, TMP_PATH_MAX) >= TMP_PATH_MAX) {
+            ACR_THROW_IO_IF_ERR(ACR_E2BIG);
+            return NULL;
+        }
+        wcslcat(name, L"\\", ACR_MBUFF_SIZ);
+    }
+    wcslcat(name, prefix, ACR_MBUFF_SIZ);
+    if (wcslcat(name, L"XXXXXX", ACR_MBUFF_SIZ) >= ACR_MBUFF_SIZ) {
+        /* Truncation occurred. We dont have enough space
+         * to create temp file template
+         */
+        ACR_THROW_IO_IF_ERR(ACR_E2BIG);
+        return NULL;
+    }
+    rc = getdtemp(name);
+    if (rc < 0) {
+        ACR_THROW_IO_ERRNO();
+        return NULL;
+    }
+    return ACR_StrdupW(_E, THROW_NMARK, name);
 }
 
 ACR_DECLARE(const wchar_t *) ACR_TempPathGet(JNIEnv *_E)



Mime
View raw message