- BY_HANDLE_FILE_INFORMATION info1;
- BY_HANDLE_FILE_INFORMATION info2;
- bool samefile = false;
- if (GetFileInformationByHandle(h1, &info1) != 0
- && GetFileInformationByHandle(h2, &info2) != 0) {
- // Serial number of the volumes containing the files.
- ULONG st1_dev = info1.dwVolumeSerialNumber;
- ULONG st2_dev = info2.dwVolumeSerialNumber;
- // Unique identifiers associated to the files on the volumes.
- ULONGLONG highbits = info1.nFileIndexHigh & 0x0000FFFF;
- ULONGLONG st1_ino = (highbits << sizeof(ULONG)) | info1.nFileIndexLow;
- highbits = info2.nFileIndexHigh & 0x0000FFFF;
- ULONGLONG st2_ino = (highbits << sizeof(ULONG)) | info2.nFileIndexLow;
- samefile = st1_ino == st2_ino && st1_dev == st2_dev;
+ // Translate device name to UNC prefix or drive letters.
+ TCHAR tmpbuf[MAX_PATH] = TEXT("\\Device\\Mup\\");
+ UINT namelen = _tcslen(tmpbuf);
+ if (_tcsnicmp(realpath, tmpbuf, namelen) == 0) {
+ // UNC path
+ _snprintf(tmpbuf, MAX_PATH, "\\\\%s", realpath + namelen);
+ strncpy(realpath, tmpbuf, MAX_PATH);
+ realpath[MAX_PATH] = '\0';
+ } else if (GetLogicalDriveStrings(MAX_PATH - 1, tmpbuf)) {
+ // Check whether device name corresponds to some local drive.
+ TCHAR name[MAX_PATH];
+ TCHAR drive[3] = TEXT(" :");
+ bool found = false;
+ TCHAR * p = tmpbuf;
+ do {
+ // Copy the drive letter to the template string
+ drive[0] = *p;
+ // Look up each device name
+ if (QueryDosDevice(drive, name, MAX_PATH)) {
+ namelen = _tcslen(name);
+ if (namelen < MAX_PATH) {
+ found = _tcsnicmp(realpath, name, namelen) == 0;
+ if (found) {
+ // Repl. device spec with drive
+ TCHAR tempfile[MAX_PATH];
+ _snprintf(tempfile,
+ MAX_PATH,
+ "%s%s",
+ drive,
+ realpath + namelen);
+ strncpy(realpath,
+ tempfile,
+ MAX_PATH);
+ realpath[MAX_PATH] = '\0';
+ }
+ }
+ }
+ // Advance p to the next NULL character.
+ while (*p++) ;
+ } while (!found && *p);