#include #include #include #include #include #include #include #include static const char __exe[] = ".EXE"; static const char __com[] = ".COM"; static const char __bat[] = ".BAT"; int spawnvp( int mode, const char *path, char **argv ) { char *fullpath = malloc( PATH_MAX ), *f, *p; strcpy( fullpath, path ); f = strrchr( fullpath, '\\' ); if( f == NULL ) f = fullpath; while( *f != '.' && *f ) f++; if( strcmp( f, __com ) == 0 || strcmp( f, __exe ) == 0 || strcmp( f, __bat ) == 0 ) { p = searchpath( fullpath ); if( p == NULL ){ free( fullpath ); return( -1 ); } goto end; } printf( "Got here 1\n" ); strcpy( f, __com ); if( ( p = searchpath( fullpath ) ) != NULL ) goto end; printf( "Got here 2\n" ); strcpy( f, __exe ); if( ( p = searchpath( fullpath ) ) != NULL ) goto end; printf( "Got here 3\n" ); strcpy( f, __bat ); if( ( p = searchpath( fullpath ) ) == NULL ) { free( fullpath ); return( -1 ); } end: free( fullpath ); return( spawnv( mode, p, argv ) ); }