Fossil

Check-in [49262642]
Login

Check-in [49262642]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Amend [9919dfbbaa], again: Include an optional directory separator in buffer size calculation, guard against the unlikely (impossible?) case that a case-adjusted filename component round-tripping from UTF-8 to UTF-16 and back get longer, plus some unrelated white space fix.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 49262642f421900cab3f58bf913417176410d036d0d06b19f17f6a8433d01265
User & Date: florian 2024-10-16 05:16:00
Context
2024-10-17
16:10
Update the built-in SQLite to the latest 3.47.0 beta for testing. ... (check-in: d0730da0 user: drh tags: trunk)
2024-10-16
07:36
Merge from trunk ... (check-in: 073e0b6b user: brickviking tags: bv-corrections01)
05:16
Amend [9919dfbbaa], again: Include an optional directory separator in buffer size calculation, guard against the unlikely (impossible?) case that a case-adjusted filename component round-tripping from UTF-8 to UTF-16 and back get longer, plus some unrelated white space fix. ... (check-in: 49262642 user: florian tags: trunk)
00:18
When searching embedded docs, search the configured 'doc-branch' branch instead of hard-wiring the search for trunk. Problem reported in forum post 520d420d04. Previously it was always searching trunk but generating links to the doc-branch. ... (check-in: 163f2f59 user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/winfile.c.

347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397




398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
*/
char *win32_file_case_preferred_name(
  const char *zBase,
  const char *zPath
){
  int cchBase = strlen(zBase);
  int cchPath = strlen(zPath);
  int cchBuf = cchBase + cchPath + 1;
  int cchRes = cchPath + 1;
  char *zBuf = fossil_malloc(cchBuf);
  char *zRes = fossil_malloc(cchRes);

  int i, j;
  memcpy(zBuf,zBase,cchBase);
  cchRes = 0;
  if( !IS_DIRSEP(zBuf,cchBase-1) ){
    zBuf[cchBase++]=L'/';
  }
  memcpy(zBuf+cchBase,zPath,cchPath+1);
  i = j = cchBase;
  while( 1 ){
    WIN32_FIND_DATAW fd;
    HANDLE hFind;
    wchar_t *wzBuf;
    char *zCompBuf = 0;
    char *zComp = &zBuf[i];
    int cchComp;
    char chSep;
    int fDone;
    if( IS_DIRSEP(zBuf,i) ){
      zRes[cchRes++] = zBuf[i];
      i = j = i+1;
      continue;
    }
    NEXT_DIRSEP(zBuf,j);
    fDone = zBuf[j]==0;
    chSep = zBuf[j];
    zBuf[j] = 0;                /* Truncate working buffer. */
    wzBuf = fossil_utf8_to_path(zBuf,0);
    hFind = FindFirstFileW(wzBuf,&fd);
    if( hFind!= INVALID_HANDLE_VALUE ){
      wchar_t *wzComp = fossil_utf8_to_path(zComp,0);
      FindClose(hFind);
      /* Test fd.cFileName, not fd.cAlternateFileName (classic 8.3 format). */
      if( win32_compare_filenames_nocase(wzComp,fd.cFileName)==0 ){
        zCompBuf = fossil_path_to_utf8(fd.cFileName);
        zComp = zCompBuf;
      }
      fossil_path_free(wzComp);
    }
    fossil_path_free(wzBuf);
    cchComp = strlen(zComp);




    memcpy(zRes+cchRes,zComp,cchComp);
    cchRes += cchComp;
    if( zCompBuf ){
      fossil_path_free(zCompBuf);
    }
    if( fDone ){
      zRes[cchRes] = 0;
      break;
    }
    zBuf[j] = chSep;            /* Undo working buffer truncation. */
    i = j;
  }
  fossil_free(zBuf);
  return zRes;
}
#endif /* _WIN32  -- This code is for win32 only */







|
|


>


<















|









|











>
>
>
>
|
|




|









347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
*/
char *win32_file_case_preferred_name(
  const char *zBase,
  const char *zPath
){
  int cchBase = strlen(zBase);
  int cchPath = strlen(zPath);
  int cchBuf = cchBase + cchPath + 2; /* + NULL + optional directory slash */
  int cchRes = cchPath + 1;           /* + NULL */
  char *zBuf = fossil_malloc(cchBuf);
  char *zRes = fossil_malloc(cchRes);
  int ncUsed = 0;
  int i, j;
  memcpy(zBuf,zBase,cchBase);

  if( !IS_DIRSEP(zBuf,cchBase-1) ){
    zBuf[cchBase++]=L'/';
  }
  memcpy(zBuf+cchBase,zPath,cchPath+1);
  i = j = cchBase;
  while( 1 ){
    WIN32_FIND_DATAW fd;
    HANDLE hFind;
    wchar_t *wzBuf;
    char *zCompBuf = 0;
    char *zComp = &zBuf[i];
    int cchComp;
    char chSep;
    int fDone;
    if( IS_DIRSEP(zBuf,i) ){
      zRes[ncUsed++] = zBuf[i];
      i = j = i+1;
      continue;
    }
    NEXT_DIRSEP(zBuf,j);
    fDone = zBuf[j]==0;
    chSep = zBuf[j];
    zBuf[j] = 0;                /* Truncate working buffer. */
    wzBuf = fossil_utf8_to_path(zBuf,0);
    hFind = FindFirstFileW(wzBuf,&fd);
    if( hFind!=INVALID_HANDLE_VALUE ){
      wchar_t *wzComp = fossil_utf8_to_path(zComp,0);
      FindClose(hFind);
      /* Test fd.cFileName, not fd.cAlternateFileName (classic 8.3 format). */
      if( win32_compare_filenames_nocase(wzComp,fd.cFileName)==0 ){
        zCompBuf = fossil_path_to_utf8(fd.cFileName);
        zComp = zCompBuf;
      }
      fossil_path_free(wzComp);
    }
    fossil_path_free(wzBuf);
    cchComp = strlen(zComp);
    if( ncUsed+cchComp+1>cchRes ){
      cchRes = ncUsed + cchComp + 32; /* While at it, add some extra space. */
      zRes = fossil_realloc(zRes,cchRes);
    }
    memcpy(zRes+ncUsed,zComp,cchComp);
    ncUsed += cchComp;
    if( zCompBuf ){
      fossil_path_free(zCompBuf);
    }
    if( fDone ){
      zRes[ncUsed] = 0;
      break;
    }
    zBuf[j] = chSep;            /* Undo working buffer truncation. */
    i = j;
  }
  fossil_free(zBuf);
  return zRes;
}
#endif /* _WIN32  -- This code is for win32 only */