]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Simplify GetFileNameFromHandle somewhat by returning early
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 4 Mar 2016 18:44:05 +0000 (19:44 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 4 Mar 2016 18:44:05 +0000 (19:44 +0100)
util.c

diff --git a/util.c b/util.c
index b0d4491a8d049ac29215e8f078426687cb0ae848..6564704aeaa7268ac5f139c6820ce5ecab226414 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1097,73 +1097,64 @@ static BOOL GetFileNameFromHandle(HANDLE hFile, TCHAR *pszFilename,
        }
 
        // Create a file mapping object.
-       hFileMap = CreateFileMapping(hFile,
-                                    NULL,
-                                    PAGE_READONLY,
-                                    0,
-                                    1,
-                                    NULL);
-
-       if (hFileMap) {
-               // Create a file mapping to get the file name.
-               void *pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1);
-
-               if (pMem) {
-                       if (GetMappedFileName(GetCurrentProcess(),
-                                             pMem,
-                                             pszFilename,
-                                             cchFilename)) {
-
-                               // Translate path with device name to drive letters.
-                               TCHAR szTemp[512];
-                               szTemp[0] = '\0';
-
-                               if (GetLogicalDriveStrings(512-1, szTemp)) {
-                                       TCHAR szName[MAX_PATH];
-                                       TCHAR szDrive[3] = TEXT(" :");
-                                       BOOL bFound = FALSE;
-                                       TCHAR *p = szTemp;
-
-                                       do
-                                       {
-                                               // Copy the drive letter to the template string
-                                               *szDrive = *p;
-
-                                               // Look up each device name
-                                               if (QueryDosDevice(szDrive, szName, MAX_PATH)) {
-                                                       size_t uNameLen = _tcslen(szName);
-
-                                                       if (uNameLen < MAX_PATH) {
-                                                               bFound = _tcsnicmp(pszFilename, szName, uNameLen) == 0
-                                                                        && *(pszFilename + uNameLen) == _T('\\');
-
-                                                               if (bFound) {
-                                                                       // Reconstruct pszFilename using szTempFile
-                                                                       // Replace device path with DOS path
-                                                                       TCHAR szTempFile[MAX_PATH];
-                                                                       _sntprintf(szTempFile,
-                                                                                  MAX_PATH-1,
-                                                                                  TEXT("%s%s"),
-                                                                                  szDrive,
-                                                                                  pszFilename+uNameLen);
-                                                                       _tcsncpy(pszFilename, szTempFile,
-                                                                                _tcslen(szTempFile));
-                                                               }
+       hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 1, NULL);
+       if (!hFileMap) {
+               return FALSE;
+       }
+
+       // Create a file mapping to get the file name.
+       void *pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1);
+       if (pMem) {
+               if (GetMappedFileName(GetCurrentProcess(),
+                                     pMem,
+                                     pszFilename,
+                                     cchFilename)) {
+                       // Translate path with device name to drive letters.
+                       TCHAR szTemp[512];
+                       szTemp[0] = '\0';
+
+                       if (GetLogicalDriveStrings(512-1, szTemp)) {
+                               TCHAR szName[MAX_PATH];
+                               TCHAR szDrive[3] = TEXT(" :");
+                               BOOL bFound = FALSE;
+                               TCHAR *p = szTemp;
+
+                               do {
+                                       // Copy the drive letter to the template string
+                                       *szDrive = *p;
+
+                                       // Look up each device name
+                                       if (QueryDosDevice(szDrive, szName, MAX_PATH)) {
+                                               size_t uNameLen = _tcslen(szName);
+
+                                               if (uNameLen < MAX_PATH) {
+                                                       bFound = _tcsnicmp(pszFilename, szName, uNameLen) == 0
+                                                                && *(pszFilename + uNameLen) == _T('\\');
+                                                       if (bFound) {
+                                                               // Reconstruct pszFilename using szTempFile
+                                                               // Replace device path with DOS path
+                                                               TCHAR szTempFile[MAX_PATH];
+                                                               _sntprintf(szTempFile,
+                                                                          MAX_PATH - 1,
+                                                                          TEXT("%s%s"),
+                                                                          szDrive,
+                                                                          pszFilename+uNameLen);
+                                                               _tcsncpy(pszFilename, szTempFile, _tcslen(szTempFile));
                                                        }
                                                }
+                                       }
 
-                                               // Go to the next NULL character.
-                                               while (*p++) ;
-                                       } while (!bFound && *p); // end of string
-                               }
+                                       // Go to the next NULL character.
+                                       while (*p++) ;
+                               } while (!bFound && *p); // end of string
                        }
-                       bSuccess = TRUE;
-                       UnmapViewOfFile(pMem);
                }
-
-               CloseHandle(hFileMap);
+               bSuccess = TRUE;
+               UnmapViewOfFile(pMem);
        }
-       return(bSuccess);
+
+       CloseHandle(hFileMap);
+       return bSuccess;
 }
 #endif