'longjmp func'에 해당되는 글 1건

  1. 2021.07.11 Watcom C Library : locking, log, log10, log2, longjmp

 

 

Watcom C Library Reference : locking, log, log10, log2, longjmp

 

 

 

 

locking

 

Synopsis : #include <sys\locking.h> 

              int locking( int handle, int mode, long nbyte );

 


Description : The locking function locks or unlocks nbyte bytes of the file specified by handle. Locking a region of a file prevents other processes from reading or writing the locked region until the region has been unlocked. The locking and unlocking takes place at the current file position. The argument mode specifies the action to be performed. The possible values for mode are:

 

 Mode  Meaning
 LK_LOCK  Locks the specified region. The function will retry to lock the region after 1 second intervals until successful or until 10 attempts have been made.
 LK_RLCK  Same action as LK_LOCK.
 LK_NBLCK  Non-blocking lock: makes only 1 attempt to lock the specified region.
 LK_NBRLCK  Same action as LK_NBLCK.
 LK_UNLCK  Unlocks the specified region. The region must have been previously locked.

 

Multiple regions of a file can be locked, but no overlapping regions are allowed. You cannot unlock multiple regions in the same call, even if the regions are contiguous. All locked regions of a file should be unlocked before closing a file or exiting the program.


With DOS, locking is supported by version 3.0 or later. Note that SHARE.COM or SHARE.EXE must be installed.

 


Returns : The locking function returns zero if successful. Otherwise, it returns -1 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
 EACCES  Indicates a locking violation (file already locked or unlocked).
 EBADF  Indicates an invalid file handle.
 EDEADLOCK  Indicates a locking violation. This error is returned when mode is LK_LOCK or LK_RLCK and the file cannot be locked after 10 attempts.
 EINVAL  Indicates that an invalid argument was given to the function.

 

 

See Also : creat, _dos_creat, _dos_open, lock, open, sopen, unlock

 


Example :

#include <stdio.h> 

#include <sys\locking.h> 

#include <share.h> 

#include <fcntl.h> 

#include <io.h>


void main( )

{
    int     handle;

    unsigned nbytes;

    unsigned long offset;

    auto char buffer[512];


    nbytes = 512;

    offset = 1024;

    handle = sopen( "db.fil", O_RDWR, SH_DENYNO );

 

    if( handle != -1 ) {
        lseek( handle, offset, SEEK_SET );

        locking( handle, LK_LOCK, nbytes );

        read( handle, buffer, nbytes);

 

        /* update data in the buffer */

        lseek( handle, offset, SEEK_SET );

        write( handle, buffer, nbytes );

        lseek( handle, offset, SEEK_SET );

        locking( handle, LK_UNLCK, nbytes );

        close( handle );

    }

}

 

Classification : WATCOM
Systems : All

 

 

 

 

 

log

 

Synopsis : #include <math.h> 

              double log( double x );

 


Description : The log function computes the natural logarithm (base e) of x. A domain error occurs if argument is negative. A range error occurs if the argument is zero.

 

 

Returns : The log function returns the natural logarithm of the argument. When the argument is outside the permissible range, the matherr function is called. Unless the default matherr function is replaced, it will set the global variable errno to EDOM, and print a "DOMAIN error" diagnostic message using the stderr stream.

 

 

See Also : exp, log10, log2, pow, matherr

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )
{
    printf( "%f\n", log(.5) );

}

 


produces the following :
-0.693147

 

Classification : ANSI
Systems : All

 

 

 

 

 

log10

 

Synopsis : #include <math.h> 

              double log10( double x );

 


Description : The log10 function computes the logarithm (base 10) of x. A domain error occurs if the argument is negative. A range error occurs if the argument is zero.

 

 

Returns : The log10 function returns the logarithm (base 10) of the argument. When the argument is outside the permissible range, the matherr function is called. Unless the default matherr function is replaced, it will set the global variable errno to EDOM, and print a "DOMAIN error" diagnostic message using the stderr stream.

 

 

See Also : exp, log, log2, pow, matherr

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )

{
    printf( "%f\n", log10(.5) );

}

 


produces the following :
-0.301030

 

Classification : ANSI
Systems : All

 

 

 

 

 

log2

 

Synopsis : #include <math.h> 

              double log2( double x );

 


Description : The log2 function computes the logarithm (base 2) of x. A domain error occurs if the argument is negative. A range error occurs if the argument is zero.

 

 

Returns : The log2 function returns the logarithm (base 2) of the argument. When the argument is outside the permissible range, the matherr function is called. Unless the default matherr function is replaced, it will set the global variable errno to EDOM, and print a "DOMAIN error" diagnostic message using the stderr stream.

 

 

See Also : exp, log, log10, pow, matherr

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )
{

    printf( "%f\n", log2 (.25) );

}

 

 

produces the following :
-2.000000

 

Classification : WATCOM
Systems : All

 

 

 

 

 

longjmp

 

Synopsis : #include <setjmp.h> 

              void longjmp( jmp_buf env, int return_value );

 


Description : The longjmp function restores the environment saved by the most recent call to the setjmp function with the corresponding jmp_buf argument.

 

 

Returns : After the longimp function restores the environment, program execution continues as if the corresponding call to setjmp had just returned the value specified by return_value. If the value of return_value is 0, the value returned is 1.

 

 

See Also : setjmp



Example :

#include <stdio.h> 

#include <setjmp.h> 

jmp_buf     env;


rtn( )

{
    printf( "about to longjmp \n" );

    longjmp( env, 14 );

}

 

 

void main( )

{
    int     ret_val = 293;


    if( 0 == ( ret_val = setjmp( env ) ) ) {
        printf( "after setjmp %d\n", ret_val );

        rtn( );

        printf( "back from rtn %d\n", ret_val );

    } else {
        printf( "back from longjmp %d\n", ret_val );

    }

}

 


produces the following :
after setjmp 0 

about to longjmp 

back from longjmp 14

 

Classification : ANSI
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 전화카드
,