Bug 872357 - Use ctypes.winLastError. r=standard8
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 13 Jun 2013 20:49:06 +0900
changeset 15727 a458adca8045cd7ac3c9d3aae9cdf6ff4a2196e9
parent 15726 47d08a243bdee2260ed54529352a3f41aa62b2d9
child 15728 b1fd2d8e66d2613675228141e71d2e4fbc89bc84
push id942
push userbugzilla@standard8.plus.com
push dateMon, 05 Aug 2013 19:15:38 +0000
treeherdercomm-beta@0e1a1c4a9f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs872357
Bug 872357 - Use ctypes.winLastError. r=standard8
mailnews/test/resources/mailTestUtils.js
--- a/mailnews/test/resources/mailTestUtils.js
+++ b/mailnews/test/resources/mailTestUtils.js
@@ -309,33 +309,26 @@ function get_file_system(aFile) {
       "GetVolumePathNameW",
       ctypes.winapi_abi,
       BOOL,              // return type: 1 indicates success, 0 failure
       ctypes.jschar.ptr, // in: lpszFileName
       ctypes.jschar.ptr, // out: lpszVolumePathName
       ctypes.uint32_t    // in: cchBufferLength
     );
 
-    // Returns the last error.
-    let GetLastError = kernel32.declare(
-      "GetLastError",
-      ctypes.winapi_abi,
-      ctypes.uint32_t // return type: the last error
-    );
-
     let filePath = aFile.path;
     // The volume path should be at most 1 greater than than the length of the
     // path -- add 1 for a trailing backslash if necessary, and 1 for the
     // terminating null character. Note that the parentheses around the type are
     // necessary for new to apply correctly.
     let volumePath = new (ctypes.jschar.array(filePath.length + 2));
 
     if (!GetVolumePathName(filePath, volumePath, volumePath.length)) {
       throw new Error("Unable to get volume path for " + filePath + ", error " +
-                      GetLastError());
+                      ctypes.winLastError);
     }
 
     // Returns information about the file system for the given volume path. We just need
     // the file system name.
     let GetVolumeInformation = kernel32.declare(
       "GetVolumeInformationW",
       ctypes.winapi_abi,
       BOOL,                // return type: 1 indicates success, 0 failure
@@ -350,17 +343,17 @@ function get_file_system(aFile) {
     );
 
     // We're only interested in the name of the file system.
     let fsName = new (ctypes.jschar.array(MAX_PATH + 1));
 
     if (!GetVolumeInformation(volumePath, null, 0, null, null, null, fsName,
                               fsName.length)) {
       throw new Error("Unable to get volume information for " +
-                      volumePath.readString() + ", error " + GetLastError());
+                      volumePath.readString() + ", error " + ctypes.winLastError);
     }
 
     return fsName.readString();
   }
   finally {
     kernel32.close();
   }
 }
@@ -437,30 +430,23 @@ function mark_file_region_sparse(aFile, 
                            // we're cheating here by not declaring a
                            // SECURITY_ATTRIBUTES structure -- that's because
                            // we're going to pass in null anyway)
         ctypes.uint32_t,   // in: dwCreationDisposition
         ctypes.uint32_t,   // in: dwFlagsAndAttributes
         HANDLE             // in, optional: hTemplateFile
       );
 
-      // Returns the last error.
-      let GetLastError = kernel32.declare(
-        "GetLastError",
-        ctypes.winapi_abi,
-        ctypes.uint32_t // return type: the last error
-      );
-
       let filePath = aFile.path;
       let hFile = CreateFile(filePath, GENERIC_WRITE, 0, null, OPEN_ALWAYS,
                              FILE_ATTRIBUTE_NORMAL, null);
       let hFileInt = ctypes.cast(hFile, ctypes.intptr_t);
       if (ctypes.Int64.compare(hFileInt.value, INVALID_HANDLE_VALUE) == 0) {
         throw new Error("CreateFile failed for " + filePath + ", error " +
-                        GetLastError());
+                        ctypes.winLastError);
       }
 
       try {
         let DeviceIoControl = kernel32.declare(
           "DeviceIoControl",
           ctypes.winapi_abi,
           BOOL,                // return type: 1 indicates success, 0 failure
           HANDLE,              // in: hDevice
@@ -479,55 +465,55 @@ function mark_file_region_sparse(aFile, 
         let sparseBuffer = new FILE_SET_SPARSE_BUFFER();
         sparseBuffer.SetSparse = 1;
 
         // Mark the file as sparse
         if (!DeviceIoControl(hFile, FSCTL_SET_SPARSE, sparseBuffer.address(),
                              FILE_SET_SPARSE_BUFFER.size, null, 0,
                              bytesReturned.address(), null)) {
           throw new Error("Unable to mark file as sparse, error " +
-                          GetLastError());
+                          ctypes.winLastError);
         }
         
         let zdInfo = new FILE_ZERO_DATA_INFORMATION();
         zdInfo.FileOffset = aRegionStart;
         let regionEnd = aRegionStart + aRegionBytes;
         zdInfo.BeyondFinalZero = regionEnd;
         // Mark the region as a sparse region
         if (!DeviceIoControl(hFile, FSCTL_SET_ZERO_DATA, zdInfo.address(),
                              FILE_ZERO_DATA_INFORMATION.size, null, 0,
                              bytesReturned.address(), null)) {
           throw new Error("Unable to mark region as zero, error " +
-                          GetLastError());
+                          ctypes.winLastError);
         }
 
         // Move to past the sparse region and mark it as the end of the file. The
         // above DeviceIoControl call is useless unless followed by this.
         let SetFilePointerEx = kernel32.declare(
           "SetFilePointerEx",
           ctypes.winapi_abi,
           BOOL,              // return type: 1 indicates success, 0 failure
           HANDLE,            // in: hFile
           LARGE_INTEGER,     // in: liDistanceToMove
           LARGE_INTEGER.ptr, // out, optional: lpNewFilePointer
           ctypes.uint32_t    // in: dwMoveMethod
         );
         if (!SetFilePointerEx(hFile, regionEnd, null, FILE_BEGIN)) {
           throw new Error("Unable to set file pointer to end, error " +
-                          GetLastError());
+                          ctypes.winLastError);
         }
 
         let SetEndOfFile = kernel32.declare(
           "SetEndOfFile",
           ctypes.winapi_abi,
           BOOL,  // return type: 1 indicates success, 0 failure
           HANDLE // in: hFile
         );
         if (!SetEndOfFile(hFile))
-          throw new Error("Unable to set end of file, error " + GetLastError());
+          throw new Error("Unable to set end of file, error " + ctypes.winLastError);
 
         return true;
       }
       finally {
         let CloseHandle = kernel32.declare(
           "CloseHandle",
           ctypes.winapi_abi,
           BOOL,  // return type: 1 indicates success, 0 failure