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

  1. 2021.07.13 Watcom C Library : _lrotl, _lrotr, lsearch, lseek, ltoa

 

 

Watcom C Library Reference : _lrotl, _lrotr, lsearch, lseek, ltoa

 

 

 

 

_lrotl

 

Synopsis : #include <stdlib.h> 

              unsigned long _lrotl( unsigned long value, unsigned int shift );

 


Description : The _lrotl function rotates the unsigned long integer, determined by value, to the left by the number of bits specified in shift.

 

 

Returns : The rotated value is returned.

 

 

See Also : _lrotr, -rotl, -rotr

 


Example :

#include <stdio.h> 

#include <stdlib.h>


unsigned long mask = 0x12345678;


void main( )

{
    mask = _lrotl( mask, 4 );

    printf( "%08lx\n", mask );

}

 


produces the following :
23456781

 

Classification : WATCOM
Systems : All

 

 

 

 

 

_lrotr

 

Synopsis : #include <stdlib.h> 

              unsigned long _lrotr( unsigned long value, unsigned int shift );


Description : The _lrotr function rotates the unsigned long integer, determined by value, to the right by the number of bits specified in shift.

 

 

Returns : The rotated value is returned.

 

 

See Also : _lrotl, _rotl, _rotr

 


Example :

#include <stdio.h> 

#include <stdlib.h>


unsigned long mask = 0x12345678;


void main( )

{
    mask = _lrotr( mask, 4 );

    printf( "%08lx\n", mask );

}

 


produces the following :
81234567

 

Classification : WATCOM
Systems : All

 

 

 

 

 

lsearch

 

Synopsis : #include <search.h> 

              void *lsearch( const void *key,       /* object to search for */
                               const void *base,     /* base of search data */

                               unsigned *num,       /* number of elements */

                               unsigned width,       /* width of each element* /

                               int (*compare) ( const void *element1, const void *element2 ) );


Description : The lsearch function performs a linear search for the value key in the array of num elements pointed to by base. Each element of the array is width bytes in size. The argument compare is a pointer to a user-supplied routine that will be called by lsearch to determine the relationship of an array element with the key. One of the arguments to the compare function will be an array element, and the other will be key.


The compare function should return 0 if element1 is identical to element2 and non-zero if the elements are not identical.

 

 

Returns : If the key value is not found in the array, then it is added to the end of the array and the number of elements is incremented. The lsearch function returns a pointer to the array element in base that matches key if it is found, or the newly added key if it was not found.

 

 

See Also : bsearch, lfind

 


Example :

#include <stdio.h> 

#include <stdlib.h> 

#include <string.h> 

#include <search.h>


void main( int argc, const char *argv[ ] )

{
    int     i;

    unsigned num = 0;

    char **array = (char **) calloc( argc, sizeof( char ** ) );

    int compare( const void *, const void * );


    for( i = 1; i < argc; ++i ) {

        lsearch( &argv[i], array, &num, sizeof (char **), compare );

    }


    for( i = 0; i < num; ++i ) {
        printf( "%s\n", array[i] );

    }

}

 


int compare( const void *op1, const void *op2 )

{
    const char **p1 = (const char **) op1;

    const char **p2 = (const char **) op2;

    return ( strcmp( *p1, *p2 ) );
}

 


/* With input: one two one three four */
produces the following :
one 

two 

three 

four

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

lseek

 

Synopsis : #include <stdio.h> 

              #include <io.h>

              long int lseek( int handle, long int offset, int whence );

 


Description : The lseek function sets the current file position at the operating system level. The file is referenced using the file handle handle returned by a successful execution of one of the creat, dup, dup2, open or sopen functions. The value of offset is used as a relative offset from a file position determined by the value of the argument whence.


The new file position is determined in a manner dependent upon the value of whence which may have one of three possible values (defined in the <stdio.h> header file):

 Whence  Definition
 SEEK_SET  The new file position is computed relative to the start of the file. The value of offset must not be negative.
 SEEK_CUR  The new file position is computed relative to the current file position. The value of offset may be positive, negative or zero.
 SEEK_END  The new file position is computed relative to the end of the file.

 

An error will occur if the requested file position is before the start of the file.


The requested file position may be beyond the end of the file. If data is later written at this point, subsequent reads of data in the gap will return bytes whose value is equal to zero until data is actually written in the gap.


Some versions of MS-DOS allow seeking to a negative offset, but it is not recommended since it is not supported by other platforms and may not be supported in future versions of MS-DOS.


The lseek function does not, in itself, extend the size of a file (see the description of the chsize function).

 

 


Returns : If successful, the current file position is returned in a system-dependent manner. A value of 0 indicates the start of the file. When an error occurs. -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 handle argument is not a valid file handle.
 EINVAL  The whence argument is not a proper value, or the resulting file offset would be invalid.

 

 

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

 


Example : The lseek function can be used to obtain the current file position (the tell function is implemented in terms of lseek). This value can then be used with the lseek function to reset the file position to that point in the file:

long int file_posn; 

int handle;


/* get current file position */ 

file_posn = lseek( handle, 0L, SEEK_CUR );

    /* or */ 

file_posn = tell( handle );

 

/* return to previous file position */ 

file_posn = lseek ( handle, file_posn, SEEK_SET );

 


If all records in the file are the same size, the position of the n'th record can be calculated and read, as illustrated in the following sample function:


#include <stdio.h> 

#include <io.h>


int read record ( int handle, long rec_numb, int rec_size, char *buffer )

{
    if( lseek( handle, rec_numb* rec_size, SEEK_SET ) == -1L ) {

        return( -1 );

    }
    return( read( handle, buffer, rec_size ) );

}

 


The function in this example assumes records are numbered starting with zero and that rec_size contains the size of a record in the file (including the carriage-return character in text files).

 

Classification : POSIX 1003.1
Systems : All

 

 

 

 

 

ltoa

 

Synopsis : #include <stdlib.h> 

              char *ltoa( long int value, char *buffer, int radix );

 


Description : The ltoa function converts the binary integer value into the equivalent string in base radix notation storing the result in the character array pointed to by buffer. A null character is appended to the result. The size of buffer must be at least 33 bytes when converting values in base 2. If the value of radix is 10 and value is negative, then a minus sign is prepended to the result.

 

 

Returns : The ltoa function returns a pointer to the result.

 

 

See Also : atol, strtol, strtoul, ultoa

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void print_value( long value )

{
    int     base;

    char    buffer[33];


    for( base = 2; base <= 16; base = base + 2 ) {

        printf( "%2d %s\n", base, ltoa ( value, buffer, base ) );

    }

}

 


void main( )

{
    print_value ( 12765L );

}

 


produces the following :

2 11000111011101 

4 3013131 

6 135033 

8 30735 

10 12765 

12 7479 

14 491b 

16 31dd

 

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