Ejemplo n.º 1
0
static ULONG vioShowBuf( USHORT usIndex, PVOID pargs )
{
    PVIOSHOWBUFPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioShowBuf, p->usOfs, p->usLen, p->hvio );

    if( m_LVBPtr )
    {
        USHORT  usStart = p->usOfs & -2;
        USHORT  usEnd = ( p->usOfs + p->usLen + 1 ) & -2;
        USHORT  usLen;

        if( usEnd > m_LVBLen )
            usEnd = m_LVBLen;

        usLen = usEnd - usStart;

        pipeOpen( &hpipe );

        DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
        DosWrite( hpipe, &usStart, sizeof( USHORT ), &cbActual );
        DosWrite( hpipe, &usLen, sizeof( USHORT ), &cbActual );
        DosWrite( hpipe, m_LVBPtr + usStart, usLen, &cbActual );

        pipeClose( hpipe );
    }

    return 0;
}
// Title и String - строки, которые надо записать.
VOID Krnl_Debug_Log( PCHAR Title, PCHAR String )
{
 // Если файла нет - создаем его.
 HFILE File = NULLHANDLE; ULONG Report = 0; ULONG New_size = 0; PEAOP2 EAs = NULL;

 ULONG Action = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
 ULONG Mode = OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_WRITEONLY;

 CHAR Log_file_name[ SIZE_OF_PATH ] = "";
 GetCurrentPath( Log_file_name ); strcat( Log_file_name, "\\_log.txt" );

 DosOpen( Log_file_name, &File, &Report, New_size, FILE_COMMON_ATTRIBUTES, Action, Mode, EAs );

 // Записываем строку.
 if( Report != FILE_CREATED )
  {
   DosSetFilePtr( File, 0, FILE_END, &Report );
   DosWrite( File, "\n", strlen( "\n" ), &Report );
  }

 if( Title[ 0 ] != 0 )
  {
   DosWrite( File, Title, strlen( Title ), &Report );
   DosWrite( File, ": ", strlen( ": " ), &Report );
  }

 DosWrite( File, String, strlen( String ), &Report );

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

 // Возврат.
 return;
}
void main(void) {
  APIRET rc; PVOID myhighmem; ULONG cbWritten;
  rc = DosWrite(HF_STDOUT,"Hello World!\r\n",14,&cbWritten);
  rc = DosAllocMem(&myhighmem, 1024*1024*1024, PAG_READ|PAG_WRITE | OBJ_ANY );  // allocate 1GB of HMA(obj_any) rw-able 
  if(rc==0) { rc = DosWrite(HF_STDOUT,"allocation ok.!\r\n",17,&cbWritten);
    rc = DosFreeMem(myhighmem);
  }
  DosExit(EXIT_PROCESS,rc);
}
Ejemplo n.º 4
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 );
}
Ejemplo n.º 5
0
void SendByte( int value )
{
    USHORT      written = 0;

    DosWrite( ComPort, (BYTE *)&value, 1, &written );
    if( !BlockTransmission ) WaitTransmit();
}
Ejemplo n.º 6
0
PRInt32
_PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
{
    PRInt32 bytes;
    int rv; 

    rv = DosWrite((HFILE)fd->secret->md.osfd,
                  (PVOID)buf,
                  len,
                  (PULONG)&bytes);

    if (rv != NO_ERROR) 
    {
        _PR_MD_MAP_WRITE_ERROR(rv);
        return -1;
    }

    if (len != bytes) {
        rv = ERROR_DISK_FULL;
        _PR_MD_MAP_WRITE_ERROR(rv);
        return -1;
    }

    return bytes;
} /* --- end _PR_MD_WRITE() --- */
Ejemplo n.º 7
0
/* Write the contents of buf into record # blkno, for the block file
 * identified by blkhandle.  Blocks are numbered starting at 0.  The
 * requested block may be past the end of the file, in which case
 * this function is expected to extend the file.
 */
