Пример #1
0
void __InitFiles( void )
{
#ifdef _M_I86
    __stream_link _WCI86NEAR    *ptr;
#endif
    __stream_link               *link;
    FILE                        *fp;

    fp = _RWD_iob;
#if defined( __RDOS__ ) || defined( __RDOSDEV__ )
    stdout->_flag &= ~(_IONBF | _IOLBF | _IOFBF);
    stderr->_flag &= ~(_IONBF | _IOLBF | _IOFBF);
#else
#if defined( __NETWARE__ )
    stdout->_flag &= ~(_IONBF | _IOLBF | _IOFBF);
    stdout->_flag |= _IONBF;
#endif
    stderr->_flag &= ~(_IONBF | _IOLBF | _IOFBF);
    stderr->_flag |= _IONBF;
#endif
    for( fp = _RWD_iob; fp->_flag != 0; ++fp ) {
#ifdef _M_I86
        ptr = lib_nmalloc( sizeof( __stream_link ) );
        if( ptr != NULL ) {
            link = ptr;
        } else {
#endif
            link = lib_malloc( sizeof( __stream_link ) );
            if( link == NULL ) {
                __fatal_runtime_error( "Not enough memory to allocate file structures", 1 );
                // never return
            }
#ifdef _M_I86
        }
#endif
        link->stream = fp;
        link->next = _RWD_ostream;
        _RWD_ostream = link;
        fp->_link = link;
        fp->_link->_base = NULL;
        fp->_link->_tmpfchar = 0;
        fp->_link->_orientation = _NOT_ORIENTED;
    }
    _RWD_cstream = NULL;
}
Пример #2
0
int __F_NAME(__cenvarg,__wcenvarg)(
/*
 *  Build environment and command line for new process.  Length of environment
 *  (in bytes) is returned on success.  -1 is returned on failure.
 */
    const CHAR_TYPE     *const argv[],  /* i: arguments for new process */
    const CHAR_TYPE     *const envp[],  /* i: env strings for new process */
    CHAR_TYPE           **envptr,       /* o: allocated memory for env */
    CHAR_TYPE           **envstrings,   /* o: pointer to environment strings */
    unsigned            *envseg,        /* o: start of env (on para boundary) */
    size_t              *cmdline_len,   /* o: size required to hold cmd line */
    int                 exec )          /* i: TRUE if for exec */
{
    unsigned            length;
    unsigned            oamblksiz;
    CHAR_TYPE           *p;
    CHAR_TYPE _WCNEAR   *np;
    unsigned            len;
    int                 i;

    if( envp == NULL ){
#ifdef __WIDECHAR__
        if( _RWD_wenviron == NULL )
            __create_wide_environment();
#endif
        envp = (const CHAR_TYPE * const *)__F_NAME(_RWD_environ,_RWD_wenviron);
    }
    length = 0;
    if( envp != NULL ){
        for( i = 0; envp[i] != NULL; i++ ) {
            length += __F_NAME(strlen,wcslen)( envp[i] ) + 1;
        }
    }
    ++length; /* trailing \0 for env */
    if( exec ){
        /* store argv[0] at 2 bytes past end of env */
        length += 2 + __F_NAME(strlen,wcslen)( argv[0] ) + 1;
    }
    length += 15;       /* so we can start on a paragraph boundary */

    oamblksiz = _RWD_amblksiz;
    _RWD_amblksiz = 16; /* force allocation in 16 byte increments */
    p = np = lib_nmalloc( length*sizeof(CHAR_TYPE) );
    if( np == NULL ){   /* 03-aug-88 */
        p = lib_malloc( length*sizeof(CHAR_TYPE) );
        if( p == NULL ){
            __set_errno( ENOMEM );
            __set_doserrno( E_nomem );
            _RWD_amblksiz = oamblksiz;
            return( -1 );
        }
    }
    _RWD_amblksiz = oamblksiz;
    *envptr = p;
#if defined( _M_I86 ) && defined( __DOS__ )
  #if defined(__SMALL_DATA__)
    p = (char *) (((unsigned) p + 15) & 0xfff0);
  #else           /* large data models */         /* 12-aug-88 */
    p = MK_FP( FP_SEG(p), (( FP_OFF(p) + 15) & 0xfff0) );
  #endif
    {
        CHAR_TYPE _WCFAR *temp;

        temp = p;
        *envseg = FP_SEG( temp ) + FP_OFF( temp )/16;
    }
#else
    *envseg = 0;
#endif
    *envstrings = p;            /* save ptr to env strings. 07-oct-92 */
    if( envp != NULL ){
        for( i = 0; envp[i] != NULL; ++i ){
            p = stpcpy( p, envp[i] ) + 1;
        }
    }
    *p++ = '\0';
    if( exec ) {
        __F_NAME(strcpy,wcscpy)( p + 2, argv[0] );
    }

    len = 0;
    if( argv[0] != NULL ) {
        for( i = 1; argv[i] != NULL; ++i ){
            if( len != 0 ) ++len;       /* plus 1 for blank separator */
            len += __F_NAME(strlen,wcslen)( argv[i] );
        }
    }
#if defined( __NT__ )
    // we are going to add quotes around program name (argv[0])
    len += _MAX_PATH2 + 3;
#elif defined( __OS2__ )
    len += _MAX_PATH2 + 1;
#elif defined( __RDOS__ ) || defined( __RDOSDEV__ )
    len += _MAX_PATH2 + 1;
#else
    if( len > 126 ) {
        __set_errno( E2BIG );
        __set_doserrno( E_badenv );
        lib_free( *envptr );
        return( -1 );
    }
    len = _MAX_PATH;    /* always use _MAX_PATH chars for DOS */
#endif
    *cmdline_len = len;

    return( length / 16 );
}
Пример #3
0
int __F_NAME(__cenvarg,__wcenvarg)(
/*
 *  Build environment and command line for new process.  Length of environment
 *  (in bytes) is returned on success.  -1 is returned on failure.
 */
    const CHAR_TYPE     *const argv[],  /* i: arguments for new process */
    const CHAR_TYPE     *const envp[],  /* i: env strings for new process */
    CHAR_TYPE           **_envptr,      /* o: environment ptr (unaligned) */
    CHAR_TYPE           **envptr,       /* o: environment ptr (DOS 16-bit aligned to para) */
    unsigned            *envseg,        /* o: environment segment (DOS 16-bit normalized, zero for others) */
    size_t              *cmdline_len,   /* o: size required to hold cmd line */
    int                 exec )          /* i: TRUE if for exec */
{
    unsigned            length;         /* environment length in bytes */
    unsigned            old_amblksiz;
    CHAR_TYPE           *p;
    CHAR_TYPE _WCNEAR   *np;
    unsigned            len;            /* command line length in characters */
    int                 i;

#if !defined( __DOS_086__ )
    exec = exec;
#endif
    if( envp == NULL ) {
#ifdef __WIDECHAR__
        if( _RWD_wenviron == NULL )
            __create_wide_environment();
#endif
        envp = (const CHAR_TYPE * const *)__F_NAME(_RWD_environ,_RWD_wenviron);
    }
    length = 0;
    if( envp != NULL ) {
        for( i = 0; envp[i] != NULL; i++ ) {
            length += ( __F_NAME(strlen,wcslen)( envp[i] ) + 1 ) * sizeof( CHAR_TYPE );
        }
    }
    length += sizeof( CHAR_TYPE ); /* trailing \0 for env */
#if defined( __DOS_086__ )
    if( exec ) {
        /* store argv[0] at 2 bytes past end of env */
        length += 2;
        length += strlen( argv[0] ) + 1;
    }
#endif
    /* round environment length to para */
    length = __ROUND_UP_SIZE_PARA( length );
#if defined( __DOS_086__ )
    /* add space for pointer alignment */
    /* so we can start on a paragraph boundary even if memory pointer is not aligned to para */
    length += 15;
#endif
    /* allocate space for new environment */
    old_amblksiz = _RWD_amblksiz;
    _RWD_amblksiz = 16; /* force allocation in 16 byte increments */
    p = np = lib_nmalloc( length );
    if( np == NULL ) {
        p = lib_malloc( length );
        if( p == NULL ) {
            _RWD_errno = ENOMEM;
            _RWD_doserrno = E_nomem;
            _RWD_amblksiz = old_amblksiz;
            return( -1 );
        }
    }
    _RWD_amblksiz = old_amblksiz;
    *_envptr = p;
#if defined( __DOS_086__ )
    /* align DOS 16-bit environment pointer to para boundary */
  #if defined(__SMALL_DATA__)
    p = (char *)__ROUND_UP_SIZE_PARA( FP_OFF( p ) );
  #else     /* __LARGE_DATA__ */
    p = MK_FP( FP_SEG( p ), __ROUND_UP_SIZE_PARA( FP_OFF( p ) ) );
  #endif
    /* normalize DOS 16-bit aligned environment pointer to segment */
    *envseg = FP_SEG( p ) + __ROUND_DOWN_SIZE_TO_PARA( FP_OFF( p ) );
    /* correct environment length (subtract aditional pointer alignment space) */
    length -= 15;
#else
    *envseg = 0;
#endif
    *envptr = p;            /* save ptr to env strings. */
    if( envp != NULL ) {
        for( i = 0; envp[i] != NULL; ++i ) {
            p = stpcpy( p, envp[i] ) + 1;
        }
    }
    *p++ = NULLCHAR;
#if defined( __DOS_086__ )
    if( exec ) {
        *p++ = 1;
        *p++ = 0;
        strcpy( p, argv[0] );
    }
#endif
    len = 0;
    if( argv[0] != NULL ) {
        for( i = 1; argv[i] != NULL; ++i ) {
            if( len != 0 )
                ++len;       /* plus 1 for blank separator */
            len += __F_NAME(strlen,wcslen)( argv[i] );
        }
    }
#if defined( __NT__ )
    // we are going to add quotes around program name (argv[0])
    len += _MAX_PATH2 + 3;
#elif defined( __OS2__ )
    len += _MAX_PATH2 + 1;
#elif defined( __RDOS__ ) || defined( __RDOSDEV__ )
    len += _MAX_PATH2 + 1;
#else       /* __DOS__ */
    if( len > 126 ) {
        _RWD_errno = E2BIG;
        _RWD_doserrno = E_badenv;
        lib_free( *_envptr );
        return( -1 );
    }
    len = _MAX_PATH;    /* always use _MAX_PATH chars for DOS */
#endif
    *cmdline_len = len;

    /* convert environment length in bytes to length in para */
    return( __ROUND_DOWN_SIZE_TO_PARA( length ) );
}