VirtualBox

Changeset 1044 in kBuild


Ignore:
Timestamp:
Jun 9, 2007 3:32:47 AM (18 years ago)
Author:
bird
Message:

Fixed a number of bugs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kObjCache/kObjCache.c

    r1043 r1044  
    8888#endif
    8989
     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
    90100
    91101/*******************************************************************************
     
    200210    void *pv = malloc(cb);
    201211    if (!pv)
    202         FatalDie(NULL, "out of memory (%d)\n", (int)cb);
     212        FatalDie("out of memory (%d)\n", (int)cb);
    203213    return pv;
    204214}
     
    209219    void *pv = realloc(pvOld, cb);
    210220    if (!pv)
    211         FatalDie(NULL, "out of memory (%d)\n", (int)cb);
     221        FatalDie("out of memory (%d)\n", (int)cb);
    212222    return pv;
    213223}
     
    218228    char *psz = strdup(pszIn);
    219229    if (!psz)
    220         FatalDie(NULL, "out of memory (%d)\n", (int)strlen(pszIn));
     230        FatalDie("out of memory (%d)\n", (int)strlen(pszIn));
    221231    return psz;
    222232}
     
    532542static int MakePath(const char *pszPath)
    533543{
    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;
    536588}
    537589
     
    579631     */
    580632    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 *));
    583635    *ppapszArgs = memcpy(papszArgs, *ppapszArgs, i * sizeof(char *));
    584636
     
    589641    while (*psz)
    590642    {
     643        size_t cch;
    591644        const char *pszEnd;
    592645        while (isspace(*psz))
     
    598651            pszEnd++;
    599652
    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
    603658        i++;
    604     }
     659        psz = pszEnd;
     660    }
     661
     662    papszArgs[i] = NULL;
    605663}
    606664
     
    14621520    {
    14631521        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);
    14661524        fdReDir = open(pszStdOut, O_CREAT | O_TRUNC | O_WRONLY, 0666);
    14671525        if (fdReDir < 0)
     
    14691527                     pszMsg, pszStdOut, strerror(errno));
    14701528
    1471         if (fdReDir != 1)
    1472         {
    1473             if (dup2(fdReDir, 1) < 0)
     1529        if (fdReDir != STDOUT_FILENO)
     1530        {
     1531            if (dup2(fdReDir, STDOUT_FILENO) < 0)
    14741532                FatalDie("%s - dup2 failed: %s\n", pszMsg, strerror(errno));
    14751533            close(fdReDir);
     
    14851543    if (fdStdOut)
    14861544    {
    1487         close(1);
    1488         fdStdOut = dup2(fdStdOut, 1);
     1545        close(STDOUT_FILENO);
     1546        fdStdOut = dup2(fdStdOut, STDOUT_FILENO);
    14891547        close(fdStdOut);
    14901548    }
     
    15001558            int fdReDir;
    15011559
    1502             close(1);
     1560            close(STDOUT_FILENO);
    15031561            fdReDir = open(pszStdOut, O_CREAT | O_TRUNC | O_WRONLY, 0666);
    15041562            if (fdReDir < 0)
    15051563                FatalDie("%s - failed to create stdout redirection file '%s': %s\n",
    15061564                         pszMsg, pszStdOut, strerror(errno));
    1507             if (fdReDir != 1)
     1565            if (fdReDir != STDOUT_FILENO)
    15081566            {
    1509                 if (dup2(fdReDir, 1) < 0)
     1567                if (dup2(fdReDir, STDOUT_FILENO) < 0)
    15101568                    FatalDie("%s - dup2 failed: %s\n", pszMsg, strerror(errno));
    15111569                close(fdReDir);
     
    15541612     * Setup redirection.
    15551613     */
    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)
    15601618            FatalDie("%s - dup2(,1) failed: %s\n", pszMsg, strerror(errno));
    15611619        close(fdStdOut);
     
    15641622#endif
    15651623    }
    1566     if (fdStdIn != -1)
    1567     {
    1568         fdSavedStdIn = dup(0 /* stdin */);
    1569         if (dup2(fdStdOut, 0 /* stdin */) < 0)
     1624    if (fdStdIn != -1 && fdStdIn != STDIN_FILENO)
     1625    {
     1626        fdSavedStdIn = dup(STDIN_FILENO);
     1627        if (dup2(fdStdIn, STDIN_FILENO) < 0)
    15701628            FatalDie("%s - dup2(,0) failed: %s\n", pszMsg, strerror(errno));
    15711629        close(fdStdIn);
     
    15981656     * Restore stdout & stdin.
    15991657     */
    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);
    16041662        close(fdSavedStdIn);
    16051663    }
    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);
    16101668        close(fdSavedStdOut);
    16111669    }
    16121670
     1671    InfoMsg(3, "%s - spawned %ld\n", pszMsg, (long)pid);
    16131672    (void)cArgv;
    16141673    (void)pEntry;
     
    16281687    int iStatus = -1;
    16291688    pid_t pidWait;
     1689    InfoMsg(3, "%s - wait-child(%ld)\n", pszMsg, (long)pid);
     1690
    16301691#ifdef __WIN__
    16311692    pidWait = _cwait(&iStatus, pid, _WAIT_CHILD);
     
    16581719static void kOCEntryCreatePipe(PKOCENTRY pEntry, int *pFDs, const char *pszMsg)
    16591720{
     1721    pFDs[0] = pFDs[1] = -1;
    16601722#if defined(__WIN__)
    16611723    if (_pipe(pFDs, 0, _O_NOINHERIT | _O_BINARY) < 0)
     
    17481810     */
    17491811    kOCEntryCreatePipe(pEntry, fds, pszMsg);
    1750     pidProducer = kOCEntrySpawnChild(pEntry, papszProdArgv, cProdArgv, fds[0 /* read */], -1, pszMsg);
     1812    pidProducer = kOCEntrySpawnChild(pEntry, papszConsArgv, cConsArgv, fds[0 /* read */], -1, pszMsg);
    17511813    fdOut = fds[1 /* write */];
    17521814
     
    20042066        cbLeft -= cbWritten;
    20052067    }
     2068    close(fdOut);
    20062069
    20072070    if (pEntry->fPipedPreComp)
     
    20752138    cbLeft = cbAlloc;
    20762139    pEntry->New.pszCppMapping = psz = xmalloc(cbAlloc);
     2140    InfoMsg(3, "precompiler|compile - starting passhtru...\n");
    20772141    for (;;)
    20782142    {
     
    20902154                     fdIn, (long)cbLeft, strerror(errno));
    20912155        }
     2156        InfoMsg(2, "precompiler|compile - read %d\n", cbRead);
    20922157
    20932158        /*
     
    21232188        }
    21242189    }
     2190    InfoMsg(2, "precompiler|compile - done passhtru\n");
    21252191
    21262192    close(fdIn);
     
    36813747        if (!pszCacheName)
    36823748        {
    3683             pszCacheName = FindFilenameInPath(pszCacheFile);
     3749            pszCacheName = FindFilenameInPath(pszEntryFile);
    36843750            if (!*pszCacheName)
    36853751                return SyntaxError("The cache file (-f) specifies a directory / nothing!\n");
     
    36893755                *psz = '\0';
    36903756        }
    3691         pszCacheFile = MakePathFromDirAndFile(pszCacheDir, pszCacheName); /* harmless leak. */
     3757        pszCacheFile = MakePathFromDirAndFile(pszCacheName, pszCacheDir);
    36923758    }
    36933759
     
    37623828     * Update the cache files.
    37633829     */
     3830    kObjCacheRemoveEntry(pCache, pEntry);
    37643831    kObjCacheInsertEntry(pCache, pEntry);
    37653832    kOCEntryWrite(pEntry);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette