VirtualBox

Changeset 727 in kBuild for trunk/src/lib/kDep.c


Ignore:
Timestamp:
Dec 17, 2006 1:43:01 AM (18 years ago)
Author:
bird
Message:

Extended the windows fixcase function to also take care of path components with spaces in them. Also, don't stop fixing the path if we were given a shortname.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/kDep.c

    r407 r727  
    8484#ifdef __WIN32__
    8585/**
    86  * Corrects the case of a path.
    87  * Expects a fullpath!
     86 * Corrects the case of a path and changes any path components containing
     87 * spaces with the short name (which can be longer).
     88 *
     89 * Expects a _fullpath!
    8890 *
    8991 * @param   pszPath     Pointer to the path, both input and output.
    90  *                      The buffer must be able to hold one more byte than the string length.
     92 *                      The buffer must be at least MAX_PATH in length.
    9193 */
    9294static void fixcase(char *pszPath)
     
    158160        char chSaved1;
    159161        char *pszEnd;
     162        int cch;
     163        int iLongNameDiff;
    160164
    161165
     
    164168        while (*pszEnd && *pszEnd != '/' && *pszEnd != '\\')
    165169            pszEnd++;
     170        cch = pszEnd - psz;
    166171
    167172        /* replace the end with "?\0" */
     
    180185        }
    181186        pszEnd[0] = '\0';
    182         while (stricmp(FindFileData.cFileName, psz))
     187        while (   (iLongNameDiff = stricmp(FindFileData.cFileName, psz))
     188               && stricmp(FindFileData.cAlternateFileName, psz))
    183189        {
    184190            if (!FindNextFile(hDir, &FindFileData))
     
    188194            }
    189195        }
    190         strcpy(psz, FindFileData.cFileName);
    191196        pszEnd[0] = chSaved0;
     197        if (iLongNameDiff || !FindFileData.cAlternateFileName[0] || !memchr(psz, ' ', cch))
     198            memcpy(psz, !iLongNameDiff ? FindFileData.cFileName : FindFileData.cAlternateFileName, cch);
     199        else
     200        {
     201            /* replace spacy name with the short name. */
     202            const int cchAlt = strlen(FindFileData.cAlternateFileName);
     203            const int cchDelta = cch - cchAlt;
     204            my_assert(cchAlt > 0);
     205            if (!cchDelta)
     206                memcpy(psz, FindFileData.cAlternateFileName, cch);
     207            else
     208            {
     209                memmove(psz + cchAlt, pszEnd, strlen(pszEnd) + 1);
     210                pszEnd -= cchDelta;
     211                memcpy(psz, FindFileData.cAlternateFileName, cchAlt);
     212            }
     213        }
     214        my_assert(pszEnd[0] == chSaved0);
    192215
    193216        /* advance to the next component */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette