Exemplo n.º 1
0
VOID TimeIt()
{
    TIMESTAMP   tsStart, tsStop;
    ULONG       ulRC, ulMsecs, ulNsecs, ulBytes;

    printf( "\nHit Ctrl-C to terminate this test program...\n" );
    for( ; ; )
    {
        printf( "\nSleeping for %u milliseconds...", ulTimePeriod );
        fflush( stdout );
        ulRC = DosRead( hfTimer, &tsStart, sizeof( TIMESTAMP ), &ulBytes );
        if( ulRC )
        {
            printf( "\nDosRead for start got a retcode of %u", ulRC );
            return;
        }
        DosSleep( ulTimePeriod );
        ulRC = DosRead( hfTimer, &tsStop, sizeof( TIMESTAMP ), &ulBytes );
        if( ulRC )
        {
            printf( "\nDosRead for stop got a retcode of %u", ulRC );
            return;
        }
        ulMsecs = CalcElapsedTime( &tsStart, &tsStop,
                                   ulOverheadMs, ulOverheadNs, &ulNsecs );
        printf( " elapsed time (ms:ns) = %06u:%06u", ulMsecs, ulNsecs );
    }
}
Exemplo n.º 2
0
BOOL ReadData( HFILE handle )
   {
   BOOL   ret = FALSE;
   char * p1;
   int    dif;
   char   crc[2];
   ULONG  bytesread;
   ULONG  actual;

   DosRead( handle, tmpbuf, BUFSIZE, &bytesread );

   if ( bytesread )
      {
      if (p1=memchr( tmpbuf, EOFFLAG, bytesread ) )
         {
         dif        = bytesread - (int)(p1-tmpbuf);
         bytesread -= dif;
         if (dif < 3)
            {
            DosRead( handle, crc+dif, 3-dif, &bytesread );
            if (dif==1)
               crc[0] = *(p1+1);
            rc = *(unsigned int *)crc;
            }
         else
            rc = *(unsigned int *)(p1+1);

         ret = TRUE;
         } /* endif */

      DosWrite( 1, tmpbuf, bytesread, &actual );
      }

   return( ret );
   }
Exemplo n.º 3
0
int main(void)
{
    APIRET apiret;
    HPIPE hpipe;
    PSZ pipeName = "\\pipe\\testpipe";
    PSZ semName = "\\sem32\\pipesem";
    HEV hev;
    CHAR objname[50];
    RESULTCODES rc;
    ULONG bytesread;
    CHAR buf[50];

    printf(__FILE__ " main function invoked\n");
    printf("Test named pipe functions\n");

    apiret = DosCreateNPipe(pipeName, &hpipe, 0, NP_WAIT, 0, 0, 0);
    printf("DosCreateNPipe function returned %d\n", (int)apiret);

    apiret = DosCreateEventSem(semName, &hev, DC_SEM_SHARED, FALSE);
    printf("DosCreateEventSem function returned %d\n", (int)apiret);

    apiret = DosExecPgm(objname, 50, EXEC_ASYNC, NULL, NULL, &rc, "./test11a");
    printf("DosExecPgm function returned %d\n", (int)apiret);

    apiret = DosWaitEventSem(hev, 5000);
    printf("DosWaitEventSem function returned %d\n", (int)apiret);

    apiret = DosRead((HFILE)hpipe, buf, sizeof(buf) - 1, &bytesread);
    printf("DosRead function returned %d\n", (int)apiret);
    buf[bytesread] = '\0';
    printf("Message was \"%s\"\n", buf);

    apiret = DosWaitEventSem(hev, 5000);
    printf("DosWaitEventSem function returned %d\n", (int)apiret);

    apiret = DosRead((HFILE)hpipe, buf, sizeof(buf) - 1, &bytesread);
    printf("DosRead function returned %d\n", (int)apiret);
    buf[bytesread] = '\0';
    printf("Message was \"%s\"\n", buf);

    apiret = DosWaitEventSem(hev, 5000);
    printf("DosWaitEventSem function returned %d\n", (int)apiret);

    apiret = DosRead((HFILE)hpipe, buf, sizeof(buf) - 1, &bytesread);
    printf("DosRead function returned %d\n", (int)apiret);
    buf[bytesread] = '\0';
    printf("Message was \"%s\"\n", buf);

    /* wait for test11a to catch up with us */
    DosSleep(2000);

    apiret = DosCloseEventSem(hev);
    printf("DosCloseEventSem function returned %d\n", (int)apiret);

    apiret = DosClose((HFILE)hpipe);
    printf("DosClose function returned %d\n", (int)apiret);

    return 0;
}
Exemplo n.º 4
0
int SERIAL_getextchar(COMPORT port) {
	ULONG dwRead = 0;	// Number of chars read
	char chRead;

	int retval = 0;
	// receive a byte; TODO communicate failure
	if (DosRead(port->porthandle, &chRead, 1, &dwRead) == NO_ERROR) {
		if (dwRead) {
			// check for errors; will OS/2 clear the error on reading its data?
			// if yes then this is in wrong order
			USHORT errors = 0, event = 0;
			ULONG ulParmLen = sizeof(errors);
			DosDevIOCtl(port->porthandle, IOCTL_ASYNC, ASYNC_GETCOMMEVENT,
				0, 0, 0, &event, ulParmLen, &ulParmLen);
			if (event & (64 + 128) ) { // Break (Bit 6) or Frame or Parity (Bit 7) error
				Bit8u errreg = 0;
				if (event & 64) retval |= SERIAL_BREAK_ERR;
				if (event & 128) {
					DosDevIOCtl(port->porthandle, IOCTL_ASYNC, ASYNC_GETCOMMERROR,
						0, 0, 0, &errors, ulParmLen, &ulParmLen);
					if (errors & 8) retval |= SERIAL_FRAMING_ERR;
					if (errors & 4) retval |= SERIAL_PARITY_ERR;
				}
			}
			retval |= (chRead & 0xff);
			retval |= 0x10000; 
		}
	}
	return retval;
}
Exemplo n.º 5
0
VOID APIENTRY Thread(VOID)
{
   APIRET rc;
   ULONG ulNumBytes;
   TRACE_EVENT te;

   printf("Thread() started\n");
   rc = DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
   if (rc) {
      printf("Thread() DosSetPriority failed with RC = %lu\n", rc);
      return;
   }

   fRunning = TRUE;
   while (!fQuit) {
      rc = DosRead(hfile, &te, sizeof(TRACE_EVENT), &ulNumBytes);
      if (rc) {
         printf("Error %d while calling device driver\n", rc);
         return;
      }
      ShowTrace(te);
   }

   printf("Thread() stopped\n");
   fRunning = FALSE;
}
Exemplo n.º 6
0
/****************************************************************************
REMARKS:
VDD implementation of the ANSI C fread function. Note that unlike Windows VxDs,
OS/2 VDDs are not limited to 64K reads or writes.
****************************************************************************/
size_t fread(
    void *ptr,
    size_t size,
    size_t n,
    FILE *f)
{
    char    *buf = ptr;
    int     bytes,readbytes,totalbytes = 0;

    /* First copy any data already read into our buffer */
    if ((bytes = (f->curp - f->startp)) > 0) {
	memcpy(buf,f->curp,bytes);
	f->startp = f->curp = f->buf;
	buf += bytes;
	totalbytes += bytes;
	bytes = (size * n) - bytes;
	}
    else
	bytes = size * n;
    if (bytes) {
	#ifdef __OS2_VDD__
	readbytes = VDHRead((HFILE)f->handle, buf, bytes);
	#else
	DosRead((HFILE)f->handle, buf, bytes, &readbytes);
	#endif
	totalbytes += readbytes;
	f->offset += readbytes;
	}
    return totalbytes / size;
}
Exemplo n.º 7
0
static VOID APIENTRY ServiceRequests( VOID )
{
    USHORT              len;
    pmhelp_packet       data;

    WinCreateMsgQueue( Hab, 0 );
    for( ;; ) {
        if( DosRead( InStream, &data, sizeof( data ), &len ) != 0 ) break;
        if( len != sizeof( data ) ) break;
        switch( data.command ) {
        case PMHELP_LOCK:
            PidDebugee = data.pid;
            TidDebugee = data.tid;
            LockIt();
            break;
        case PMHELP_UNLOCK:
            PidDebugee = data.pid;
            TidDebugee = data.tid;
            UnLockIt();
            break;
        case PMHELP_EXIT:
            WinPostMsg( hwndClient, WM_QUIT, 0, 0 );/* Cause termination*/
            break;
        }
        WinInvalidateRegion( hwndClient, 0L, FALSE );
    }
    Say( "Read Failed" );
}
Exemplo n.º 8
0
void _System Reader(ULONG arg)
{
    int        data;
    ULONG      read;
    int        new_index;
    APIRET     rc;

    OverRun = FALSE;
    for( ;; ) {
        rc = DosRead( ComPort, &data, 1, &read );
        if( rc != NO_ERROR )
            break;
        if( read == 1 ) {
            new_index = ReadBuffAdd + 1;
            new_index &= BSIZE-1;
            if( new_index == ReadBuffRemove ) {
                OverRun = TRUE;
            } else {
                ReadBuff[ ReadBuffAdd ] = data;
                ReadBuffAdd = new_index;
            }
            DosPostEventSem( ReadSemaphore );
        }
    }
}
Exemplo n.º 9
0
char far *InitAlias( char far * inname )
/**************************************/
{
    USHORT hdl,read;
    static char b[80];
    char *bp;
    unsigned long ppos,pos;
    USHORT action;
    char far *endname;
    static char noalias = 0;

    endname = inname;
    while( *endname == ' ' ) ++endname;
    for( ;; ) {
        if( *endname == '\0' ) {
            break;
        }
        if( *endname == ' ' ) {
            *endname = '\0';
            ++endname;
            break;
        }
        ++endname;
    }
    bp = b;
    while( *bp = *inname ) {
        ++bp;
        ++inname;
    }
    action=action;
    if( DosOpen( b, &hdl, &action, 0L, 0, 1, 0x10 ,0L ) == 0 ) {
        DosChgFilePtr( hdl, 0L, 2, &ppos );
        pos = ppos;
        DosChgFilePtr( hdl, 0L, 0, &ppos );
#ifdef DOS
        {
            static int alias_seg;
            DosAllocSeg( pos + 1 + ALIAS_SLACK, &alias_seg, 0 );
            *(((int far *)&AliasList)+0) = 0;
            *(((int far *)&AliasList)+1) = alias_seg;
            AliasSize = pos + ALIAS_SLACK;
        }
#else
        AliasList = AliasArea;
        AliasSize = 2047;
#endif
        DosRead( hdl, AliasList, pos, &read );
        if( pos > 0 && AliasList[ pos-1 ] != '\n' ) {
            AliasList[ pos+0 ] = '\r';
            AliasList[ pos+1 ] = '\n';
            AliasList[ pos+2 ] = '\0';
        } else {
            AliasList[ pos ] = '\0';
        }
        DosClose( hdl );
    } else {
        AliasList = &noalias;
    }
    return( endname );
}
Exemplo n.º 10
0
/*
** Read data from a file into a buffer.  Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/
static int os2Read(
  sqlite3_file *id,               /* File to read from */
  void *pBuf,                     /* Write content into this buffer */
  int amt,                        /* Number of bytes to read */
  sqlite3_int64 offset            /* Begin reading at this offset */
){
  ULONG fileLocation = 0L;
  ULONG got;
  os2File *pFile = (os2File*)id;
  assert( id!=0 );
  SimulateIOError( return SQLITE_IOERR_READ );
  OSTRACE3( "READ %d lock=%d\n", pFile->h, pFile->locktype );
  if( DosSetFilePtr(pFile->h, offset, FILE_BEGIN, &fileLocation) != NO_ERROR ){
    return SQLITE_IOERR;
  }
  if( DosRead( pFile->h, pBuf, amt, &got ) != NO_ERROR ){
    return SQLITE_IOERR_READ;
  }
  if( got == (ULONG)amt )
    return SQLITE_OK;
  else {
    /* Unread portions of the input buffer must be zero-filled */
    memset(&((char*)pBuf)[got], 0, amt-got);
    return SQLITE_IOERR_SHORT_READ;
  }
}
Exemplo n.º 11
0
size_t read_func(void *ptr, size_t size, size_t nmemb, void *datasource)
{
    ULONG ulActual;

    DosRead( (HFILE)datasource, ptr, (size*nmemb), &ulActual );
    return ulActual / size;
}
Exemplo n.º 12
0
static int
TRANS(Os2Read)(XtransConnInfo ciptr, char *buf, int size)
{
    int ret;
    APIRET rc;
    ULONG ulRead;
    PRMSG(2,"Os2Read(%d,%x,%d)\n", ciptr->fd, buf, size );
    errno = 0;
    rc = DosRead(ciptr->fd, buf, size, &ulRead);
    if (rc == 0){
        ret = ulRead;
        }
    else if ((rc == 232) || (rc == 231)){
        errno = EAGAIN;
        ret = -1;
        }
    else if (rc == 6){
        errno = EBADF;
        ret = -1;
        }
     else if ((rc == 109) || (rc == 230) || (rc == 233)){
        errno = EPIPE;
       ret = -1;
        }
    else {
           PRMSG(2,"Os2Read: Unknown return code from DosRead, fd %d rc=%d\n", ciptr->fd,rc,0 );
           errno = EINVAL;
           ret = -1;
           }
    return (ret);
}
Exemplo n.º 13
0
/*
 * get the address of Dos32Debug, and get the flat selectors, too.
 */
int GetDos32Debug( char __far *err )
{
    char        buff[256];
    RESULTCODES resc;
    USHORT      dummy;
    PSZ         start;
    PSZ         p;
    HFILE       inh;
    HFILE       outh;
    USHORT      rc;
    struct {
        ULONG       dos_debug;
        USHORT      cs;
        USHORT      ds;
        USHORT      ss;
    }           data;

    rc = DosGetModName( ThisDLLModHandle, sizeof( buff ), buff );
    if( rc ) {
        StrCopy( TRP_OS2_no_dll, err );
        return( FALSE );
    }
    start = buff;
    for( p = buff; *p != '\0'; ++p ) {
        switch( *p ) {
        case ':':
        case '\\':
        case '/':
           start = p + 1;
           break;
        }
    }
    p = StrCopy( LOCATOR, start );
    if( DosMakePipe( &inh, &outh, sizeof( data ) ) ) {
        StrCopy( TRP_OS2_no_pipe, err );
        return( FALSE );
    }
    *++p = outh + '0';
    *++p = '\0';
    *++p = '\0';
    rc = DosExecPgm( NULL, 0, EXEC_ASYNC, buff, NULL, &resc, buff );
    DosClose( outh );
    if( rc )  {
        DosClose( inh );
        StrCopy( TRP_OS2_no_help, err );
        return( FALSE );
    }
    rc = DosRead( inh, &data, sizeof( data ), &dummy );
    DosClose( inh );
    if( rc ) {
        StrCopy( TRP_OS2_no_help, err );
        return( FALSE );
    }
    DebugFunc = (void __far *)data.dos_debug;
    FlatCS = (USHORT) data.cs;
    FlatDS = (USHORT) data.ds;

    _retaddr = MakeLocalPtrFlat( (void __far *)DoReturn );
    return( TRUE );
}
Exemplo n.º 14
0
static void init( void )
{
    ULONG     rc;
    ULONG     action;
    ULONG     bytes;

    rc = DosOpen( "WTIMER$", &timerHandle, &action, 0,
                   FILE_NORMAL, FILE_OPEN, OPEN_SHARE_DENYNONE, NULL );
    if( rc == 0 ) {
        DosRead( timerHandle, &startTime, sizeof( TIMESTAMP ), &bytes );
        DosRead( timerHandle, &stopTime, sizeof( TIMESTAMP ), &bytes );
        calc_time( &overHead, &startTime, &stopTime, NULL );
        DosRead( timerHandle, &startTime, sizeof( TIMESTAMP ), &bytes );
    } else {
        printf( "Could not open WTIMER$\n" );
    }
}
Exemplo n.º 15
0
int myread( int handle, char *buff, int len )
{
    APIRET      rc;
    ULONG       bytes_read;

    rc = DosRead( handle, buff, len, &bytes_read );
    if( rc != 0 ) return( 0 );
    return( bytes_read );
}
Exemplo n.º 16
0
char __far *InitAlias( char __far * inname )
/******************************************/
{
    USHORT          hdl,read;
    static char     b[80];
    char            *bp;
    unsigned long   ppos,pos;
    USHORT          action;
    char            __far *endname;
    static char     noalias = 0;
#ifndef DOS
    static char     AliasArea[2048]; /* The DLL seems to need static memory */
#endif

    endname = inname;
    while( *endname == ' ' )
        ++endname;
    for( ; *endname != '\0'; endname++ ) {
        if( *endname == ' ' ) {
            *endname++ = '\0';
            break;
        }
    }
    for( bp = b; (*bp = *inname) != '\0'; bp++ ) {
        ++inname;
    }
    action=action;
    if( DosOpen( b, &hdl, &action, 0L, 0, 1, 0x10 ,0L ) == 0 ) {
        DosChgFilePtr( hdl, 0L, 2, &ppos );
        pos = ppos;
        DosChgFilePtr( hdl, 0L, 0, &ppos );
#ifdef DOS
        {
            static int alias_seg;

            DosAllocSeg( pos + 1 + ALIAS_SLACK, &alias_seg, 0 );
            AliasList = (char __far *)MK_FP( alias_seg, 0 );
            AliasSize = pos + ALIAS_SLACK;
        }
#else
        AliasList = AliasArea;
        AliasSize = 2047;
#endif
        DosRead( hdl, AliasList, pos, &read );
        if( pos > 0 && AliasList[pos - 1] != '\n' ) {
            AliasList[pos + 0] = '\r';
            AliasList[pos + 1] = '\n';
            AliasList[pos + 2] = '\0';
        } else {
            AliasList[pos] = '\0';
        }
        DosClose( hdl );
    } else {
        AliasList = &noalias;
    }
    return( endname );
}
VOID CheckSystemConfig( VOID )
{
 // Проверяем настройки в файле "Config.sys".
 CHAR File_name[ SIZE_OF_NAME ] = "*:\\Config.sys"; ULONG Boot_drive = 0;
 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PULONG) &Boot_drive, sizeof( Boot_drive ) );
 File_name[ 0 ] = (CHAR) Boot_drive + 64;

 ULONG Action = OPEN_ACTION_OPEN_IF_EXISTS;
 ULONG Mode = OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY;

 HFILE File = NULLHANDLE; ULONG Report = 0;
 APIRET RC = DosOpen( File_name, &File, &Report, 0, FILE_NORMAL, Action, Mode, NULL );

 // Если файл был открыт:
 if( RC == NO_ERROR )
  {
   // Отводим память для текста.
   PCHAR Text = NULL; ULONG Length = 65536;
   if( DosAllocMem( (PPVOID) &Text, Length, PAG_ALLOCATE ) != NO_ERROR )
    {
     DosClose( File );
     DosExit( EXIT_PROCESS, 0 );
    }

   // Читаем настройки.
   memset( Text, 0, Length );
   DosRead( File, Text, Length, &Length );

   // Проверяем, есть ли в настройках путь к каталогу расширителя.
   BYTE Path_is_present = 1; if( !stristr( "NICE\\ENHANCER", Text ) ) Path_is_present = 0;

   // Освобождаем память.
   DosFreeMem( Text ); Text = NULL;

   // Закрываем файл.
   DosClose( File ); File = NULLHANDLE;

   // Если настройки заданы неправильно:
   if( !Path_is_present )
    {
     // Показываем сообщение.
     CHAR Title[ SIZE_OF_TITLE ] = ""; GetEnhancerWindowTitle( Title );

     if( QuerySystemCodePage() == RUSSIAN )
      WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, StrConst_RU_No_path_in_Config_sys, Title, NULLHANDLE, NULLHANDLE );
     else
      WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, StrConst_EN_No_path_in_Config_sys, Title, NULLHANDLE, NULLHANDLE );

     // Выход.
     DosExit( EXIT_PROCESS, 0 );
    }
  }

 // Возврат.
 return;
}
Exemplo n.º 18
0
char *ReadPipe(int iPipe)
{
    APIRET rc;
    ULONG ulTotal     = 0;
    ULONG ulBytesRead = 0;
    Chunk* pHead = new Chunk;
    Chunk* pCurr = pHead;

    do
    {
        ulBytesRead = 0;

        rc = DosRead(0, pCurr->data, sizeof(pCurr->data), &ulBytesRead);

        pCurr->sz = ulBytesRead;
        ulTotal += ulBytesRead;

        if(ulBytesRead)
        {
            pCurr->next = new Chunk;
            pCurr       = pCurr->next;
        }
    }
    while(!rc && ulBytesRead);

    char *str = 0;

    if(ulTotal)
    {
        str = new char[ulTotal+1];

        char *ptr = str;

        for(pCurr = pHead; pCurr; pCurr = pCurr->next)
        {
            if(!pCurr->sz)
                continue;

            memcpy(ptr, pCurr->data, pCurr->sz);
            ptr += pCurr->sz;
        }
        *ptr = 0;
    }

    //Free memory

    for(pCurr = pHead; pCurr; )
    {
        Chunk* pTmp  = pCurr;
        pCurr = pCurr->next;

        delete pTmp;
    }

    return str;
}
Exemplo n.º 19
0
/* --------------------------------------------------------------------------
 Read 'cb' bytes from the file 'hf' into the buffer 'pBuffer'.
 Display an error message in case of error.
- Parameters -------------------------------------------------------------
 HFILE hf      : file handle.
 PVOID pBuffer : read buffer.
 ULONG cb      : count of bytes to be read.
- Return value -----------------------------------------------------------
 LONG : count of succesfully read bytes (-1 in case of error).
-------------------------------------------------------------------------- */
LONG fmRead(HFILE hf, PVOID pBuffer, ULONG cb) {
   ULONG cbRead;

   g.rc = DosRead(hf, pBuffer, cb, &cbRead);
   if (g.mode & FSJVERBOSE)
      printMsg(IROW_DEBUG, SZ_FREAD, hf, cb, cbRead, g.rc);
   if (g.rc)
      return handleFileIOError(-1, SZERR_READFILE, "", g.rc);

   return cbRead;
}
Exemplo n.º 20
0
COUNT csysOpen(void)
{	COUNT fd;
	struct nlsCSys_fileHeader header;

	if((fd = DosOpen((BYTE FAR*)filename, 0)) < 0) {
		printf("Cannot open: \"%s\"\n", filename);
		return 1;
	}

	if(DosRead(fd, &header, sizeof(header)) != sizeof(header);
	 || strcmp(header.csys_idstring, CSYS_FD_IDSTRING) != 0
Exemplo n.º 21
0
// read bitmap color palette
BOOL GBMReadPalette( HFILE hFile, GBM *gbm, GBMRGB *gbmrgb )
{
    BMP_PRIV *bmp_priv = ( BMP_PRIV * )gbm->priv;
    ULONG ulActual;

    if( gbm->bpp != 24 )
    {
        int i;
        BYTE b[4];

        if( bmp_priv->windows )             // OS/2 2.0 and Windows 3.0
        {
            DosSetFilePtr(  hFile,                                  // set to beginning of palette
                            bmp_priv->base + 14L + bmp_priv->cbFix,
                            FILE_BEGIN,
                            &ulActual );

            for( i = 0; i < ( int )bmp_priv->cclrUsed; i++ )        // read colors
            {
                DosRead( hFile, b, 4, &ulActual );                  // colors are in file as bgr
                ( gbmrgb + i )->Blue    = *b;
                ( gbmrgb + i )->Green   = *( b + 1 );
                ( gbmrgb + i )->Red     = *( b + 2 );
            }
        }
        else                                                        // OS/2 1.1 and 1.2
        {
            DosSetFilePtr( hFile, bmp_priv->base + 26L, FILE_BEGIN, &ulActual );  // set to palette start

            for( i = 0; i < ( 1 << gbm->bpp ); i++ )                            // read colors
            {
                DosRead( hFile, b, 3, &ulActual );                  // colors are in file as bgr
                ( gbmrgb + i )->Blue    = *b;
                ( gbmrgb + i )->Green   = *( b + 1 );
                ( gbmrgb + i )->Red     = *( b + 2 );
            }
        }
    }

    return( TRUE );
}
Exemplo n.º 22
0
int ReadConfigFile(HWND hwnd, char szFileSpec[],char **ppBuffer)
  {
  ULONG ulStatus;
  HFILE hFile;
  FILESTATUS3 stFileInfo;
  int iCount;
  char szMessage[CCHMAXPATH];
  APIRET rc;

  if ((rc = DosOpen(szFileSpec,&hFile,&ulStatus,0L,0,1,0x0022,(PEAOP2)0L)) != 0)
    {
    if (hwnd != NULLHANDLE)
      {
      sprintf(szMessage,"Could not open %s - Error = %u",szFileSpec,rc);
      MessageBox(HWND_DESKTOP,szMessage);
      }
    return(0);
    }
  DosQueryFileInfo(hFile,1,&stFileInfo,sizeof(FILESTATUS3));
  iCount = stFileInfo.cbFile;
  if ((rc = DosAllocMem((PVOID)ppBuffer,(iCount + 10),(PAG_COMMIT | PAG_READ | PAG_WRITE))) != NO_ERROR)
    {
    if (hwnd != NULLHANDLE)
      {
      sprintf(szMessage,"Unable to Allocate memory to read %s - %u",szFileSpec,rc);
      MessageBox(HWND_DESKTOP,szMessage);
      }
    iCount = 0;
    }
  if (DosRead(hFile,(PVOID)*ppBuffer,iCount,(ULONG *)&iCount) != 0)
    {
    DosFreeMem(*ppBuffer);
    iCount = 0;
    }
  else
    {
    /*
    ** ignore/remove EOF character, if present
    */
    if ((*ppBuffer)[(iCount) - 1] == '\x1a')
      iCount--;
    /*
    **  Add LF and CR to end of file, if not already there
    */
    if ((*ppBuffer)[iCount - 1] != '\x0a')
      {
      (*ppBuffer)[(iCount)++] = '\x0d';
      (*ppBuffer)[(iCount)++] = '\x0a';
      }
    }
  DosClose(hFile);
  return(iCount);
  }
Exemplo n.º 23
0
static void fini( TIMESTAMP *time )
{
    ULONG     rc;
    ULONG     bytes;

    DosRead( timerHandle, &stopTime, sizeof( TIMESTAMP ), &bytes );
    calc_time( time, &startTime, &stopTime, &overHead );
    rc = DosClose( timerHandle );
    if( rc != 0 ) {
        printf( "Could not close WTIMER$\n" );
    }
}
Exemplo n.º 24
0
unsigned LocalRead( sys_handle filehndl, void *ptr, unsigned len )
{
    USHORT      read;
    USHORT      ret;

    ret = DosRead( filehndl, ptr, len, &read );
    if( ret != 0 ) {
        StashErrCode( ret, OP_LOCAL );
        return( ERR_RETURN );
    }
    return( read );
}
Exemplo n.º 25
0
int read(int fd, void *buffer, unsigned int count)
{
  APIRET   rc;
  ULONG    actual;

  rc= DosRead( fd, (PVOID) buffer, count, &actual);

  if (!rc)
    return( actual);				/* NO_ERROR */
  _OS2errno( rc);				/* set errno */
  return(-1);					/* read failed */
}
Exemplo n.º 26
0
static VOID pipeClose( HPIPE hpipe )
{
#if 0
    USHORT usIndex;
    ULONG  cbActual;

    // wait acknowledgement
    DosRead( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
#endif

    DosClose( hpipe );
}
Exemplo n.º 27
0
unsigned LocalRead(sys_handle filehndl, void *ptr, unsigned len)
{
    ULONG       read;
    APIRET      ret;

    ret = DosRead(filehndl, ptr, len, &read);
    if (ret != 0) {
        StashErrCode(ret, OP_LOCAL);
        return ERR_RETURN;
    }
    return read;
}
Exemplo n.º 28
0
INT multiRead(CHAR *inFile, INT datS, INT sizeF, INT recNum)
{
struct Samp
   {
   SHORT indx;
   CHAR noteName[NAMESIZE];
   }sample;
ULONG oneRecSize, start;
APIRET apiret;
ULONG ulAction, ulBufferSize, ulBytesRead, newP;
HFILE hfile;

ulBufferSize = sizeF;
apiret = DosOpen(inFile,
		 &hfile,
		 &ulAction,
		 ulBufferSize,
		 FILE_NORMAL,
		 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
		 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE | OPEN_FLAGS_SEQUENTIAL,
		 NULL);
oneRecSize = sizeof(sample) + sizeF;
start = sizeof(recIndex);
DosSetFilePtr(hfile, start+(oneRecSize*(recNum)), FILE_BEGIN, &newP);
DosRead (hfile, &sample, sizeof(sample), &ulBytesRead);
if( datS == 1 )
   {
   DosRead (hfile, &dataRecs.noteText, sizeF, &ulBytesRead);
   dataRecs.indx = sample.indx;
   strcpy(dataRecs.noteName, sample.noteName);
   }
else
   {
   DosRead (hfile, &dataR.noteText, sizeF, &ulBytesRead);
   dataR.indx = sample.indx;
   strcpy(dataR.noteName, sample.noteName);
   }
DosClose(hfile);
return(1);
}
Exemplo n.º 29
0
ULONG       FileReadFile( HFILE hFile, char * pBuf, ULONG cbRequest, char * path)

{
    ULONG   rc;
    ULONG   ul;
    ULONG   ulRtn;

do {
    ulRtn = 0;
    rc = DosRead( hFile, pBuf, cbRequest, &ulRtn);
    if (!rc && ulRtn == cbRequest)
        break;

    printf( "FileReadFile - first attempt - rc= 0x%lx  request= 0x%lx  read= 0x%lx\n   file= %s\n",
            rc, cbRequest, ulRtn, path);

    DosSleep( 100);

    rc = DosSetFilePtr( hFile, -(ulRtn), FILE_CURRENT, &ul);
    if (rc) {
        printf( "FileReadFile - DosSetFilePtr - rc= 0x%lx\n", rc);
        ulRtn = 0;
        break;
    }

    ulRtn = 0;
    rc = DosRead( hFile, pBuf, cbRequest, &ulRtn);
    if (!rc && ulRtn == cbRequest)
        break;

    printf( "FileReadFile - second attempt - rc= 0x%lx  request= 0x%lx  read= 0x%lx\n",
            rc, cbRequest, ulRtn);

    ulRtn = 0;

} while (0);

    return (ulRtn);

}
Exemplo n.º 30
0
int __qread( int handle, void *buffer, unsigned len )
{
#if defined( __NT__ )
    DWORD           amount_read;
#elif defined(__OS2__)
    OS_UINT         amount_read;
    APIRET          rc;
#else
    unsigned        amount_read;
    tiny_ret_t      rc;
#endif

    __handle_check( handle, -1 );
#ifdef DEFAULT_WINDOWING
    if( _WindowsStdin != NULL ) {
        LPWDATA res;

        res = _WindowsIsWindowedHandle( handle );
        if( res ) {
            int rt;
            rt = _WindowsStdin( res, buffer, len );
            return( rt );
        }
    }
#endif
#if defined(__NT__)
    if( !ReadFile( __getOSHandle( handle ), buffer, len, &amount_read, NULL ) ) {
        DWORD       err;
        err = GetLastError();
        __set_errno_dos( err );
        if( err != ERROR_BROKEN_PIPE || amount_read != 0 ) {
            return( -1 );
        }
    }
#elif defined(__OS2__)
    rc = DosRead( handle, buffer, len, &amount_read );
    if( rc ) {
        return( __set_errno_dos( rc ) );
    }
#else
  #if defined( __WINDOWS_386__ )
    rc = __TinyRead( handle, buffer, len );
  #else
    rc = TinyRead( handle, buffer, len );
  #endif
    if( TINY_ERROR( rc ) ) {
        return( __set_errno_dos( TINY_INFO( rc ) ) );
    }
    amount_read = TINY_LINFO( rc );
#endif
    return( amount_read );
}