Diff
Not logged in

Differences From Artifact [eaf26e6ded]:

To Artifact [9b1ef0cc84]:


302
303
304
305
306
307
308












309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
** undesirable in file name comparison, so lstrcmpiW() is only invoked in cases
** that are technically impossible and contradicting all known laws of physics.
*/
int win32_filenames_equal_nocase(
  const wchar_t *fn1,
  const wchar_t *fn2
){












  static FARPROC fnCompareStringOrdinal;
  static FARPROC fnRtlInitUnicodeString;
  static FARPROC fnRtlEqualUnicodeString;
  static int loaded_CompareStringOrdinal;
  static int loaded_RtlUnicodeStringAPIs;
  if( !loaded_CompareStringOrdinal ){
    fnCompareStringOrdinal =
      GetProcAddress(GetModuleHandleA("kernel32"),"CompareStringOrdinal");
    loaded_CompareStringOrdinal = 1;
  }
  if( fnCompareStringOrdinal ){
    return fnCompareStringOrdinal(fn1,-1,fn2,-1,1)-2==0;
  }
  if( !loaded_RtlUnicodeStringAPIs ){
    fnRtlInitUnicodeString =
      GetProcAddress(GetModuleHandleA("ntdll"),"RtlInitUnicodeString");
    fnRtlEqualUnicodeString =
      GetProcAddress(GetModuleHandleA("ntdll"),"RtlEqualUnicodeString");
    loaded_RtlUnicodeStringAPIs = 1;
  }
  if( fnRtlInitUnicodeString && fnRtlEqualUnicodeString ){
    struct { /* UNICODE_STRING from <ntdef.h> */
      unsigned short Length;
      unsigned short MaximumLength;
      wchar_t *Buffer;
    } u1, u2;
    fnRtlInitUnicodeString(&u1,fn1);
    fnRtlInitUnicodeString(&u2,fn2);
    return (unsigned char)fnRtlEqualUnicodeString(&u1,&u2,1);
  }
  /* In what kind of strange parallel universe are we? */
  return lstrcmpiW(fn1,fn2)==0;
}

/* Helper macros to deal with directory separators. */
#define IS_DIRSEP(s,i) ( s[i]=='/' || s[i]=='\\' )







>
>
>
>
>
>
>
>
>
>
>
>
|
|
|



|







|

|




<
<
<
<
|


|







302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341




342
343
344
345
346
347
348
349
350
351
352
** undesirable in file name comparison, so lstrcmpiW() is only invoked in cases
** that are technically impossible and contradicting all known laws of physics.
*/
int win32_filenames_equal_nocase(
  const wchar_t *fn1,
  const wchar_t *fn2
){
  /* ---- Data types used by dynamically loaded API functions. -------------- */
  typedef struct { /* UNICODE_STRING from <ntdef.h> */
    USHORT Length;
    USHORT MaximumLength;
    PWSTR Buffer;
  } MY_UNICODE_STRING;
  /* ---- Prototypes for dynamically loaded API functions. ------------------ */
  typedef int (WINAPI *FNCOMPARESTRINGORDINAL)(LPCWCH,int,LPCWCH,int,BOOL);
  typedef VOID (NTAPI *FNRTLINITUNICODESTRING)(MY_UNICODE_STRING*,PCWSTR);
  typedef BOOLEAN (NTAPI *FNRTLEQUALUNICODESTRING)
    (MY_UNICODE_STRING*,MY_UNICODE_STRING*,BOOLEAN);
  /* ------------------------------------------------------------------------ */
  static FNCOMPARESTRINGORDINAL fnCompareStringOrdinal;
  static FNRTLINITUNICODESTRING fnRtlInitUnicodeString;
  static FNRTLEQUALUNICODESTRING fnRtlEqualUnicodeString;
  static int loaded_CompareStringOrdinal;
  static int loaded_RtlUnicodeStringAPIs;
  if( !loaded_CompareStringOrdinal ){
    fnCompareStringOrdinal = (FNCOMPARESTRINGORDINAL)
      GetProcAddress(GetModuleHandleA("kernel32"),"CompareStringOrdinal");
    loaded_CompareStringOrdinal = 1;
  }
  if( fnCompareStringOrdinal ){
    return fnCompareStringOrdinal(fn1,-1,fn2,-1,1)-2==0;
  }
  if( !loaded_RtlUnicodeStringAPIs ){
    fnRtlInitUnicodeString = (FNRTLINITUNICODESTRING)
      GetProcAddress(GetModuleHandleA("ntdll"),"RtlInitUnicodeString");
    fnRtlEqualUnicodeString = (FNRTLEQUALUNICODESTRING)
      GetProcAddress(GetModuleHandleA("ntdll"),"RtlEqualUnicodeString");
    loaded_RtlUnicodeStringAPIs = 1;
  }
  if( fnRtlInitUnicodeString && fnRtlEqualUnicodeString ){




    MY_UNICODE_STRING u1, u2;
    fnRtlInitUnicodeString(&u1,fn1);
    fnRtlInitUnicodeString(&u2,fn2);
    return (BOOLEAN/*unsigned char*/)fnRtlEqualUnicodeString(&u1,&u2,1);
  }
  /* In what kind of strange parallel universe are we? */
  return lstrcmpiW(fn1,fn2)==0;
}