void 
blkwrite (BLK    *buf,    /* buffer, holds contents of block */
          _BLKNO_  blkno) /* where to write it */
{
  LONG offset;
  ULONG actual;

#ifdef FEATURE_RAM
  /* store it in RAM */
  if (nblks > 0)
  {
    if (blkno >= nblks)
    {
      blklist = (BLK **)realloc(blklist,
            (nblks + 1024) * sizeof(BLK *));
      memset(&blklist[nblks], 0, 1024 * sizeof(BLK *));
      nblks += 1024;
    }
    if (!blklist[blkno])
      blklist[blkno] = malloc(o_blksize);
    memcpy(blklist[blkno], buf, o_blksize);
    return;
  }
#endif

  /* write the block */
  offset = (LONG)blkno * (LONG)o_blksize;
  if (DosSetFilePtr (fd, offset, FILE_BEGIN, &actual) != NO_ERROR
    || DosWrite (fd, buf, o_blksize, &actual) != NO_ERROR
    || actual != o_blksize)
  {
    msg (MSG_FATAL, "blkwrite(%d) failed", blkno);
  } /* if */
}
Ejemplo n.º 8
0
bool SERIAL_sendchar(COMPORT port, char data) {
	ULONG bytesWritten = 0;

	APIRET rc = DosWrite(port->porthandle, &data, 1, &bytesWritten);
	if (rc == NO_ERROR && bytesWritten > 0) return true;
	else return false;
}
Ejemplo n.º 9
0
Archivo: specific.c Proyecto: etix/vlc
/**
 * Cleans up after system_Init() and system_Configure().
 */
void system_End(void)
{
    if( tidIPCFirst == _gettid())
    {
        HPIPE hpipe;
        ULONG ulAction;
        ULONG cbActual;
        ULONG rc;

        do
        {
            rc = DosOpen( VLC_IPC_PIPE, &hpipe, &ulAction, 0, 0,
                          OPEN_ACTION_OPEN_IF_EXISTS,
                          OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE |
                          OPEN_FLAGS_FAIL_ON_ERROR,
                          NULL );

            if( rc == ERROR_PIPE_BUSY )
                DosWaitNPipe( VLC_IPC_PIPE, -1 );
            else if( rc )
                DosSleep( 1 );
        } while( rc );

        /* Ask for IPCHelper to quit */
        ULONG ulCmd = IPC_CMD_QUIT;
        DosWrite( hpipe, &ulCmd, sizeof( ulCmd ), &cbActual );

        DosClose( hpipe );

        TID tid = tidIPCHelper;
        DosWaitThread( &tid, DCWW_WAIT );
    }
}
Ejemplo n.º 10
0
static int
TRANS(Os2Write)(XtransConnInfo ciptr, char *buf, int size)
{
    int ret;
    APIRET rc;
    ULONG nWritten;
    PRMSG(2,"Os2Write(%d,%x,%d)\n", ciptr->fd, buf, size );
    rc = DosWrite(ciptr->fd, buf, size, &nWritten);
    if (rc == 0){
         ret = nWritten;
         if(nWritten == 0) {
                 errno=EAGAIN;
                 ret = -1;
                 }
         }
    else if ((rc == 39) || (rc == 112)){
        errno = EAGAIN;
        ret = -1;
        }
    else if ((rc == 109) || (rc == 230) || (rc == 233)){
        errno = EPIPE;
        ret = -1;
        }
    else if (rc == 6){
         errno=EBADF;
         ret = -1;
         }
    else {
        PRMSG(2,"(Os2Write)Unknown return code from DosWrite, fd %d rc=%d\n", ciptr->fd,rc,0 );
        errno = EINVAL;
        ret = -1;
        }
    return (ret);
}
Ejemplo n.º 11
0
void main()
{
    USHORT rc, Action;
    HFILE FileHandle;

    DosSetSigHandler(BrkHandler, NULL, NULL, SIGA_ACCEPT, SIG_CTRLC);
    DosSetSigHandler(BrkHandler, NULL, NULL, SIGA_ACCEPT, SIG_KILLPROCESS);
    DosSetSigHandler(BrkHandler, NULL, NULL, SIGA_ACCEPT, SIG_CTRLBREAK);

    DosSetPrty(PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0);

    rc = DosOpen("Idlehlt$", &FileHandle, &Action, 0L,
                 FILE_NORMAL, FILE_OPEN, OPEN_SHARE_DENYNONE, 0L);

    if(!rc) {
        while(!ExitWhile)
            DosDevIOCtl(NULL, NULL, 0x01, 0x91, FileHandle);
        DosClose(FileHandle);
    } else {
        char buf[6], Message[36] = "HLT Driver not installed? rc=";
        char *src = buf, *dst = &Message[29];
        int len;

        utoa(rc, buf, 10);
        while(*dst++ = *src++);
        len = dst - Message;
        Message[len-1] = '\r';
        Message[len] = '\n';

        DosWrite(STDERR_FILENO, Message, len+1, &Action);
    }
}
Ejemplo n.º 12
0
static void SwitchBack( void )
{
    USHORT      written;

    static pmhelp_packet data = { PMHELP_SWITCHBACK };
    DosWrite( OutStream, &data, sizeof( data ), &written );
}
Ejemplo n.º 13
0
/****************************************************************************
REMARKS:
VDD implementation of the ANSI C fwrite function.
****************************************************************************/
size_t fwrite(
    void *ptr,
    size_t size,
    size_t n,
    FILE *f)
{
    char        *buf = ptr;
    int         bytes,writtenbytes,totalbytes = 0;

    /* Flush anything already in the buffer */
    if (!f->writemode)
	return 0;
    fflush(f);
    bytes = size * n;
    #ifdef __OS2_VDD__
    writtenbytes = VDHWrite((HFILE)f->handle, buf, bytes);
    #else
    DosWrite((HFILE)f->handle, buf, bytes, &writtenbytes);
    #endif
    totalbytes += writtenbytes;
    f->offset += writtenbytes;
    if (f->offset > f->filesize)
	f->filesize = f->offset;
    return totalbytes / size;
}
Ejemplo n.º 14
0
/*
** Write data from a buffer into a file.  Return SQLITE_OK on success
** or some other error code on failure.
*/
static int os2Write(
  sqlite3_file *id,               /* File to write into */
  const void *pBuf,               /* The bytes to be written */
  int amt,                        /* Number of bytes to write */
  sqlite3_int64 offset            /* Offset into the file to begin writing at */
){
  ULONG fileLocation = 0L;
  APIRET rc = NO_ERROR;
  ULONG wrote;
  os2File *pFile = (os2File*)id;
  assert( id!=0 );
  SimulateIOError( return SQLITE_IOERR_WRITE );
  SimulateDiskfullError( return SQLITE_FULL );
  OSTRACE3( "WRITE %d lock=%d\n", pFile->h, pFile->locktype );
  if( DosSetFilePtr(pFile->h, offset, FILE_BEGIN, &fileLocation) != NO_ERROR ){
    return SQLITE_IOERR;
  }
  assert( amt>0 );
  while( amt > 0 &&
         ( rc = DosWrite( pFile->h, (PVOID)pBuf, amt, &wrote ) ) == NO_ERROR &&
         wrote > 0
  ){
    amt -= wrote;
    pBuf = &((char*)pBuf)[wrote];
  }

  return ( rc != NO_ERROR || amt > (int)wrote ) ? SQLITE_FULL : SQLITE_OK;
}
Ejemplo n.º 15
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 );
   }
Ejemplo n.º 16
0
/* write acts like write() but returns either an error (return code
 * == -errno) or the number of bytes written. EINTR and friends leads to a
 * re-write.
 * use_blocked_io is a flag. If set, the handle is set to blocked IO and
 * we shall use blocked IO here.
 * The file must be flushed if buf or size are 0.
 */
