Exemplo n.º 1
0
static int open_base( const CHAR_TYPE *name, int mode )
{
    int                 handle;
    rdos_handle_type   *obj;
    int                 rdos_handle;
    int                 rwmode;
    unsigned            iomode_flags;

    rwmode = mode & OPENMODE_ACCESS_MASK;
    iomode_flags = 0;
    if( mode == O_RDWR )                iomode_flags |= _READ | _WRITE;
    if( rwmode == O_RDONLY)             iomode_flags |= _READ;
    if( rwmode == O_WRONLY)             iomode_flags |= _WRITE;
    if( mode & O_APPEND )               iomode_flags |= _APPEND;
    if( mode & (O_BINARY|O_TEXT) )
        if( mode & O_BINARY )           iomode_flags |= _BINARY;

    if( !strcmp( name, CONSOLE ) ) {
        if( mode & O_CREAT )
            obj = console_out;
        else
            obj = console_in;
        obj->ref_count++;
        handle = AllocHandleEntry( obj );
        return( handle );
    }
    else {
        if( mode & O_CREAT ) {
            if( mode & O_EXCL ) {
                rdos_handle = RdosOpenFile( name, 0 );
                if( rdos_handle ) {
                    RdosCloseFile( rdos_handle );
                    return( -1 );
                }
            }
            rdos_handle = RdosCreateFile( name, 0 );    
        }
        else
            rdos_handle = RdosOpenFile( name, 0 );    

        if( rdos_handle )
            if( mode & O_TRUNC )
                RdosSetFileSize( rdos_handle, 0 );
    
        if( rdos_handle ) {
            obj = AllocHandleObj( name );
            if( obj ) {
                obj->rdos_handle = rdos_handle;
                obj->mode = iomode_flags;
                obj->type = HANDLE_TYPE_FILE;
                handle = AllocHandleEntry( obj );
                return( handle );
            }
        }
    }
    return( -1 );
}
Exemplo n.º 2
0
static void ProcessFile( char *filename, int handle, unsigned mode )
{
    rdos_handle_type *obj;
    int rdos_handle;
    int org_handle;
    
    rdos_handle = RdosOpenFile( filename, 0 );

    if( rdos_handle ) {
        obj = AllocHandleObj( filename );
    }

    if( obj ) {
        obj->rdos_handle = rdos_handle;
        obj->mode = mode;
        obj->type = HANDLE_TYPE_FILE;
        org_handle = AllocHandleEntry( obj );
        dup2( org_handle, handle );
        close( org_handle );
    }
}
Exemplo n.º 3
0
int _dospawn( int mode, CHAR_TYPE *pgmname, CHAR_TYPE *cmdline,
                                  CHAR_TYPE *envpar, 
                                  const CHAR_TYPE * const argv[] )
{
    int tid;
    int handle;
    int wait;
    int rc = -1;
    int fh;
    int len;
    char *p;
    char *drive;
    char *dir;
    char *fname;
    char *ext;
    char *envdata;
    char *envp;
    char *ep;
    char *options;
    int ok;

    options = __CreateInheritString();

    __F_NAME(__ccmdline,__wccmdline)( pgmname, argv, cmdline, 0 );

    ok = 0;

    len = strlen( pgmname ) + 7 + _MAX_PATH2;
    p = lib_malloc( len );

    _splitpath2( pgmname, p + (len-_MAX_PATH2),
                 &drive, &dir, &fname, &ext );

    _makepath( p, drive, dir, fname, ext );
    fh = RdosOpenFile( p, 0 );
    if( fh == 0 ) {
        if( strlen( drive ) == 0 && strlen( dir ) == 0 ) {
            envdata = getenv( "PATH" );
            if( envdata ) {
                envp = envdata;
                while( envp && !ok) {
                    ep = strchr( envp, ';' );
                    if( ep ) {
                        *ep = 0;
                        ep++;
                    }
                    _makepath( p, "", envp, fname, ext );
                    fh = RdosOpenFile( pgmname, 0 );
                    if( fh ) {
                        ok = 1;
                        RdosCloseFile( fh );
                    }
                    envp = ep;
                }                
            }
        }
    } else {
        RdosCloseFile( fh );    
        ok = 1;
    }

    if( ok ) {
        handle = RdosSpawn( pgmname, cmdline, 0, envpar, options, &tid );

        if( !handle )
            ok = 0;
    }

    if( ok ) {
        if( mode == P_WAIT ) {
            wait = RdosCreateWait();
            RdosAddWaitForProcessEnd( wait, handle, 0 );
            RdosWaitForever( wait );
            rc = RdosGetProcessExitCode( handle );
            RdosCloseWait( wait );
        } 
        else
            rc = tid;
            
        RdosFreeProcessHandle( handle );                        
    }

    lib_free( options );
    lib_free( p );

    return( rc );
}
Exemplo n.º 4
0
int _doexec( CHAR_TYPE *pgmname, CHAR_TYPE *cmdline,
              const CHAR_TYPE * const argv[] )
{
    char *options;
    int len;
    char *p;
    int ok;
    char *fname;
    char *ext;
    char *envdata;
    char *envp;
    char *ep;
    int rc = -1;
    int fh;
    char *drive;
    char *dir;

    options = __CreateInheritString();

    __F_NAME(__ccmdline,__wccmdline)( pgmname, argv, cmdline, 0 );

    ok = 0;

    len = strlen( pgmname ) + 7 + _MAX_PATH2;
    p = lib_malloc( len );

    _splitpath2( pgmname, p + (len-_MAX_PATH2),
                 &drive, &dir, &fname, &ext );

    _makepath( p, drive, dir, fname, ext );
    fh = RdosOpenFile( p, 0 );
    if( fh == 0 ) {
        if( strlen( drive ) == 0 && strlen( dir ) == 0 ) {
            envdata = getenv( "PATH" );
            if( envdata ) {
                envp = envdata;
                while( envp && !ok) {
                    ep = strchr( envp, ';' );
                    if( ep ) {
                        *ep = 0;
                        ep++;
                    }
                    _makepath( p, "", envp, fname, ext );
                    fh = RdosOpenFile( pgmname, 0 );
                    if( fh ) {
                        ok = 1;
                        RdosCloseFile( fh );
                    }
                    envp = ep;
                }                
            }
        }
    } else {
        RdosCloseFile( fh );    
        ok = 1;
    }

    if( ok )
        rc = RdosExec( pgmname, cmdline, options );

    lib_free( options );
    lib_free( p );

    return( rc );
}