'Watcom C Library reference guide'에 해당되는 글 33건

  1. 2021.11.26 Watcom C Library : utime, utoa, va_arg, va_end, va_start

 

 

Watcom C Library Reference : utime, utoa, va_arg, va_end, va_start

 

 

 

 

utime

 

Synopsis : #include <sys\utime.h> 

              int utime( const char *path, const struct utimbuf *times );
             

              struct utimbuf {
                     time_t actime;        /* access time */
                     time_t modtime;      /* modification time */

              };


Description : The utime function records the access and modification times for the file identified by path. Write access to this file must be permitted for the time to be recorded.


When the times argument is NULL, the current time is recorded. Otherwise, the argument must point at an object whose type is struct utimbuf. The modification time is taken from the modtime field in this structure.

 

 

Returns : The utime function returns zero when the time was successfully recorded. A value of -1 indicates an error occurred.

 

 

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

 Cosntant  Meaning
 EACCES  Search permission is denied for a component of path or the times argument is NULL and the effective user ID of the process does not match the owner of the file and write access is denied.
 EINVAL  The date is before 1980 (DOS only).
 EMFILE  There are too many open files.
 ENOENT  The specified path does not exist or path is an empty string.

 

 

Example :

#include <stdio.h> 

#include <sys\utime.h>


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

{
    if(( utime( argv[1], NULL ) != 0 ) && ( argc > 1 )) {
        printf( "Unable to set time for %s\n", argv[1] );

    }

}

 

Classification : POSIX 1003.1
Systems : All

 

 

 

 

 

 

 

utoa

 

Synopsis : #include <stdlib.h> 

              char *utoa( unsigned int value, char *buffer, int radix );

 


Description : The utoa function converts the unsigned 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 (8 * sizeof(int) + 1) bytes when converting values in base 2. That makes the size 17 bytes on 16-bit machines, and 33 bytes on 32-bit machines.

 

 

Returns : The utoa function returns the pointer to the result.

 

 

See Also : atoi, itoa, strtol, strtoul

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    int     base;

    char   buffer[18];


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

        printf( "%2d : %s\n", base, utoa( (unsigned) 12765, buffer, base ) );

    }

}

 


produces the following :
2 : 11000111011101

4 : 3013131

6 : 135033

8 : 30735

10 : 12765

12 : 7479

14 : 491b

16 : 31dd

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

 

va_arg

 

Synopsis : #include <stdarg.h> 

              type va_arg( va_list param, type );

 


Description : va_arg is a macro that can be used to obtain the next argument in a list of variable arguments. It must be used with the associated macros va_start and va_end. A sequence such as
        va_list curr_arg;

        type next_arg;
        next_arg = va_arg( curr_arg, type );

causes next_arg to be assigned the value of the next variable argument. The type is the type of the argument originally passed.


The macro va_start must be executed first in order to properly initialize the variable next_arg and the macro va_end should be executed after all arguments have been obtained


The data item curr_arg is of type va_list which contains the information to permit successive acquisitions of the arguments.

 

 

Returns : The macro returns the value of the next variable argument, according to type passed as the second parameter.

 

 

See Also : va_end, va_start, vfprintf, vprintf, vsprintf

 


Example :

#include <stdio.h> 

#include <stdarg.h>


void test_fn( const char *msg, const char *types, ... );


void main( )

{
    printf( "VA...TEST\n" );

    test_fn( "PARAMETERS: 1, \"abc\", 546", "isi", 1, "abc", 546 );

    test_fn( "PARAMETERS: \"def\", 789", "si", "def", 789 );

}


static void test_fn(

        const char *msg,     /* message to be printed  */

        const char *types,   /* parameter types (i,s)    */

        ... )                   /* variable arguments      */
{
    va_list  argument;

    int      argint;

    char    *arg_string;

    const char *types_ptr;

   

    types_ptr = types;

    printf( "\n%s -- %s\n", msg, types );

    va_start( argument, types );

 

    while( *types_ptr != '\0' ) {

        if( *types_ptr == 'i') {
            arg_int = va_arg( argument, int );
            printf( "integer: %d\n", arg_int );

        } else if( *types_ptr == 's') {
            arg_string = va_arg( argument, char * );

            printf( "string: %s\n", arg_string );

        }
        ++types_ptr;

    }

    va_end( argument );

}

 


produces the following :
VA... TEST


PARAMETERS: 1, "abc", 546 -- isi 

integer: 1 

string: abc 

integer: 546

 

PARAMETERS: "def", 789 -- si 

string: def 

integer: 789

 

Classification : ANSI
Systems : MACRO

 

 

 

 

 

 

 

va_end

 

Synopsis : #include <stdarg.h> 

              void va_end( va list param );

 


Description : vg_end is a macro used to complete the acquisition of arguments from a list of variable arguments. It must be used with the associated macros va_start and va_arg. See the description for va_arg for complete documentation on these macros.

 

 

Returns : The macro does not return a value.

 

 

See Also : va_arg, va_start, vfprintf, vprintf, vsprintf

 


Example :

#include <stdio.h> 

#include <stdarg.h> 

#include <time.h>


#define ESCAPE 27


void tprintf( int row, int col, char *fmt, ... )

{
    auto va_list ap;

    char *p1, *p2;

 

    va_start( ap, fmt );   

    p1 = va_arg( ap, char * );

    p2 = va_arg( ap, char * );

    printf( "%c[%2.2d;%2.2dH", ESCAPE, row, col );

    printf( fmt, p1, p2 );

    va_end( ap );

}


void main( )

{
    struct tm    time_of_day;

    time_t       ltime;

    auto char   buf[26];


    time( &ltime );

    _localtime( &ltime, &time_of_day );

    tprintf( 12, 1, "Date and time is: %s\n", _asctime( &time_of_day, buf ) );
}

 

Classification : ANSI
Systems : MACRO

 

 

 

 

 

 

 

va_start

 

Synopsis : #include <stdarg.h> 

              void va_start( va_list param, previous );

 


Description : va_start is a macro used to start the acquisition of arguments from a list of variable arguments. The param argument is used by the va_arg macro to locate the current acquired argument. The previous argument is the argument that immediately precedes the "..." notation in the original function definition. It must be used with the associated macros va_arg and va_end. See the description of va_arg for complete documentation on these macros.

 

 

Returns : The macro does not return a value.

 

 

See Also : va_arg, va_end, vfprintf, vprintf, vsprintf

 


Example :

#include <stdio.h> 

#include <stdarg.h> 

#include <time.h>


#define ESCAPE 27


void tprintf( int row, int col, char *fmt, ... )

{
    auto va_list ap;

    char *p1, *p2;


    va_start( ap, fmt );

    p1 = va_arg( ap, char * );

    p2 = va_arg( ap, char * );

    printf( "%c (%2.2d;%2.20H", ESCAPE, row, col );

    printf( fmt, p1, p2 );

    va_end ( ap );

}


void main( )

{
    struct tm    time_of_day;

    time_t       ltime;

    auto char   buf[26];

 

    time( &ltime );

    _localtime( &ltime, &time_of_day );

    tprintf( 12, 1, "Date and time is: %s\n", _asctime( &time_of_day, buf ) );

}

 

Classification : ANSI
Systems : MACRO

 

 

 

 

 

 

 

 

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