Changeset 1044 in kBuild
- Timestamp:
- Jun 9, 2007 3:32:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kObjCache/kObjCache.c
r1043 r1044 88 88 #endif 89 89 90 #ifndef STDIN_FILENO 91 # define STDIN_FILENO 0 92 #endif 93 #ifndef STDOUT_FILENO 94 # define STDOUT_FILENO 1 95 #endif 96 #ifndef STDERR_FILENO 97 # define STDERR_FILENO 2 98 #endif 99 90 100 91 101 /******************************************************************************* … … 200 210 void *pv = malloc(cb); 201 211 if (!pv) 202 FatalDie( NULL,"out of memory (%d)\n", (int)cb);212 FatalDie("out of memory (%d)\n", (int)cb); 203 213 return pv; 204 214 } … … 209 219 void *pv = realloc(pvOld, cb); 210 220 if (!pv) 211 FatalDie( NULL,"out of memory (%d)\n", (int)cb);221 FatalDie("out of memory (%d)\n", (int)cb); 212 222 return pv; 213 223 } … … 218 228 char *psz = strdup(pszIn); 219 229 if (!psz) 220 FatalDie( NULL,"out of memory (%d)\n", (int)strlen(pszIn));230 FatalDie("out of memory (%d)\n", (int)strlen(pszIn)); 221 231 return psz; 222 232 } … … 532 542 static int MakePath(const char *pszPath) 533 543 { 534 /** @todo implement me */ 535 return 0; 544 int iErr = 0; 545 char *pszAbsPath = AbsPath(pszPath); 546 char *psz = pszAbsPath; 547 548 /* Skip to the root slash (PC). */ 549 while (!IS_SLASH(*psz) && *psz) 550 psz++; 551 /** @todo UNC */ 552 for (;;) 553 { 554 char chSaved; 555 556 /* skip slashes */ 557 while (IS_SLASH(*psz)) 558 psz++; 559 if (!*psz) 560 break; 561 562 /* find the next slash or end and terminate the string. */ 563 while (!IS_SLASH(*psz) && *psz) 564 psz++; 565 chSaved = *psz; 566 *psz = '\0'; 567 568 /* try create the directory, ignore failure because the directory already exists. */ 569 errno = 0; 570 #ifdef _MSC_VER 571 if ( _mkdir(pszAbsPath) 572 && errno != EEXIST) 573 #else 574 if ( mkdir(pszAbsPath, 0777) 575 && errno != EEXIST) 576 #endif 577 { 578 iErr = errno; 579 break; 580 } 581 582 /* restore the slash/terminator */ 583 *psz = chSaved; 584 } 585 586 free(pszAbsPath); 587 return iErr ? -1 : 0; 536 588 } 537 589 … … 579 631 */ 580 632 i = *pcArgs; 581 *pcArgs = i + cExtraArgs + 1 +!!pszWedgeArg;582 papszArgs = xmalloc( *pcArgs* sizeof(char *));633 *pcArgs = i + cExtraArgs + !!pszWedgeArg; 634 papszArgs = xmalloc((*pcArgs + 1) * sizeof(char *)); 583 635 *ppapszArgs = memcpy(papszArgs, *ppapszArgs, i * sizeof(char *)); 584 636 … … 589 641 while (*psz) 590 642 { 643 size_t cch; 591 644 const char *pszEnd; 592 645 while (isspace(*psz)) … … 598 651 pszEnd++; 599 652 600 papszArgs[i] = xmalloc(psz - pszEnd + 1); 601 memcpy(papszArgs[i], psz, psz - pszEnd); 602 papszArgs[i][psz - pszEnd] = '\0'; 653 cch = pszEnd - psz; 654 papszArgs[i] = xmalloc(cch + 1); 655 memcpy(papszArgs[i], psz, cch); 656 papszArgs[i][cch] = '\0'; 657 603 658 i++; 604 } 659 psz = pszEnd; 660 } 661 662 papszArgs[i] = NULL; 605 663 } 606 664 … … 1462 1520 { 1463 1521 int fdReDir; 1464 fdStdOut = dup( 1); /* dup2(1,-1) doesn't work right on windows */1465 close( 1);1522 fdStdOut = dup(STDOUT_FILENO); 1523 close(STDOUT_FILENO); 1466 1524 fdReDir = open(pszStdOut, O_CREAT | O_TRUNC | O_WRONLY, 0666); 1467 1525 if (fdReDir < 0) … … 1469 1527 pszMsg, pszStdOut, strerror(errno)); 1470 1528 1471 if (fdReDir != 1)1472 { 1473 if (dup2(fdReDir, 1) < 0)1529 if (fdReDir != STDOUT_FILENO) 1530 { 1531 if (dup2(fdReDir, STDOUT_FILENO) < 0) 1474 1532 FatalDie("%s - dup2 failed: %s\n", pszMsg, strerror(errno)); 1475 1533 close(fdReDir); … … 1485 1543 if (fdStdOut) 1486 1544 { 1487 close( 1);1488 fdStdOut = dup2(fdStdOut, 1);1545 close(STDOUT_FILENO); 1546 fdStdOut = dup2(fdStdOut, STDOUT_FILENO); 1489 1547 close(fdStdOut); 1490 1548 } … … 1500 1558 int fdReDir; 1501 1559 1502 close( 1);1560 close(STDOUT_FILENO); 1503 1561 fdReDir = open(pszStdOut, O_CREAT | O_TRUNC | O_WRONLY, 0666); 1504 1562 if (fdReDir < 0) 1505 1563 FatalDie("%s - failed to create stdout redirection file '%s': %s\n", 1506 1564 pszMsg, pszStdOut, strerror(errno)); 1507 if (fdReDir != 1)1565 if (fdReDir != STDOUT_FILENO) 1508 1566 { 1509 if (dup2(fdReDir, 1) < 0)1567 if (dup2(fdReDir, STDOUT_FILENO) < 0) 1510 1568 FatalDie("%s - dup2 failed: %s\n", pszMsg, strerror(errno)); 1511 1569 close(fdReDir); … … 1554 1612 * Setup redirection. 1555 1613 */ 1556 if (fdStdOut != -1 )1557 { 1558 fdSavedStdOut = dup( 1 /* stdout */);1559 if (dup2(fdStdOut, 1 /* stdout */) < 0)1614 if (fdStdOut != -1 && fdStdOut != STDOUT_FILENO) 1615 { 1616 fdSavedStdOut = dup(STDOUT_FILENO); 1617 if (dup2(fdStdOut, STDOUT_FILENO) < 0) 1560 1618 FatalDie("%s - dup2(,1) failed: %s\n", pszMsg, strerror(errno)); 1561 1619 close(fdStdOut); … … 1564 1622 #endif 1565 1623 } 1566 if (fdStdIn != -1 )1567 { 1568 fdSavedStdIn = dup( 0 /* stdin */);1569 if (dup2(fdStd Out, 0 /* stdin */) < 0)1624 if (fdStdIn != -1 && fdStdIn != STDIN_FILENO) 1625 { 1626 fdSavedStdIn = dup(STDIN_FILENO); 1627 if (dup2(fdStdIn, STDIN_FILENO) < 0) 1570 1628 FatalDie("%s - dup2(,0) failed: %s\n", pszMsg, strerror(errno)); 1571 1629 close(fdStdIn); … … 1598 1656 * Restore stdout & stdin. 1599 1657 */ 1600 if (fdSavedStdIn )1601 { 1602 close( 0 /* stdin */);1603 dup2(fdStdOut, 0 /* stdin */);1658 if (fdSavedStdIn != -1) 1659 { 1660 close(STDIN_FILENO); 1661 dup2(fdStdOut, STDIN_FILENO); 1604 1662 close(fdSavedStdIn); 1605 1663 } 1606 if (fdSavedStdOut )1607 { 1608 close( 1 /* stdout */);1609 dup2(fdSavedStdOut, 1 /* stdout */);1664 if (fdSavedStdOut != -1) 1665 { 1666 close(STDOUT_FILENO); 1667 dup2(fdSavedStdOut, STDOUT_FILENO); 1610 1668 close(fdSavedStdOut); 1611 1669 } 1612 1670 1671 InfoMsg(3, "%s - spawned %ld\n", pszMsg, (long)pid); 1613 1672 (void)cArgv; 1614 1673 (void)pEntry; … … 1628 1687 int iStatus = -1; 1629 1688 pid_t pidWait; 1689 InfoMsg(3, "%s - wait-child(%ld)\n", pszMsg, (long)pid); 1690 1630 1691 #ifdef __WIN__ 1631 1692 pidWait = _cwait(&iStatus, pid, _WAIT_CHILD); … … 1658 1719 static void kOCEntryCreatePipe(PKOCENTRY pEntry, int *pFDs, const char *pszMsg) 1659 1720 { 1721 pFDs[0] = pFDs[1] = -1; 1660 1722 #if defined(__WIN__) 1661 1723 if (_pipe(pFDs, 0, _O_NOINHERIT | _O_BINARY) < 0) … … 1748 1810 */ 1749 1811 kOCEntryCreatePipe(pEntry, fds, pszMsg); 1750 pidProducer = kOCEntrySpawnChild(pEntry, papsz ProdArgv, cProdArgv, fds[0 /* read */], -1, pszMsg);1812 pidProducer = kOCEntrySpawnChild(pEntry, papszConsArgv, cConsArgv, fds[0 /* read */], -1, pszMsg); 1751 1813 fdOut = fds[1 /* write */]; 1752 1814 … … 2004 2066 cbLeft -= cbWritten; 2005 2067 } 2068 close(fdOut); 2006 2069 2007 2070 if (pEntry->fPipedPreComp) … … 2075 2138 cbLeft = cbAlloc; 2076 2139 pEntry->New.pszCppMapping = psz = xmalloc(cbAlloc); 2140 InfoMsg(3, "precompiler|compile - starting passhtru...\n"); 2077 2141 for (;;) 2078 2142 { … … 2090 2154 fdIn, (long)cbLeft, strerror(errno)); 2091 2155 } 2156 InfoMsg(2, "precompiler|compile - read %d\n", cbRead); 2092 2157 2093 2158 /* … … 2123 2188 } 2124 2189 } 2190 InfoMsg(2, "precompiler|compile - done passhtru\n"); 2125 2191 2126 2192 close(fdIn); … … 3681 3747 if (!pszCacheName) 3682 3748 { 3683 pszCacheName = FindFilenameInPath(psz CacheFile);3749 pszCacheName = FindFilenameInPath(pszEntryFile); 3684 3750 if (!*pszCacheName) 3685 3751 return SyntaxError("The cache file (-f) specifies a directory / nothing!\n"); … … 3689 3755 *psz = '\0'; 3690 3756 } 3691 pszCacheFile = MakePathFromDirAndFile(pszCache Dir, pszCacheName); /* harmless leak. */3757 pszCacheFile = MakePathFromDirAndFile(pszCacheName, pszCacheDir); 3692 3758 } 3693 3759 … … 3762 3828 * Update the cache files. 3763 3829 */ 3830 kObjCacheRemoveEntry(pCache, pEntry); 3764 3831 kObjCacheInsertEntry(pCache, pEntry); 3765 3832 kOCEntryWrite(pEntry);
Note:
See TracChangeset
for help on using the changeset viewer.