Changeset 3184 for trunk/src/kmk
- Timestamp:
- Mar 23, 2018, 11:36:43 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/dir-nt-bird.c
r3169 r3184 31 31 * Header Files * 32 32 *********************************************************************************************************************************/ 33 #include <Windows.h> /* locking */ 33 34 #include "nt/kFsCache.h" 34 35 #include "makeint.h" … … 147 148 * @returns 1 if it does exist, 0 if it doesn't. 148 149 * @param pszPath The path to check out. 150 * @note Multi-thread safe. 149 151 */ 150 152 int file_exists_p(const char *pszPath) 151 153 { 152 int fRc; 153 if (GetCurrentThreadId() == g_idMainThread) 154 { 155 KFSLOOKUPERROR enmError; 156 PKFSOBJ pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError); 157 if (pPathObj) 158 { 159 fRc = pPathObj->bObjType != KFSOBJ_TYPE_MISSING; 160 kFsCacheObjRelease(g_pFsCache, pPathObj); 161 } 162 else 163 fRc = 0; 164 } 165 else 166 fRc = GetFileAttributesA(pszPath) != INVALID_FILE_ATTRIBUTES; 154 int fRc; 155 KFSLOOKUPERROR enmError; 156 PKFSOBJ pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError); 157 if (pPathObj) 158 { 159 fRc = pPathObj->bObjType != KFSOBJ_TYPE_MISSING; 160 kFsCacheObjRelease(g_pFsCache, pPathObj); 161 } 162 else 163 fRc = 0; 164 return fRc; 165 } 166 167 168 /** 169 * Checks if a file exists and is a regular file, given a UTF-16 string. 170 * 171 * @returns 1 if it regular file, 0 if doesn't exist or isn't a file 172 * @param pwszPath The UTF-16 path to check out. 173 * @note Multi-thread safe. 174 */ 175 int utf16_regular_file_p(const wchar_t *pwszPath) 176 { 177 int fRc; 178 KFSLOOKUPERROR enmError; 179 PKFSOBJ pPathObj = kFsCacheLookupW(g_pFsCache, pwszPath, &enmError); 180 if (pPathObj) 181 { 182 fRc = pPathObj->bObjType == KFSOBJ_TYPE_FILE; 183 kFsCacheObjRelease(g_pFsCache, pPathObj); 184 } 185 else 186 fRc = 0; 167 187 return fRc; 168 188 } … … 483 503 void nt_fullpath_cached(const char *pszPath, char *pszFull, size_t cbFull) 484 504 { 485 if (GetCurrentThreadId() == g_idMainThread) 486 { 487 KFSLOOKUPERROR enmError; 488 PKFSOBJ pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError); 489 if (pPathObj) 490 { 491 KSIZE off = pPathObj->cchParent; 492 if (off > 0) 493 { 494 KSIZE offEnd = off + pPathObj->cchName; 495 if (offEnd < cbFull) 505 KFSLOOKUPERROR enmError; 506 PKFSOBJ pPathObj; 507 508 KFSCACHE_LOCK(g_pFsCache); /* let's start out being careful. */ 509 510 pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError); 511 if (pPathObj) 512 { 513 KSIZE off = pPathObj->cchParent; 514 if (off > 0) 515 { 516 KSIZE offEnd = off + pPathObj->cchName; 517 if (offEnd < cbFull) 518 { 519 PKFSDIR pAncestor; 520 521 pszFull[offEnd] = '\0'; 522 memcpy(&pszFull[off], pPathObj->pszName, pPathObj->cchName); 523 524 for (pAncestor = pPathObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent) 496 525 { 497 PKFSDIR pAncestor; 498 499 pszFull[offEnd] = '\0'; 500 memcpy(&pszFull[off], pPathObj->pszName, pPathObj->cchName); 501 502 for (pAncestor = pPathObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent) 526 kHlpAssert(off > 1); 527 kHlpAssert(pAncestor != NULL); 528 kHlpAssert(pAncestor->Obj.cchName > 0); 529 pszFull[--off] = '/'; 530 #ifdef KFSCACHE_CFG_SHORT_NAMES 531 if ( pAncestor->Obj.pszName == pAncestor->Obj.pszShortName 532 || memchr(pAncestor->Obj.pszName, ' ', pAncestor->Obj.cchName) == NULL) 533 #endif 503 534 { 504 kHlpAssert(off > 1);505 kHlpAssert(pAncestor != NULL);506 kHlpAssert(pAncestor->Obj.cchName > 0);507 pszFull[--off] = '/';535 off -= pAncestor->Obj.cchName; 536 kHlpAssert(pAncestor->Obj.cchParent == off); 537 memcpy(&pszFull[off], pAncestor->Obj.pszName, pAncestor->Obj.cchName); 538 } 508 539 #ifdef KFSCACHE_CFG_SHORT_NAMES 509 if ( pAncestor->Obj.pszName == pAncestor->Obj.pszShortName 510 || memchr(pAncestor->Obj.pszName, ' ', pAncestor->Obj.cchName) == NULL) 540 else 541 { 542 /* 543 * The long name constains a space, so use the alternative name instead. 544 * Most likely the alternative name differs in length, usually it's shorter, 545 * so we have to shift the part of the path we've already assembled 546 * accordingly. 547 */ 548 KSSIZE cchDelta = (KSSIZE)pAncestor->Obj.cchShortName - (KSSIZE)pAncestor->Obj.cchName; 549 if (cchDelta != 0) 550 { 551 if ((KSIZE)(offEnd + cchDelta) >= cbFull) 552 goto l_fallback; 553 memmove(&pszFull[off + cchDelta], &pszFull[off], offEnd + 1 - off); 554 off += cchDelta; 555 offEnd += cchDelta; 556 } 557 off -= pAncestor->Obj.cchShortName; 558 kHlpAssert(pAncestor->Obj.cchParent == off); 559 memcpy(&pszFull[off], pAncestor->Obj.pszShortName, pAncestor->Obj.cchShortName); 560 } 511 561 #endif 512 {513 off -= pAncestor->Obj.cchName;514 kHlpAssert(pAncestor->Obj.cchParent == off);515 memcpy(&pszFull[off], pAncestor->Obj.pszName, pAncestor->Obj.cchName);516 }517 #ifdef KFSCACHE_CFG_SHORT_NAMES518 else519 {520 /*521 * The long name constains a space, so use the alternative name instead.522 * Most likely the alternative name differs in length, usually it's shorter,523 * so we have to shift the part of the path we've already assembled524 * accordingly.525 */526 KSSIZE cchDelta = (KSSIZE)pAncestor->Obj.cchShortName - (KSSIZE)pAncestor->Obj.cchName;527 if (cchDelta != 0)528 {529 if ((KSIZE)(offEnd + cchDelta) >= cbFull)530 goto l_fallback;531 memmove(&pszFull[off + cchDelta], &pszFull[off], offEnd + 1 - off);532 off += cchDelta;533 offEnd += cchDelta;534 }535 off -= pAncestor->Obj.cchShortName;536 kHlpAssert(pAncestor->Obj.cchParent == off);537 memcpy(&pszFull[off], pAncestor->Obj.pszShortName, pAncestor->Obj.cchShortName);538 }539 #endif540 }541 kFsCacheObjRelease(g_pFsCache, pPathObj);542 return;543 562 } 544 } 545 else 546 { 547 if ((size_t)pPathObj->cchName + 1 < cbFull) 548 { 549 /* Assume no spaces here. */ 550 memcpy(pszFull, pPathObj->pszName, pPathObj->cchName); 551 pszFull[pPathObj->cchName] = '/'; 552 pszFull[pPathObj->cchName + 1] = '\0'; 553 554 kFsCacheObjRelease(g_pFsCache, pPathObj); 555 return; 556 } 557 } 558 559 /* do fallback. */ 563 kFsCacheObjRelease(g_pFsCache, pPathObj); 564 KFSCACHE_UNLOCK(g_pFsCache); 565 return; 566 } 567 } 568 else 569 { 570 if ((size_t)pPathObj->cchName + 1 < cbFull) 571 { 572 /* Assume no spaces here. */ 573 memcpy(pszFull, pPathObj->pszName, pPathObj->cchName); 574 pszFull[pPathObj->cchName] = '/'; 575 pszFull[pPathObj->cchName + 1] = '\0'; 576 577 kFsCacheObjRelease(g_pFsCache, pPathObj); 578 KFSCACHE_UNLOCK(g_pFsCache); 579 return; 580 } 581 } 582 583 /* do fallback. */ 560 584 #ifdef KFSCACHE_CFG_SHORT_NAMES 561 585 l_fallback: 562 586 #endif 563 564 565 566 }587 kHlpAssertFailed(); 588 kFsCacheObjRelease(g_pFsCache, pPathObj); 589 } 590 KFSCACHE_UNLOCK(g_pFsCache); 567 591 568 592 nt_fullpath(pszPath, pszFull, cbFull); -
trunk/src/kmk/makeint.h
r3170 r3184 720 720 void dir_setup_glob (glob_t *); 721 721 void hash_init_directories (void); 722 #if defined (KMK) && defined (KBUILD_OS_WINDOWS) 723 int utf16_regular_file_p(const wchar_t *pwszPath); 724 #endif 722 725 723 726 void define_default_variables (void);
Note:
See TracChangeset
for help on using the changeset viewer.