static int Os2_write(int hdl, const void *buf, unsigned size, void *async_info)
{
   ULONG rc;
   ULONG done;

   if ((buf == NULL) || (size == 0)) /* nothing to do for flushing buffers */
      return(0);

   do {
      rc = DosWrite((HFILE) hdl, buf, size, &done);
   } while (rc == ERROR_INTERRUPT);

   if (rc != 0)
   {
      if (rc == ERROR_NO_DATA)
         return(-EAGAIN);
      if ((rc == ERROR_BROKEN_PIPE) || (rc == ERROR_DISCARDED))
         return(-EPIPE);
      if (rc == ERROR_INVALID_HANDLE)
         return(-EINVAL);
      return(-ENOSPC);   /* good assumption */
   } else if (done == 0)
      return(-EAGAIN);

   return((int) done);
}
Ejemplo n.º 17
0
Archivo: gvpeps.c Proyecto: 131/gsview
/* Write out a BMP file */
void
paste_to_file(void)
{
	LPBITMAP1 pbm1 = (LPBITMAP1)bitmap.pbmi;
	BITMAPFILEHEADER2 bmfh;
	UINT bmfh_length = sizeof(BITMAPFILEHEADER2) - sizeof(BITMAPINFOHEADER2);
	UINT offset = 0;
	UINT length = 0;	/* bitmap length */
	ULONG fh;		/* file handle */
	ULONG action;
	ULONG count;
	char output[MAXSTR];
	strcpy(output, "*.bmp");
	if (!get_filename(output, TRUE, FILTER_BMP, 0, IDS_TOPICCLIP))
		return;

	bmfh.usType = 0x4d42;	/* "BM" */
        if (bitmap.pbmi->cbFix == sizeof(BITMAP1)) {
	    offset = pbm1->bcSize + sizeof(RGB3) * dib_pal_colors((unsigned char *)bitmap.pbmi);
	    length = offset + ( dib_bytewidth((unsigned char *)bitmap.pbmi) * pbm1->bcHeight );
	}
	else {
	    offset = bitmap.pbmi->cbFix + sizeof(RGB2) * dib_pal_colors((unsigned char *)bitmap.pbmi);
	    length = offset + ( dib_bytewidth((unsigned char *)bitmap.pbmi) * bitmap.pbmi->cy );
	}
	bmfh.cbSize = bmfh_length + length;
	bmfh.xHotspot = bmfh.yHotspot = 0;
	bmfh.offBits = bmfh_length + offset;
	if (DosOpen((PCSZ)output,	/* filename */
		&fh,		/* pointer to handle */
		&action,	/* pointer to result */
		0,		/* initial length */
		FILE_NORMAL,	/* normal file */
		OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
		OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE,
		0)) {
		gserror(0, "Error opening BMP file", MB_ICONEXCLAMATION, SOUND_ERROR);
		return;
	}
	if (DosWrite(fh, (PBYTE)&bmfh, bmfh_length, &count))
		gserror(0, "Error writing BMP header", MB_ICONEXCLAMATION, SOUND_ERROR);
	if (DosWrite(fh, (PBYTE)bitmap.pbmi, length, &count))
		gserror(0, "Error writing BMP body", MB_ICONEXCLAMATION, SOUND_ERROR);
	if (DosClose(fh))
		gserror(0, "Error closing BMP file", MB_ICONEXCLAMATION, SOUND_ERROR);
}
Ejemplo n.º 18
0
bool SERIAL_sendchar(COMPORT port, char data) {
	ULONG bytesWritten = 0;
	if(port->breakstatus) return true; // does OS/2 need this?

	APIRET rc = DosWrite(port->porthandle, &data, 1, &bytesWritten);
	if (rc == NO_ERROR && bytesWritten > 0) return true;
	else return false;
}
Ejemplo n.º 19
0
_WCRTLINK void __exit_with_msg( char _WCI86FAR *msg, unsigned retcode )
/******************************************************************/
{
    unsigned    len;
    char        *end;
    ULONG       written;
    char        newline[2];

    end = msg;
    for( len = 0; *end++ != '\0'; len++ )
        ;
    DosWrite( STDERR_FILENO, msg, len, &written );
    newline[0] = '\r';
    newline[1] = '\n';
    DosWrite( STDERR_FILENO, &newline, 2, &written );
    __exit( retcode );
}
Ejemplo n.º 20
0
VOID logfunction(PSZ pszFile, ULONG line, PSZ pszCall,
                 PSZ memfunc, PVOID address, ULONG cb)
  {
  CHAR buf[256];
  cb = sprintf(buf, "calling %s() from %s->[%d]%s() address: %08p size %u\n",
               memfunc, pszFile, line, pszCall, address, cb);
  DosWrite(hf, buf, cb, &cb);
  }