/* Helper macros to deal with directory separators. */
#define IS_DIRSEP(s,i) ( s[i]=='/' || s[i]=='\\' )
459
460
461
462
463
464
465









466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
** Call the GetFileInformationByHandleEx() function on Windows Vista, and resort
** to the GetFileInformationByHandle() function on Windows XP. The result string
** is allocated by mprintf(), or NULL on failure.
*/
char *win32_file_id(
  const char *zFileName
){









  static FARPROC fnGetFileInformationByHandleEx;
  static int loaded_fnGetFileInformationByHandleEx;
  wchar_t *wzFileName = fossil_utf8_to_path(zFileName,0);
  HANDLE hFile;
  char *zFileId = 0;
  hFile = CreateFileW(
            wzFileName,
            0,
            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
            NULL,
            OPEN_EXISTING,
            FILE_FLAG_BACKUP_SEMANTICS,
            NULL);
  if( hFile!=INVALID_HANDLE_VALUE ){
    BY_HANDLE_FILE_INFORMATION fi;
    struct { /* FILE_ID_INFO from <winbase.h> */
      u64 VolumeSerialNumber;
      unsigned char FileId[16];
    } fi2;
    if( !loaded_fnGetFileInformationByHandleEx ){
      fnGetFileInformationByHandleEx = GetProcAddress(

        GetModuleHandleA("kernel32"),"GetFileInformationByHandleEx");
      loaded_fnGetFileInformationByHandleEx = 1;
    }
    if( fnGetFileInformationByHandleEx ){
      if( fnGetFileInformationByHandleEx(
            hFile,/*FileIdInfo*/0x12,&fi2,sizeof(fi2)) ){
        zFileId = mprintf(
                    "%016llx/"







>
>
>
>
>
>
>
>
>
|














|
<
<
<

|
>
|







467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498



499
500
501
502
503
504
505
506
507
508
509
** Call the GetFileInformationByHandleEx() function on Windows Vista, and resort
** to the GetFileInformationByHandle() function on Windows XP. The result string
** is allocated by mprintf(), or NULL on failure.
*/
char *win32_file_id(
  const char *zFileName
){
  /* ---- Data types used by dynamically loaded API functions. -------------- */
  typedef struct { /* FILE_ID_INFO from <winbase.h> */
    ULONGLONG VolumeSerialNumber;
    BYTE FileId[16];
  } MY_FILE_ID_INFO;
  /* ---- Prototypes for dynamically loaded API functions. ------------------ */
  typedef int (WINAPI *FNGETFILEINFORMATIONBYHANDLEEX)
    (HANDLE,int/*enum*/,MY_FILE_ID_INFO*,DWORD);
  /* ------------------------------------------------------------------------ */
  static FNGETFILEINFORMATIONBYHANDLEEX fnGetFileInformationByHandleEx;
  static int loaded_fnGetFileInformationByHandleEx;
  wchar_t *wzFileName = fossil_utf8_to_path(zFileName,0);
  HANDLE hFile;
  char *zFileId = 0;
  hFile = CreateFileW(
            wzFileName,
            0,
            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
            NULL,
            OPEN_EXISTING,
            FILE_FLAG_BACKUP_SEMANTICS,
            NULL);
  if( hFile!=INVALID_HANDLE_VALUE ){
    BY_HANDLE_FILE_INFORMATION fi;
    MY_FILE_ID_INFO fi2;



    if( !loaded_fnGetFileInformationByHandleEx ){
      fnGetFileInformationByHandleEx = (FNGETFILEINFORMATIONBYHANDLEEX)
        GetProcAddress(
          GetModuleHandleA("kernel32"),"GetFileInformationByHandleEx");
      loaded_fnGetFileInformationByHandleEx = 1;
    }
    if( fnGetFileInformationByHandleEx ){
      if( fnGetFileInformationByHandleEx(
            hFile,/*FileIdInfo*/0x12,&fi2,sizeof(fi2)) ){
        zFileId = mprintf(
                    "%016llx/"