Exemple #1
0
RET_T TouchFile( const char *name )
/****************************************/
{
    tiny_date_t     dt;
    tiny_time_t     tm;
    tiny_ftime_t    p_hms;
    tiny_fdate_t    p_ymd;
    tiny_ret_t      ret;

    ret = TinyOpen( name, TIO_WRITE );
    if( TINY_OK( ret ) ) {
        dt = TinyGetDate();
        p_ymd.year  = dt.year + (1900 - 1980);
        p_ymd.month = dt.month;
        p_ymd.day   = dt.day_of_month;

        tm = TinyGetTime();
        p_hms.hours   = tm.hour;
        p_hms.minutes = tm.minutes;
        p_hms.twosecs = tm.seconds / 2;

        TinySetFileStamp( TINY_INFO( ret ), p_hms, p_ymd );
        TinyClose( TINY_INFO( ret ) );
    } else {
        ret = TinyCreate( name, TIO_NORMAL );
        if( TINY_OK( ret ) ) {
            TinyClose( TINY_INFO( ret ) );
        } else {
            return( RET_ERROR );
        }
    }
    return( RET_SUCCESS );
}
Exemple #2
0
long FindFilePath( char *pgm, char *buffer, char *ext_list )
{
    const char  far *path;
    char        *p2;
    char        *p3;
    tiny_ret_t  rc;
    int         have_ext;
    int         have_path;

    have_ext = 0;
    have_path = 0;
    for( p3 = pgm, p2 = buffer; *p2 = *p3; ++p3, ++p2 ) {
        switch( *p3 ) {
        case '\\':
        case '/':
        case ':':
            have_path = 1;
            have_ext = 0;
            break;
        case '.':
            have_ext = 1;
            break;
        }
    }
    if( have_ext )
        ext_list = "";
    rc = TryPath( buffer, p2, ext_list );
    if( TINY_OK( rc ) || have_path )
        return( rc );
    path = DOSEnvFind( "PATH" );
    if( path == NULL )
        return( rc );
    for(;;) {
        if( *path == '\0' )
            break;
        p2 = buffer;
        while( *path ) {
            if( *path == ';' )
                break;
            *p2++ = *path++;
        }
        if( p2[-1] != '\\' && p2[-1] != '/' ) {
            *p2++ = '\\';
        }
        for( p3 = pgm; *p2 = *p3; ++p2, ++p3 )
            {}
        rc = TryPath( buffer, p2, ext_list );
        if( TINY_OK( rc ) )
            break;
        if( *path == '\0' )
            break;
        ++path;
    }
    return( rc );
}
Exemple #3
0
_WCRTLINK int __F_NAME(mkdir,_wmkdir)( const CHAR_TYPE *path )
/************************************************************/
{
#ifdef __WIDECHAR__
    size_t              rcConvert;
    char                mbcsPath[MB_CUR_MAX * _MAX_PATH];
    unsigned char       *p;

    /*** Convert the wide character string to a multibyte string ***/
    rcConvert = wcstombs( mbcsPath, path, sizeof( mbcsPath ) );
    p = _mbsninc( (unsigned char *)mbcsPath, rcConvert );
    *p = '\0';
    return( mkdir( mbcsPath ) );
#else
  #ifdef __WATCOM_LFN__
    tiny_ret_t  rc = 0;

    if( _RWD_uselfn && TINY_OK( rc = _mkdir_lfn( path ) ) ) {
        return( 0 );
    }
    if( IS_LFN_ERROR( rc ) ) {
        return( __set_errno_dos( TINY_INFO( rc ) ) );
    }
  #endif
    return( __mkdir_sfn( path ) );
#endif
}
Exemple #4
0
trap_retval ReqFile_string_to_fullpath( void )
{
    char                        *name;
    char                        *fullname;
    char                        *ext_list;
    file_string_to_fullpath_req *acc;
    file_string_to_fullpath_ret *ret;
    tiny_ret_t                  rc;

    acc = GetInPtr( 0 );
    name = GetInPtr( sizeof( *acc ) );
    ret = GetOutPtr( 0 );
    fullname = GetOutPtr( sizeof( *ret ) );
    if( acc->file_type == TF_TYPE_EXE ) {
        ext_list = GetExeExtensions();
    } else {
        ext_list = "";
    }
    rc = FindFilePath( name, fullname, ext_list );
    if( TINY_OK( rc ) ) {
        ret->err = 0;
    } else {
        ret->err = TINY_INFO( rc );
        *fullname = '\0';
    }
    return( sizeof( *ret ) + 1 + strlen( fullname ) );
}
Exemple #5
0
int __close( int handle )
{
    tiny_ret_t rc;
#ifdef DEFAULT_WINDOWING
    LPWDATA res;
#endif
    int     rv;

    __handle_check( handle, -1 );
    rv = 0;
    rc = TinyClose( handle );
    if( TINY_OK(rc) ) {
#ifdef DEFAULT_WINDOWING
        if( _WindowsCloseWindow != 0 ) {
            res = _WindowsIsWindowedHandle( handle );
            if( res != NULL ) {
                _WindowsRemoveWindowedHandle( handle );
                _WindowsCloseWindow( res );
            }
        }
#endif
    } else {
        __set_errno( EBADF );
        rv = -1;
    }
    __SetIOMode_nogrow( handle, 0 );
    return( rv );
}
Exemple #6
0
f_handle ExeCreate( char *name )
/*************************************/
{
    tiny_ret_t      h;

    h = DoOpen( name, TRUE, TIO_NORMAL );
    LastResult = TINY_INFO( h );
    if( TINY_OK( h ) ) return( TINY_INFO( h ) );
    return( NIL_HANDLE );
}
Exemple #7
0
static f_handle NSOpen( char *name, unsigned mode )
/*************************************************/
{
    tiny_ret_t       h;

    h = DoOpen( name, FALSE, mode );
    LastResult = TINY_INFO( h );
    if( TINY_OK( h ) ) return( TINY_INFO( h ) );
    return( NIL_HANDLE );
}
Exemple #8
0
f_handle QOpenRW( char *name )
/***********************************/
{
    tiny_ret_t h;

    h = DoOpen( name, TRUE, TIO_NORMAL );
    if( TINY_OK( h ) ) return( (f_handle)TINY_INFO( h ) );
    LnkMsg( FTL+MSG_CANT_OPEN, "12", name, QErrMsg( TINY_INFO( h ) ) );
    return( NIL_HANDLE );
}
Exemple #9
0
void QClose( f_handle file, char *name )
/*********************************************/
/* file close */
{
    tiny_ret_t h;

    CheckBreak();
    h = TinyClose( file );
    OpenFiles--;
    if( TINY_OK( h ) || name == NULL ) return;
    LnkMsg( ERR+MSG_IO_PROBLEM, "12", name, QErrMsg( TINY_INFO( h ) ) );
}
Exemple #10
0
bool XchkOpen( where_parm where, char *f_buff )
{
    tiny_ret_t      rc;

    fileHandle = TINY_HANDLE_NULL;
    if( f_buff != NULL ) {
        fullName = f_buff;
        *f_buff++ = TinyGetCurrDrive() + 'A';
        *f_buff++ = ':';
        *f_buff++ = '\\';
        rc = TinyFarGetCWDir( f_buff, 0 );
        if( TINY_OK( rc ) ) {
            while( *f_buff != 0 )
                ++f_buff;
            if( f_buff[-1] == '\\' ) {
                --f_buff;
            } else {
                *f_buff++ = '\\';
            }
            memcpy( f_buff, CHECK_FILE, sizeof( CHECK_FILE ) );
            rc = TinyCreate( fullName, TIO_NORMAL );
            if( TINY_OK( rc ) ) {
                fileHandle = TINY_INFO( rc );
            }
        }
        if( fileHandle == TINY_HANDLE_NULL ) {
            fullName = NULL;
        }
    } else {
        if( fullName != NULL ) {
            rc = TinyOpen( fullName, TIO_READ );
            if( TINY_OK( rc ) ) {
                fileHandle = TINY_INFO( rc );
            }
        }
    }
    return( fileHandle != TINY_HANDLE_NULL );
}
Exemple #11
0
static void *RationalAlloc( size_t size )
{
    dpmi_hdr        *dpmi;
    mheapptr        mhp;
    tiny_ret_t      save_DOS_block;
    tiny_ret_t      DOS_block;

    __FreeDPMIBlocks();
    /* size is a multiple of 4k */
    dpmi = TinyDPMIAlloc( size );
    if( dpmi != NULL ) {
        mhp = (mheapptr)( dpmi + 1 );
        mhp->len = size - sizeof( dpmi_hdr );
        dpmi->dos_seg_value = 0;        // indicate DPMI block
        return( (void *)mhp );
    }
    if( __minreal & 0xfff00000 ) {
        /* checks for users that want >1M real memory saved */
        __minreal = 0xfffff;
    }
    if( size > 0x00010000 ) {
        /* cannot allocate more than 64k from DOS real memory */
        return( NULL );
    }
    save_DOS_block = TinyAllocBlock( __ROUND_DOWN_SIZE_TO_PARA( __minreal ) | 1 );
    if( TINY_OK( save_DOS_block ) ) {
        DOS_block = TinyAllocBlock( __ROUND_DOWN_SIZE_TO_PARA( size ) );
        TinyFreeBlock( save_DOS_block );
        if( TINY_OK( DOS_block ) ) {
            dpmi = (dpmi_hdr *)TinyDPMIBase( DOS_block );
            dpmi->dos_seg_value = DOS_block;
            mhp = (mheapptr)( dpmi + 1 );
            mhp->len = size - sizeof( dpmi_hdr );
            return( (void *)mhp );
        }
    }
    return( NULL );
}
Exemple #12
0
static int os_write( int handle, const void *buffer, unsigned len, unsigned *amt )
/********************************************************************************/
{
#ifdef DEFAULT_WINDOWING
    LPWDATA     res;
#endif
#if defined(__NT__)
    HANDLE      h;
    int         rc;
#else
    tiny_ret_t  rc;
#endif

    rc = 0;
#ifdef DEFAULT_WINDOWING
    if( _WindowsStdout != 0 && (res = _WindowsIsWindowedHandle( handle )) != 0 ) {
        *amt = _WindowsStdout( res, buffer, len );
    } else
#endif
    {
#if defined(__NT__)
        h = __getOSHandle( handle );
        if( !WriteFile( h, (LPCVOID)buffer, (DWORD)len, (LPDWORD)amt, NULL ) ) {
            rc = __set_errno_nt();
        }
#elif defined(__OS2_286__)
        rc = DosWrite( handle, (PVOID)buffer, (USHORT)len, (PUSHORT)amt );
#elif defined(__OS2__)
        rc = DosWrite( handle, (PVOID)buffer, (ULONG)len, (PULONG)amt );
#else
        rc = TinyWrite( handle, buffer, len );
        *amt = TINY_LINFO( rc );
        if( TINY_OK( rc ) ) {
            rc = 0;
        }
#endif
    }
#if !defined(__NT__)
    if( TINY_ERROR( rc ) ) {
        rc = __set_errno_dos( TINY_INFO( rc ) );
    }
#endif
    if( *amt != len ) {
        rc = ENOSPC;
        __set_errno( rc );
    }
    return( rc );
}
Exemple #13
0
_WCRTLINK unsigned _dos_open( const char *path, unsigned mode, int *handle )
/**************************************************************************/
{
#ifdef __WATCOM_LFN__
    tiny_ret_t  rc = 0;

    if( _RWD_uselfn && TINY_OK( rc = __dos_open_lfn( path, mode ) ) ) {
        *handle = TINY_INFO( rc );
        return( 0 );
    }
    if( IS_LFN_ERROR( rc ) ) {
        return( __set_errno_dos_reterr( TINY_INFO( rc ) ) );
    }
#endif
    return( __dos_open_sfn_err( path, mode, handle ) );
}
Exemple #14
0
static const char *GetHelpName( const char *exe_name )
{
    /*
      if executable is:
          PE format, subsystem PE_SS_PL_DOSSTYLE (0x42) then PEDHELP.EXP
      or:
          PE format, other subsystems then PENHELP.EXP
      otherwise:
          PLSHELP.EXP
    */
    tiny_ret_t          rc;
    tiny_handle_t       handle;
    unsigned_32         off;
    union {
        dos_exe_header  dos;
        pe_header       pe;
    }   head;

    rc = TinyOpen( exe_name, 0 );
    if( TINY_OK( rc ) ) {
        handle = TINY_INFO( rc );
        TinyRead( handle, &head.dos, sizeof( head.dos ) );
        if( head.dos.signature != DOS_SIGNATURE ) {
            TinyClose( handle );
        } else {
            TinySeek( handle, OS2_NE_OFFSET, SEEK_SET );
            TinyRead( handle, &off, sizeof( off ) );
            TinySeek( handle, off, SEEK_SET );
            TinyRead( handle, &head.pe, sizeof( head.pe ) );
            TinyClose( handle );
            switch( head.pe.signature ) {
            case PE_SIGNATURE:
            case PL_SIGNATURE:
                if( head.pe.subsystem == PE_SS_PL_DOSSTYLE ) {
                    _DBG_Writeln( "Want PEDHELP" );
                    return( HELPNAME_DS );
                }
                _DBG_Writeln( "Want PENHELP" );
                return( HELPNAME_NS );
            }
        }
    }
    _DBG_Writeln( "Want PLSHELP" );
    return( HELPNAME );
}
Exemple #15
0
_WCRTLINK unsigned _dos_findclose( struct find_t *fdta )
/******************************************************/
{
#if defined( __WATCOM_LFN__ )
    tiny_ret_t      rc;

    if( IS_LFN( fdta ) ) {
        if( TINY_OK( rc = _dos_find_close_lfn( LFN_HANDLE_OF( fdta ) ) ) )
            return( 0 );
        return( __set_errno_dos_reterr( TINY_INFO( rc ) ) );
    }
#endif
#ifdef __OSI__
    return( __dos_find_close_dta( fdta ) );
#else
    return( 0 );
#endif
}
Exemple #16
0
_WCRTLINK unsigned _dos_findnext( struct find_t *fdta )
/*****************************************************/
{
#ifdef __WATCOM_LFN__
    lfnfind_t       lfndta;
    tiny_ret_t      rc;

    if( IS_LFN( fdta ) ) {
        rc = _dos_find_next_lfn( LFN_HANDLE_OF( fdta ), &lfndta );
        if( TINY_OK( rc ) ) {
            convert_to_find_t( fdta, &lfndta );
            return( 0 );
        }
        return( __set_errno_dos_reterr( TINY_INFO( rc ) ) );
    }
#endif
    return( __dos_find_next_dta( fdta ) );
}
Exemple #17
0
static tiny_ret_t TryPath( char *name, char *end, char *ext_list )
{
    tiny_ret_t  rc;
    char        *p;
    int         done;
    int         mode;

    done = 0;
    mode = 0 ; //IsDOS3 ? 0x40 : 0;
    do {
        if( *ext_list == '\0' ) done = 1;
        for( p = end; *p = *ext_list; ++p, ++ext_list )
            {}
        rc = TinyOpen( name, mode );
        if( TINY_OK( rc ) ) {
            TinyClose( TINY_INFO( rc ) );
            return( rc );
        }
        ++ext_list;
    } while( !done );
    return( rc );
}
Exemple #18
0
static tiny_ret_t DoOpen( char *name, bool create, unsigned mode )
/****************************************************************/
{
    tiny_ret_t       h;

    CheckBreak();
    for( ;; ) {
        if( OpenFiles >= MAX_OPEN_FILES ) CleanCachedHandles();
        if( create ) {
            h  = TinyCreate( name, mode );
        } else {
            h = TinyOpen( name, mode );
        }
        if( TINY_OK( h ) ) {
            OpenFiles++;
            break;
        }
        if( TINY_INFO( h ) != TOOMANY ) break;
        if( !CleanCachedHandles() ) break;
    }
    return( h );
}
Exemple #19
0
_WCRTLINK unsigned _dos_findfirst( const char *path, unsigned attrib,
                                                           struct find_t *fdta )
