VirtualBox

Changeset 2484 in kBuild


Ignore:
Timestamp:
Jul 21, 2011 7:01:08 PM (14 years ago)
Author:
bird
Message:

mscfakes.c: link() fix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/mscfakes.c

    r2476 r2484  
    216216{
    217217    int rc = 0;
    218     int saved_errno;
    219218    int fMustBeDir;
    220219    char *pszPathFree = msc_fix_path(&pszPath, &fMustBeDir);
     
    259258
    260259
     260typedef BOOL (WINAPI *PFNCREATEHARDLINKA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES);
    261261int link(const char *pszDst, const char *pszLink)
    262262{
    263     if (CreateHardLink(pszDst, pszLink, NULL))
     263    static PFNCREATEHARDLINKA   s_pfnCreateHardLinkA = NULL;
     264    static int                  s_fTried = FALSE;
     265
     266    /* The API was introduced in Windows 2000, so resolve it dynamically. */
     267    if (!s_pfnCreateHardLinkA)
     268    {
     269        if (!s_fTried)
     270        {
     271            HMODULE hmod = LoadLibrary("KERNEL32.DLL");
     272            if (hmod)
     273                *(FARPROC *)&s_pfnCreateHardLinkA = GetProcAddress(hmod, "CreateHardLinkA");
     274            s_fTried = TRUE;
     275        }
     276        if (!s_pfnCreateHardLinkA)
     277        {
     278            errno = ENOSYS;
     279            return -1;
     280        }
     281    }
     282
     283    if (s_pfnCreateHardLinkA(pszLink, pszDst, NULL))
    264284        return 0;
    265285    return msc_set_errno(GetLastError());
Note: See TracChangeset for help on using the changeset viewer.

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