VirtualBox

Changeset 3473 in kBuild for trunk


Ignore:
Timestamp:
Sep 16, 2020 9:12:58 PM (4 years ago)
Author:
bird
Message:

kash: Added two specialized shfile_stat variants: shfile_stat_isreg, shfile_stat_exists. Increased the pipe size for windows to 64KB (SHFILE_PIPE_SIZE).

Location:
trunk/src/kash
Files:
3 edited

Legend:

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

    r3463 r3473  
    6767
    6868#define EMPTY -2                /* marks an unused slot in redirtab */
    69 #ifndef PIPE_BUF
    70 # define PIPESIZE 4096          /* amount of buffering in a pipe */
    71 #else
    72 # define PIPESIZE PIPE_BUF
    73 #endif
     69#define PIPESIZE SHFILE_PIPE_SIZE
    7470
    7571
  • trunk/src/kash/shfile.c

    r3471 r3473  
    3636
    3737#if K_OS == K_OS_WINDOWS
    38 # include <limits.h>
    39 # ifndef PIPE_BUF
    40 #  define PIPE_BUF 512
    41 # endif
    4238# include <ntstatus.h>
    4339# define WIN32_NO_STATUS
     
    17111707
    17121708    fds[1] = fds[0] = -1;
    1713     if (CreatePipe(&hRead, &hWrite, &SecurityAttributes, 4096))
     1709    if (CreatePipe(&hRead, &hWrite, &SecurityAttributes, SHFILE_PIPE_SIZE))
    17141710    {
    17151711        fds[0] = shfile_insert(pfdtab, (intptr_t)hRead, O_RDONLY, SHFILE_FLAGS_PIPE, -1, "shfile_pipe", "pipe-rd");
     
    21932189#else
    21942190    return stat(path, pst);
     2191#endif
     2192}
     2193
     2194/**
     2195 * @retval 1 if regular file.
     2196 * @retval 0 if found but not a regular file.
     2197 * @retval -1 and errno on failure
     2198 */
     2199int shfile_stat_isreg(shfdtab *pfdtab, const char *path)
     2200{
     2201#if defined(SHFILE_IN_USE) && K_OS == K_OS_WINDOWS
     2202    char    abspath[SHFILE_MAX_PATH];
     2203    KU16    mode = 0;
     2204    int     rc = shfile_make_path(pfdtab, path, &abspath[0]);
     2205    if (!rc)
     2206    {
     2207        rc = birdStatModeOnly(abspath, &mode, 0 /*fFollowLink*/);
     2208        if (rc >= 0)
     2209            rc = S_ISREG(mode) ? 1 : 0;
     2210    }
     2211    TRACE2((NULL, "shfile_stat_isreg(,%s,) -> %d [%d] st_mode=%o\n", path, rc, errno, mode));
     2212    return rc;
     2213#else
     2214    struct stat st;
     2215    int rc = shfile_stat(pfdtab, path, &st);
     2216    if (rc >= 0)
     2217        rc = S_ISREG(st.st_mode) ? 1 : 0;
     2218    return rc;
     2219#endif
     2220}
     2221
     2222/**
     2223 * Same as shfile_stat, but without the data structure.
     2224 */
     2225int shfile_stat_exists(shfdtab *pfdtab, const char *path)
     2226{
     2227#if defined(SHFILE_IN_USE) && K_OS == K_OS_WINDOWS
     2228    char    abspath[SHFILE_MAX_PATH];
     2229    KU16    mode = 0;
     2230    int     rc = shfile_make_path(pfdtab, path, &abspath[0]);
     2231    if (!rc)
     2232        rc = birdStatModeOnly(abspath, &mode, 0 /*fFollowLink*/);
     2233    TRACE2((NULL, "shfile_stat_exists(,%s,) -> %d [%d] st_mode=%o\n", path, rc, errno, mode));
     2234    return rc;
     2235#else
     2236    struct stat ignored;
     2237    return shfile_stat(pfdtab, path, &ignored);
    21952238#endif
    21962239}
  • trunk/src/kash/shfile.h

    r3469 r3473  
    4747# endif
    4848#endif
     49#include <limits.h> /* for PIPE_BUF */
    4950#ifndef _MSC_VER
    5051# include <fcntl.h>
     
    160161
    161162int shfile_open(shfdtab *, const char *, unsigned, mode_t);
     163#if K_OS == K_OS_WINDOWS
     164# define SHFILE_PIPE_SIZE   65536
     165#elif defined(PIPE_BUF)
     166# define SHFILE_PIPE_SIZE   PIPE_BUF
     167#else
     168# define SHFILE_PIPE_SIZE   4096
     169#endif
    162170int shfile_pipe(shfdtab *, int [2]);
    163171int shfile_close(shfdtab *, unsigned);
     
    171179
    172180int shfile_stat(shfdtab *, const char *, struct stat *);
     181int shfile_stat_isreg(shfdtab *, const char *);  /**< returns -1, 0 or 1. */
     182int shfile_stat_exists(shfdtab *, const char *); /**< same as shfile_stat, but discards the stat data. */
    173183int shfile_lstat(shfdtab *, const char *, struct stat *);
    174184int shfile_chdir(shfdtab *, const char *);
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