Ejemplo n.º 21
0
static void PmHelp( int command )
{
    USHORT      dummy;
    pmhelp_packet       data;

    if( !HaveHelper ) return;
    data.command = command;
    DosWrite( PmOuth, &data, sizeof( data ), &dummy );
}
Ejemplo n.º 22
0
static ULONG vioSetCurType( USHORT usIndex, PVOID pargs )
{
    PVIOSETCURTYPEPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioSetCurType, p->pvci, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pvci, sizeof( VIOCURSORINFO ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
Ejemplo n.º 23
0
int mywrite( int handle, char *buff, int len )
{
    APIRET      rc;
    ULONG       bytes_written;

    rc = DosWrite( handle, buff, len, &bytes_written );
    if( rc != 0 ) return( 0 );
    return( bytes_written );
}
Ejemplo n.º 24
0
void putstring( char *str )
{
    unsigned bytes;

    while( *str ) {
        DosWrite( 1, str, 1, &bytes );
        ++str;
    }
}
Ejemplo n.º 25
0
VOID MSG_fPrint (HFILE FileHandle, MSGID MessageID) {
   CHAR   TempBuffer[2048];
   ULONG  MessageLen = 0;
   ULONG  Written;

   if (DosGetMessage(MSG_InsertTable, 5, TempBuffer, 2048, (ULONG)MessageID, MSG_Filename, &MessageLen))
      return;
   TempBuffer[MessageLen] = 0;
   DosWrite (FileHandle, &TempBuffer, MessageLen, &Written);
 }
Ejemplo n.º 26
0
static ULONG vioSetCurPos( USHORT usIndex, PVOID pargs )
{
    PVIOSETCURPOSPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioSetCurPos, p->usRow, p->usCol, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRow, sizeof( USHORT ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
Ejemplo n.º 27
0
_WCRTLINK unsigned _dos_write( int handle, void const _WCI86FAR *buffer, unsigned count, unsigned *bytes )
{
    APIRET  rc;

    rc = DosWrite( handle, (PVOID)buffer, count, (OS_PUINT)bytes );
    if( rc ) {
        return( __set_errno_dos_reterr( rc ) );
    }
    return( 0 );
}
Ejemplo n.º 28
0
INT multiWrite(CHAR *inFile, INT datS, INT sizeF, INT recNum)
{
struct Samp
   {
   SHORT indx;
   CHAR noteName[NAMESIZE];
   }sample;
ULONG oneRecSize, start;
CHAR noteText[NOTESIZE];
APIRET apiret;
ULONG ulAction, ulBufferSize, ulBytesWritten, 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_WRITEONLY | OPEN_SHARE_DENYWRITE | OPEN_FLAGS_SEQUENTIAL,
		 NULL);
oneRecSize = sizeof(sample) + sizeF;
start = sizeof(recIndex);
DosSetFilePtr(hfile, start+(oneRecSize*(recNum)), FILE_BEGIN, &newP);
if( datS == 1 )
   {
   sample.indx = dataRecs.indx;
   strcpy(sample.noteName, dataRecs.noteName);
   DosWrite(hfile, &sample, sizeof(sample), &ulBytesWritten);
   DosWrite(hfile, &dataRecs.noteText, sizeF, &ulBytesWritten);
   }
else
   {
   sample.indx = dataR.indx;
   strcpy(sample.noteName, dataR.noteName);
   DosWrite(hfile, &sample, sizeof(sample), &ulBytesWritten);
   DosWrite(hfile, &dataR.noteText, sizeF, &ulBytesWritten);
   }
DosClose(hfile);
return(1);
}
void CDirectSerial::transmitByte (Bit8u val) {
	// mean bug: with break = 1, WriteFile will never return.
	ULONG bytesWritten = 0;
	APIRET rc = DosWrite (hCom, &val, 1, &bytesWritten);
	if (rc == NO_ERROR && bytesWritten > 0) {
		ByteTransmitted ();
		//LOG_MSG("UART 0x%x: TX 0x%x", base,val);
	} else {
		LOG_MSG ("UART 0x%x: NO BYTE WRITTEN!", base);
	}
}
Ejemplo n.º 30
0
BOOL WriteConfigData( VOID )
    {
    HFILE	ConfigFile;

    DosCreate( CONFIGFILENAME, &ConfigFile, FILE_NORMAL );
    DosWrite( ConfigFile, ConfigData, sizeof( *ConfigData ), NULL );
    DosClose( ConfigFile );

    DosFreeFarMem( ConfigData );
    return( TRUE );
    }