All pastes #273352 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-09 20:49 UTC
rendered paste body
#include <stdlib.h>
#include <dos.h>
#include <errno.h>
#include <process.h>
#include <string.h>
#include <dir.h>
#include <io.h>
#include <limits.h>

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 ) );
}