'_dos_setvect'에 해당되는 글 1건

  1. 2021.06.22 Watcom C Library Reference : _dos_setvect, _dos_write, dup, dup2

 

 

Watcom C Library Reference : _dos_setvect, _dos_write, dup, dup2

 

 

 

 

_dos_setvect

 

Synopsis : #include <dos.h> 

              void _dos_setvect ( unsigned intnum, void (__interrupt __far *handler) ( ) );


Description : The _dos_setvect function sets interrupt vector number intnum to point to the interrupt handling function pointed to by handler.

 

 

Returns : The function does not return a value.

 

 

See Also : _chain_intr, -dos_getvect, _dos_keep

 


Example :

#include <stdio.h> 

#include <dos.h>


volatile int clock_ticks; 

void (__interrupt __far *prev_int_1c) ( );

#define BLIP_COUNT (5 * 18)     /* 5 seconds */


void __interrupt __far timer_rtn( )

{
    ++clock_ticks;

    _chain_intr( prev_int_1c );

}


int delays = 0;

 

 

void main( )

{
    prev_int_1c = _dos_getvect( 0x1c );

    _dos_setvect ( 0x1c, timer_rtn);

 

    while ( compile_a_line () ) {

        if( clock_ticks >= BLIP_COUNT ) {
            putchar( ',' );

            clock_ticks -= BLIP_COUNT;

        }

    }
    _dos_setvect ( 0xlc, prev_int_1c);

}

 


int compile_a_line ( )

{
    if( delays > 15 ) return( 0 );

    delay ( 1000 );    /* delay for 1 second */

    printf( "Delayed for 1 second\n" );

    delays++;

    return( 1 );

}

 

Classification : WATCOM
Systems : DOS, Win/16, DOS/PM

 

 

 

 

 

_dos_write

 

Synopsis : #include <dos.h> 

              unsigned _dos_write( int handle, void __far *buffer, unsigned count, unsigned *bytes );


Description : The _dos_write function uses system call 0x40 to write count bytes of data from the buffer pointed to by buffer to the file specified by handle. The number of bytes successfully written will be stored in the unsigned integer pointed to by bytes.

 

 

Returns : The _dos_write function returns zero if successful. Otherwise, it returns an MS-DOS error code and sets errno to one of the following values:

 Constant  Meaning
 EACCES  Access denied because the file is not open for write access
 EBADF  Invalid file handle

 


See Also : _dos_close, _dos_open, _dos_read

 


Example :

#include <stdio.h> 

#include <dos.h> 

#include <fcntl.h>


char buffer[ ] = "This is a test for _dos_write.";


void main( )

{
    unsigned    len_written;

    int           handle;


    if( _dos_creat ( "file", _A_NORMAL, &handle ) != 0 ) {
        printf( "Unable to create file\n" );

    } else {

        printf( "Create succeeded\n" );

        _dos_write( handle, buffer, sizeof (buffer), &len_written ); 

        _dos_close( handle );

    }

}

 

Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM

 

 

 

 

 

dup

 

Synopsis : #include <io.h> 

              int dup( int handle );


Description : The dup function duplicates the file handle given by the argument handle. The new file handle refers to the same open file handle as the original file handle, and shares any locks.

 

The new file handle is identical to the original in that it references the same file or device, it has the same open mode (read and/or write) and it will have file position identical to the original. Changing the position with one handle will result in a changed position in the other.

 

 

Returns : If successful, the new file handle is returned to be used with the other functions which operate on the file. Otherwise, -1 is returned and errno is set to indicate the error.

 


Errors : When an error has occurred, errno contains a value indicating the type of error that has been detected.

 Constant  Meaning
 EBADF  The argument handle is not a valid open file handle.
 EMFILE  The number of file handles would exceed {OPEN_MAX}.

 


See Also : chsize, close, creat, dup2, eof, exec Functions, filelength, fileno, fstat, isatty, lseek, open, read, setmode, sopen, stat, tell, write, umask

 


Example :

#include <fcntl.h> 

#include <io.h>


void main( )

{
    int     handle, dup_handle;


    handle = open( "file", O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, 

                           S_IRUSR | S_IWUSR |S_IRGRP | S_IWGRP ); 

 

    if( handle != -1 ) {
        dup_handle = dup( handle ) ;

        if( dup_handle != -1 ) {
            /* process file */
            close( dup_handle );

        }
        close( handle );

    }

}

 

Classification : POSIX 1003.1
Systems : All

 

 

 

 

 

dup2

 

Synopsis : #include <io.h> 

              int dup2 ( int handle, int handle2 );


Description : The dup2 function duplicates the file handle given by the argument handle. The new file handle is identical to the original in that it references the same file or device, it has the same open mode (read and/or write) and it will have identical file position to the original (changing the position with one handle will result in a changed position in the other).


The number of the new handle is handle2. If a file already is opened with this handle, the file is closed before the duplication is attempted.

 

 

Returns : The dup2 function returns zero if successful. Otherwise, -1 is returned and errno is set to indicate the error.

 

 

Errors : When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

 Constant  Meaning
 EBADF  The argument handle is not a valid open file handle or handle2 is out of range.
 EMFILE  The number of file handles would exceed {OPEN_MAX), or no file handles above handle2 are available.

 


See Also : chsize, close, creat, dup, eof, exec Functions, filelength, fileno, fstat, isatty, lseek, open, read, setmode, sopen, stat, tell, write, umask

 


Example :

#include <fcntl.h>

#include <io.h>


void main( )

{
    int     handle, dup_handle;


    handle = open( "file", O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
                           S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);

 

    if( handle != -1 ) {
        dup_handle = 4;

        if( dup2 ( handle, dup_handle ) != -1 ) {
            /* process file */
            close( dup_handle );

        }
        close( handle );

    }

}

 

Classification : POSIX 1003.1
Systems : All

 

 

 

 

 

 

 

 

This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).

 

WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)

 

 

 

728x90
반응형
Posted by 전화카드
,