VirtualBox

Changeset 2652 in kBuild for trunk/src/kash/shfile.c


Ignore:
Timestamp:
Sep 9, 2012 5:21:48 PM (12 years ago)
Author:
bird
Message:

kash: Fixes for hash-bang-scripts on windows. Related debug tracing fix. Another CWD slash fix. Fixed a couple of assertions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/shfile.c

    r2650 r2652  
    164164static void shfile_native_close(intptr_t native, unsigned flags)
    165165{
    166 #if K_OS == K_OS_WINDOWS
     166# if K_OS == K_OS_WINDOWS
    167167    BOOL fRc = CloseHandle((HANDLE)native);
    168168    assert(fRc); (void)fRc;
    169 #else
     169# else
    170170    int s = errno;
    171171    close(native);
    172172    errno = s;
    173 #endif
     173# endif
    174174    (void)flags;
    175175}
     
    289289}
    290290
    291 #if K_OS != K_OS_WINDOWS
     291# if K_OS != K_OS_WINDOWS
    292292/**
    293293 * Makes a copy of the native file, closes the original, and inserts the copy
     
    318318    return fd;
    319319}
    320 #endif /* !K_OS_WINDOWS */
     320# endif /* !K_OS_WINDOWS */
    321321
    322322/**
     
    385385    }
    386386    if (    *path == '/'
    387 #if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     387# if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
    388388        ||  *path == '\\'
    389389        ||  (   *path
     
    391391             && (   (*path >= 'A' && *path <= 'Z')
    392392                 || (*path >= 'a' && *path <= 'z')))
    393 #endif
     393# endif
    394394        )
    395395    {
     
    419419    }
    420420
    421 #if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     421# if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
    422422    if (!strcmp(buf, "/dev/null"))
    423423        strcpy(buf, "NUL");
    424 #endif
     424# endif
    425425    return 0;
    426426}
     
    528528
    529529/**
     530 * Converts DOS slashes to UNIX slashes if necessary.
     531 *
     532 * @param   pszPath             The path to fix.
     533 */
     534static void shfile_fix_slashes(char *pszPath)
     535{
     536#if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     537    while ((pszPath = strchr(pszPath, '\\')))
     538        *pszPath++ = '/';
     539#else
     540    (void)pszPath;
     541#endif
     542}
     543
     544/**
    530545 * Initializes the global variables in this file.
    531546 */
     
    574589        if (getcwd(buf, sizeof(buf)))
    575590        {
    576 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
    577             char *pszSlash = strchr(buf, '\\');
    578             while (pszSlash)
    579             {
    580                 *pszSlash = '/';
    581                 pszSlash = strchr(pszSlash + 1, '\\');
    582             }
    583 # endif
     591            shfile_fix_slashes(buf);
    584592
    585593            pfdtab->cwd = sh_strdup(NULL, buf);
     
    13901398        rc = -1;
    13911399
    1392 #else
     1400# ifdef DEBUG
    13931401    if (fd != shthread_get_shell()->tracefd)
    1394     {
     1402        TRACE2((NULL, "shfile_write(%d,,%d) -> %d [%d]\n", fd, len, rc, errno));
     1403# endif
     1404
     1405#else
     1406    if (fd != shthread_get_shell()->tracefd)
     1407    {
     1408        int iSavedErrno = errno;
    13951409        struct stat s;
    13961410        int x;
     
    13981412        TRACE2((NULL, "shfile_write(%d) - %lu bytes (%d) - pos %lu - before; %o\n",
    13991413                fd, (long)s.st_size, x, (long)lseek(fd, 0, SEEK_CUR), s.st_mode ));
    1400         errno = 0;
     1414        errno = iSavedErrno;
    14011415    }
    14021416
    14031417    rc = write(fd, buf, len);
    1404 #endif
    1405 
    1406 #ifdef DEBUG
    1407     if (fd != shthread_get_shell()->tracefd)
    1408     {
    1409         struct stat s;
    1410         int x;
    1411         TRACE2((NULL, "shfile_write(%d,,%d) -> %d [%d]\n", fd, len, rc, errno));
    1412         x=fstat(fd, &s);
    1413         TRACE2((NULL, "shfile_write(%d) - %lu bytes (%d) - pos %lu - after\n", fd, (long)s.st_size, x, (long)lseek(fd, 0, SEEK_CUR) ));
    1414     }
    14151418#endif
    14161419    return rc;
     
    16011604        char *abspath_copy = sh_strdup(psh, abspath);
    16021605        char *free_me = abspath_copy;
    1603         rc = chdir(path);
     1606        rc = chdir(abspath);
    16041607        if (!rc)
    16051608        {
     
    16071610            shmtx_enter(&pfdtab->mtx, &tmp);
    16081611
     1612            shfile_fix_slashes(abspath_copy);
    16091613            free_me = pfdtab->cwd;
    16101614            pfdtab->cwd = abspath_copy;
Note: See TracChangeset for help on using the changeset viewer.

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