示例#1
0
static void *_allocate( unsigned amount )

{

    void *p;



#if defined(__386__)

    p = malloc( amount );

#else

    p = _nmalloc( amount );

#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)

    if( (void near *) p == NULL )  p = malloc( amount );

#endif

#endif

    if( p == NULL )  _Not_Enough_Memory();

    return( p );

}
示例#2
0
static int _make_argv( char *p, char ***argv )

{

    int			argc;

    char		*start;

    char		*new_arg;

    char		wildcard;

    char		lastchar;

    DIR *		dir;

    struct dirent	*dirent;

    char		drive[_MAX_DRIVE];

    char		directory[_MAX_DIR];

    char		name[_MAX_FNAME];

    char		extin[_MAX_EXT];

    char		pathin[_MAX_PATH];



    argc = 1;

    for(;;) {

	while( *p == ' ' ) ++p;	/* skip over blanks */

	if( *p == '\0' ) break;

	/* we are at the start of a parm */

	wildcard = 0;

	if( *p == '\"' ) {

	    p++;

	    new_arg = start = p;

	    for(;;) {

		/* end of parm: NULLCHAR or quote */

		if( *p == '\"' ) break;

		if( *p == '\0' ) break;

		if( *p == '\\' ) {

		    if( p[1] == '\"'  ||  p[1] == '\\' )  ++p;

		}

		*new_arg++ = *p++;

	    }

	} else {

	    new_arg = start = p;

	    for(;;) {

		/* end of parm: NULLCHAR or blank */

		if( *p == '\0' ) break;

		if( *p == ' ' ) break;

		if(( *p == '\\' )&&( p[1] == '\"' )) {

		    ++p;

		} else if( *p == '?'  ||  *p == '*' ) {

		    wildcard = 1;

		}

		*new_arg++ = *p++;

	    }

	}

	*argv = (char **) realloc( *argv, (argc+2) * sizeof( char * ) );

	if( *argv == NULL )  _Not_Enough_Memory();

	(*argv)[ argc ] = start;

	++argc;

	lastchar = *p;

	*new_arg = '\0';

	++p;

	if( wildcard ) {

	    /* expand file names */

	    dir = opendir( start );

	    if( dir != NULL ) {

		--argc;

		_splitpath( start, drive, directory, name, extin );

		for(;;) {

		    dirent = readdir( dir );

		    if( dirent == NULL ) break;

		    if( dirent->d_attr &

		      (_A_HIDDEN+_A_SYSTEM+_A_VOLID+_A_SUBDIR) ) continue;

		    _splitpath( dirent->d_name, NULL, NULL, name, extin );

		    _makepath( pathin, drive, directory, name, extin );

		    *argv = (char **) realloc( *argv, (argc+2) * sizeof( char * ) );

		    if( *argv == NULL )  _Not_Enough_Memory();

		    new_arg = (char *) _allocate( strlen( pathin ) + 1 );

		    strcpy( new_arg, pathin );

		    (*argv)[argc++] = new_arg;

		}

		closedir( dir );

	    }

	}

	if( lastchar == '\0' ) break;

    }

    return( argc );

}
示例#3
0
static void SetupArgs( struct _proc_spawn *cmd )
{
    register char *cp, **cpp, *mp, **argv;
    register int argc, envc, i;

    /*
     * Set up argv[] and count argc.
     */
    argc = cmd->argc + 1;
    /* The argc + 1 provides for a NULL pointer at end */
    argv = cpp = (char **) malloc( (argc + 1) * sizeof( char * ) );
    if( argv == NULL ) _Not_Enough_Memory();

    cp = cmd->data;
    for( i = argc; i != 0; --i ) {
    *cpp++ = cp;
    while( *cp++ )
        ;
    }
    *cpp = NULL;
    if( *cp == '\0' ) ++cp;

    /*
     * Set up envp and *environ.
     */

    envc = cmd->envc;

    environ = cpp = (char **) malloc( (envc + 1) * sizeof(char *) +
                    envc * sizeof(char) );
    if( environ == NULL ) _Not_Enough_Memory();
    __env_mask = mp = (char *) &cpp[ envc + 1 ];
    for( i = envc ; i != 0 ; --i ) {
    *mp++ = 0;  /* indicate environment string not alloc'd */
    *cpp++ = cp;
    while( *cp++ )
        ;
    }
    --cpp;                                      /* Back up to the __CWD     */
    if ( !strncmp( "__CWD=", *cpp, 6 ) ) {      /* Did spawn pass __CWD ?   */
        /*
        Copy the cwd passed in an envar into magic and remove it from the
        environment. For old programs, also check the Q_CWD envar.
        The +6 skips over the __CWD=
        */
        if ( (__MAGIC.sptrs[3] = (char __FAR *) strdup( *cpp+6) ) == NULL )
            _Not_Enough_Memory();
        }
    else {
        ++cpp;      /* __CWD not passed, point to normal end of environment */
        }
    *cpp = NULL;    /* Null terminate the environment                       */

    --cpp;                                      /* Back up to the __PFX     */
    if ( !strncmp( "__PFX=", *cpp, 6 ) ) {      /* Did spawn pass __PFX ?   */
        /*
        Copy the pfx passed in an envar into magic and remove it from the
        environment. The +6 skips over the __PFX=
        */
        if ( (__MAGIC.sptrs[4] = (char __FAR *) strdup( *cpp+6) ) == NULL )
            _Not_Enough_Memory();
        }
    else {
        ++cpp;      /* __PFX not passed, point to normal end of environment */
        }
    *cpp = NULL;    /* Null terminate the environment                       */
    _argc = argc - 1;
    _argv = &argv[1];
}