/******************************************************************************/
{
#ifdef __WATCOM_LFN__
    lfnfind_t       lfndta;
    tiny_ret_t      rc = 0;

    LFN_SIGN_OF( fdta )   = 0;
    LFN_HANDLE_OF( fdta ) = 0;
    if( _RWD_uselfn && TINY_OK( rc = _dos_find_first_lfn( path, attrib, &lfndta ) ) ) {
        convert_to_find_t( fdta, &lfndta );
        LFN_SIGN_OF( fdta )   = _LFN_SIGN;
        LFN_HANDLE_OF( fdta ) = TINY_INFO( rc );
        return( 0 );
    }
    if( IS_LFN_ERROR( rc ) ) {
        return( __set_errno_dos_reterr( TINY_INFO( rc ) ) );
    }
#endif
    return( __dos_find_first_dta( path, attrib, fdta ) );
}
Exemple #20
0
static char *SearchPath( const char __far *env, const char *file, char *buff, char **pendname )
{
    char        *endname;
    char        *name;
    tiny_ret_t  rc;
    char        save[20];
    unsigned    len;
    char        *ptr;

    if( env == NULL ) {
        CopyStr( ";", buff );
    } else {
        CopyStr( ";", CopyStr( env, CopyStr( ".;", buff ) ) );
    }
    name = buff;
    len = strlen( file );
    while( *name ) {
        endname = name;
        while( *endname != ';' )
            ++endname;
        memcpy( save, endname, len + 2 );
        ptr = endname;
        if( name != ptr && ptr[-1]!=':' && ptr[-1]!='/' && ptr[-1]!='\\' ) {
            *ptr++ = '\\';
        }
        memcpy( ptr, file, len + 1 );
        rc = TinyOpen( name, 0 );
        if( TINY_OK( rc ) ) {
            TinyClose( TINY_INFO( rc ) );
            break;
        }
        memcpy( endname, save, len + 2 );
        name = endname + 1;
    }
    *pendname = endname;
    return( name );
}
Exemple #21
0
_WCRTLINK int __F_NAME(unlink,_wunlink)( const CHAR_TYPE *filename )
/******************************************************************/
{
#ifdef __WIDECHAR__
    char    mbFilename[MB_CUR_MAX * _MAX_PATH]; /* single-byte char */

    if( wcstombs( mbFilename, filename, sizeof( mbFilename ) ) == -1 ) {
        mbFilename[0] = '\0';
    }
    return( unlink( mbFilename ) );
#else
  #ifdef __WATCOM_LFN__
    tiny_ret_t  rc = 0;

    if( _RWD_uselfn && TINY_OK( rc = _unlink_lfn( filename ) ) ) {
        return( 0 );
    }
    if( IS_LFN_ERROR( rc ) ) {
        return( __set_errno_dos( TINY_INFO( rc ) ) );
    }
  #endif
    return( __unlink_sfn( filename ) );
#endif
}
Exemple #22
0
unsigned ReqProg_load( void )
{
    char                buffer[160];
    char                *src;
    char                *dst;
    char                *name;
    char                *endparm;
    char                *err;
    tiny_ret_t          rc;
    prog_load_ret       *ret;
    unsigned_16         len;

    SaveVectors( OrigVectors );
    _DBG_EnterFunc( "AccLoadProg()" );
    ret = GetOutPtr( 0 );
    src = name = GetInPtr( sizeof( prog_load_req ) );
    rc = FindFilePath( src, buffer, DosXExtList );
    endparm = LinkParm;
    while( *endparm++ != '\0' ) {}      // skip program name
    strcpy( endparm, buffer );
    err = RemoteLink( LinkParm, 0 );
    if( err != NULL ) {
        _DBG_Writeln( "Can't RemoteLink" );
        TinyWrite( TINY_ERR, err, strlen( err ) );
        LoadError = err;
        ret->err = 1;
        len = 0;
    } else {
        if( TINY_OK( rc ) ) {
            while( *src++ != '\0' ) {}
            len = GetTotalSize() - ( src - name ) - sizeof( prog_load_req );
            dst = (char *)buffer;
            while( *dst++ != '\0' ) {};
            memcpy( dst, src, len );
            dst += len;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( sizeof( prog_load_req ), In_Mx_Ptr[0].ptr );
            _DBG_Writeln( "AddPacket" );
            AddPacket( dst - buffer, buffer );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            len = GetPacket();
            _DBG_Writeln( "RemovePacket" );
            RemovePacket( sizeof( *ret ), ret );
        } else {
            len = DoAccess();
        }
        _DBG_Writeln( "Linked --" );
        if( ret->err != 0 ) {
            get_err_text_req    erracc;
            prog_kill_req       killacc;
            int                 msg_len;

            _DBG_Writeln( "loadret->errcode != 0" );
            if( LoadError == NULL ) {
                _DBG_Writeln( "making a REQ_GET_ERR_TEXT request" );
                erracc.req = REQ_GET_ERR_TEXT;
                erracc.err = ret->err;
                _DBG_Writeln( "StartPacket" );
                StartPacket();
                _DBG_Writeln( "AddPacket" );
                AddPacket( sizeof( erracc ), &erracc );
                _DBG_Writeln( "PutPacket" );
                PutPacket();
                _DBG_Writeln( "GetPacket" );
                msg_len = GetPacket();
                _DBG_Writeln( "RemovePacket" );
                RemovePacket( msg_len, FailMsg );
                _DBG_Write( "FailMsg :  " );
                _DBG_NoTabWriteln( FailMsg );
                LoadError = FailMsg;
            }

            _DBG_Writeln( "making a REQ_PROG_KILL request" );
            killacc.req = REQ_PROG_KILL;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( sizeof( killacc ), &killacc );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            GetPacket();
            //RemovePacket( msg_len, &erracc );
            RemoteUnLink();

            TaskLoaded = FALSE;
        }
    }
    if( ret->err == 0 ) {
        _DBG_Writeln( "loadret->error_code == 0" );
        TaskLoaded = TRUE;
    }
    SaveVectors( LoadVectors );
    SaveVectors( CurrVectors );
    _DBG_ExitFunc( "AccLoadProg()" );
    return( len );
}
Exemple #23
0
_WCRTLINK int fstat( int handle, struct stat *buf )
{
    unsigned        iomode_flags;
    tiny_ret_t      rc;

    __handle_check( handle, -1 );

    rc = TinyGetDeviceInfo( handle );
    if( TINY_ERROR( rc ) ) {
        return( __set_errno_dos( TINY_INFO( rc ) ) );
    }
    /* isolate drive number */
    buf->st_dev = TINY_INFO( rc ) & TIO_CTL_DISK_DRIVE_MASK;
    buf->st_rdev = buf->st_dev;

    buf->st_nlink = 1;
    buf->st_uid = buf->st_gid = 0;
    buf->st_ino = handle;
    buf->st_mode = 0;
    iomode_flags = __GetIOMode( handle );
    if( iomode_flags & _READ ) {
        buf->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
    }
    if( iomode_flags & _WRITE ) {
        buf->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
    }
    if( TINY_INFO( rc ) & TIO_CTL_DEVICE ) {
        buf->st_size = 0;
        buf->st_atime = buf->st_ctime = buf->st_mtime = 0;
        buf->st_mode |= S_IFCHR;
    } else {                /* file */
#ifdef __WATCOM_LFN__
        lfninfo_t       lfni;

        rc = 0;
        if( _RWD_uselfn && TINY_OK( rc = _getfileinfo_lfn( handle, &lfni ) ) ) {
            buf->st_mtime = _cvt_stamp2ttime_lfn( &lfni.writetimestamp );
            if( lfni.creattimestamp ) {
                buf->st_ctime = _cvt_stamp2ttime_lfn( &lfni.creattimestamp );
            } else {
                buf->st_ctime = buf->st_mtime;
            }
            if( lfni.accesstimestamp ) {
                buf->st_atime = _cvt_stamp2ttime_lfn( &lfni.accesstimestamp );
            } else {
                buf->st_atime = buf->st_mtime;
            }
            buf->st_size = lfni.lfilesize;
            buf->st_attr = lfni.attributes;
        } else if( IS_LFN_ERROR( rc ) ) {
            return( __set_errno_dos( TINY_INFO( rc ) ) );
        } else {
#endif
            long    rc1;

            rc1 = __getfilestamp_sfn( handle );
            if( rc1 == -1 ) {
                return( -1 );
            }
            buf->st_mtime = _d2ttime( rc1 >> 16, rc1 );
            buf->st_atime = buf->st_mtime;
            buf->st_ctime = buf->st_mtime;
            buf->st_size = filelength( handle );
            buf->st_attr = 0;
#ifdef __WATCOM_LFN__
        }
#endif
        buf->st_mode |= S_IFREG;
    }
    buf->st_btime = buf->st_mtime;
    buf->st_archivedID = 0;
    buf->st_updatedID = 0;
    buf->st_inheritedRightsMask = 0;
    buf->st_originatingNameSpace = 0;
    return( 0 );
}
Exemple #24
0
trap_retval ReqProg_load( void )
{
    addr_seg        psp;
    pblock          parmblock;
    tiny_ret_t      rc;
    char            *parm;
    char            *name;
    char            __far *dst;
    char            exe_name[128];
    char            ch;
    EXE_TYPE        exe;
    prog_load_ret   *ret;
    unsigned        len;

    ExceptNum = -1;
    ret = GetOutPtr( 0 );
    memset( &TaskRegs, 0, sizeof( TaskRegs ) );
    TaskRegs.EFL = MyFlags() & ~USR_FLAGS;
    /* build a DOS command line parameter in our PSP command area */
    Flags.BoundApp = FALSE;
    psp = DbgPSP();
    parm = name = GetInPtr( sizeof( prog_load_req ) );
    if( TINY_ERROR( FindFilePath( name, exe_name, DosExtList ) ) ) {
        exe_name[0] = '\0';
    }
    while( *parm++ != '\0' ) {}     // skip program name
    len = GetTotalSize() - ( parm - name ) - sizeof( prog_load_req );
    if( len > 126 )
        len = 126;
    dst = MK_FP( psp, CMD_OFFSET + 1 );
    for( ; len > 0; --len ) {
        ch = *parm++;
        if( ch == '\0' ) {
            if( len == 1 )
                break;
            ch = ' ';
        }
        *dst++ = ch;
    }
    *dst = '\r';
    *(byte __far *)MK_FP( psp, CMD_OFFSET ) = FP_OFF( dst ) - ( CMD_OFFSET + 1 );
    parmblock.envstring = 0;
    parmblock.commandln.segment = psp;
    parmblock.commandln.offset =  CMD_OFFSET;
    parmblock.fcb01.segment = psp;
    parmblock.fcb02.segment = psp;
    parmblock.fcb01.offset  = 0x5C;
    parmblock.fcb02.offset  = 0x6C;
    exe = CheckEXEType( exe_name );
    if( EXEhandle != 0 ) {
        TinyClose( EXEhandle );
        EXEhandle = 0;
    }
    switch( exe ) {
    case EXE_RATIONAL_386:
        ret->err = ERR_RATIONAL_EXE;
        return( sizeof( *ret ) );
    case EXE_PHARLAP_SIMPLE:
        ret->err = ERR_PHARLAP_EXE;
        return( sizeof( *ret ) );
    }
    SegmentChain = 0;
    BoundAppLoading = FALSE;
    rc = DOSLoadProg( exe_name, &parmblock );
    if( TINY_OK( rc ) ) {
        TaskRegs.SS = parmblock.startsssp.segment;
        /* for some insane reason DOS returns a starting SP two less then
           normal */
        TaskRegs.ESP = parmblock.startsssp.offset + 2;
        TaskRegs.CS = parmblock.startcsip.segment;
        TaskRegs.EIP = parmblock.startcsip.offset;
        psp = DOSTaskPSP();
    } else {
        psp = TinyAllocBlock( TinyAllocBlock( 0xffff ) );
        TinyFreeBlock( psp );
        TaskRegs.SS = psp + 0x10;
        TaskRegs.ESP = 0xfffe;
        TaskRegs.CS = psp + 0x10;
        TaskRegs.EIP = 0x100;
    }
    TaskRegs.DS = psp;
    TaskRegs.ES = psp;
    if( TINY_OK( rc ) ) {
        if( Flags.NoOvlMgr || !CheckOvl( parmblock.startcsip ) ) {
            if( exe == EXE_OS2 ) {
                opcode_type __far *loc_brk_opcode;

                BoundAppLoading = TRUE;
                RunProg( &TaskRegs, &TaskRegs );
                loc_brk_opcode = MK_FP(TaskRegs.CS, TaskRegs.EIP);
                if( *loc_brk_opcode == BRKPOINT ) {
                    *loc_brk_opcode = saved_opcode;
                }
                BoundAppLoading = FALSE;
                rc = TinyOpen( exe_name, TIO_READ_WRITE );
                if( TINY_OK( rc ) ) {
                    EXEhandle = TINY_INFO( rc );
                    SeekEXEset( StartByte );
                    WriteEXE( saved_opcode );
                    TinySetFileStamp( EXEhandle, EXETime, EXEDate );
                    TinyClose( EXEhandle );
                    EXEhandle = 0;
                    Flags.BoundApp = TRUE;
                }
            }
        }
    }
    ret->err = TINY_ERROR( rc ) ? TINY_INFO( rc ) : 0;
    ret->task_id = psp;
    ret->flags = 0;
    ret->mod_handle = 0;
    return( sizeof( *ret ) );
}
Exemple #25
0
trap_retval ReqProg_load( void )
{
    char                buffer[160];
    char                *src;
    char                *dst;
    char                *name;
    char                *endparm;
    const char          *err;
    tiny_ret_t          rc;
    prog_load_ret       *ret;
    trap_elen           len;

    SaveVectors( OrigVectors );
    _DBG_EnterFunc( "AccLoadProg()" );
    ret = GetOutPtr( 0 );
    src = name = GetInPtr( sizeof( prog_load_req ) );
    rc = FindProgFile( src, buffer, DosExtList );
    endparm = LinkParms;
    while( *endparm++ != '\0' ) {}      // skip trap parameters
    strcpy( endparm, buffer );          // add command line
    // result is as follow
    // "trap parameters string"+"\0"+"command line string"+"\0"
    err = RemoteLink( LinkParms, false );
    if( err != NULL ) {
        _DBG_Writeln( "Can't RemoteLink" );
        TinyWrite( TINY_ERR, err, strlen( err ) );
        LoadError = err;
        ret->err = 1;
        len = 0;
    } else {
        if( TINY_OK( rc ) ) {
            while( *src++ != '\0' ) {}
            len = GetTotalSize() - ( src - name ) - sizeof( prog_load_req );
            dst = (char *)buffer;
            while( *dst++ != '\0' ) {};
            memcpy( dst, src, len );
            dst += len;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( In_Mx_Ptr[0].ptr, sizeof( prog_load_req ) );
            _DBG_Writeln( "AddPacket" );
            AddPacket( buffer, dst - buffer );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            len = GetPacket();
            _DBG_Writeln( "RemovePacket" );
            RemovePacket( ret, sizeof( *ret ) );
        } else {
            len = DoAccess();
        }
        _DBG_Writeln( "Linked --" );
        if( ret->err != 0 ) {
            get_err_text_req    erracc;
            prog_kill_req       killacc;
            trap_elen           msg_len;

            _DBG_Writeln( "loadret->errcode != 0" );
            if( LoadError == NULL ) {
                _DBG_Writeln( "making a REQ_GET_ERR_TEXT request" );
                erracc.req = REQ_GET_ERR_TEXT;
                erracc.err = ret->err;
                _DBG_Writeln( "StartPacket" );
                StartPacket();
                _DBG_Writeln( "AddPacket" );
                AddPacket( &erracc, sizeof( erracc ) );
                _DBG_Writeln( "PutPacket" );
                PutPacket();
                _DBG_Writeln( "GetPacket" );
                msg_len = GetPacket();
                _DBG_Writeln( "RemovePacket" );
                RemovePacket( FailMsg, msg_len );
                _DBG_Write( "FailMsg :  " );
                _DBG_NoTabWriteln( FailMsg );
                LoadError = FailMsg;
            }

            _DBG_Writeln( "making a REQ_PROG_KILL request" );
            killacc.req = REQ_PROG_KILL;
            _DBG_Writeln( "StartPacket" );
            StartPacket();
            _DBG_Writeln( "AddPacket" );
            AddPacket( &killacc, sizeof( killacc ) );
            _DBG_Writeln( "PutPacket" );
            PutPacket();
            _DBG_Writeln( "GetPacket" );
            GetPacket();
            //RemovePacket( &erracc, msg_len );
            RemoteUnLink();

            TaskLoaded = false;
        }
    }
    if( ret->err == 0 ) {
        _DBG_Writeln( "loadret->error_code == 0" );
        TaskLoaded = true;
    }
    SaveVectors( LoadVectors );
    SaveVectors( CurrVectors );
    _DBG_ExitFunc( "AccLoadProg()" );
    return( len );
}