Changeset 2681 in kBuild for trunk/src/kash/shfile.c
- Timestamp:
- Apr 14, 2013 6:41:58 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/shfile.c
r2653 r2681 427 427 428 428 # if K_OS == K_OS_WINDOWS 429 430 /** 431 * Adjusts the file name if it ends with a trailing directory slash. 432 * 433 * Windows APIs doesn't like trailing slashes. 434 * 435 * @returns 1 if it has a directory slash, 0 if not. 436 * 437 * @param abspath The path to adjust (SHFILE_MAX_PATH). 438 */ 439 static int shfile_trailing_slash_hack(char *abspath) 440 { 441 /* 442 * Anything worth adjust here? 443 */ 444 size_t path_len = strlen(abspath); 445 if ( path_len == 0 446 || ( abspath[path_len - 1] != '/' 447 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2 448 && abspath[path_len - 1] != '\\' 449 # endif 450 ) 451 ) 452 return 0; 453 454 /* 455 * Ok, make the adjustment. 456 */ 457 if (path_len + 2 <= SHFILE_MAX_PATH) 458 { 459 /* Add a '.' to the end. */ 460 abspath[path_len++] = '.'; 461 abspath[path_len] = '\0'; 462 } 463 else 464 { 465 /* No space for a dot, remove the slash if it's alone or just remove 466 one and add a dot like above. */ 467 if ( abspath[path_len - 2] != '/' 468 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2 469 && abspath[path_len - 2] != '\\' 470 # endif 471 ) 472 abspath[--path_len] = '\0'; 473 else 474 abspath[path_len - 1] = '.'; 475 } 476 477 return 1; 478 } 479 429 480 430 481 /** … … 1555 1606 { 1556 1607 # if K_OS == K_OS_WINDOWS 1608 int dir_slash = shfile_trailing_slash_hack(abspath); 1557 1609 rc = stat(abspath, pst); /** @todo re-implement stat. */ 1610 if (!rc && dir_slash && !S_ISDIR(pst->st_mode)) 1611 { 1612 rc = -1; 1613 errno = ENOTDIR; 1614 } 1558 1615 # else 1559 1616 rc = stat(abspath, pst); … … 1577 1634 { 1578 1635 # if K_OS == K_OS_WINDOWS 1579 rc = stat(abspath, pst); /** @todo implement lstat. */ 1636 int dir_slash = shfile_trailing_slash_hack(abspath); 1637 rc = stat(abspath, pst); /** @todo re-implement stat. */ 1638 if (!rc && dir_slash && !S_ISDIR(pst->st_mode)) 1639 { 1640 rc = -1; 1641 errno = ENOTDIR; 1642 } 1580 1643 # else 1581 1644 rc = lstat(abspath, pst);
Note:
See TracChangeset
for help on using the changeset viewer.