'Watcom C Reference/T ~ Z'에 해당되는 글 7건

  1. 2021.12.01 Watcom C Library : wait, wcstombs, wctomb, _wrapon, write

 

 

Watcom C Library Reference : wait, wcstombs, wctomb, _wrapon, write

 

 

 

 

wait

 

Synopsis : #include <process.h> 

              int wait( int *status );

 


Description : The wait function suspends the calling process until any of the caller's immediate child processes terminate.


If status is not NULL, it points to a word that will be filled in with the termination status word and return code of the terminated child process.


If the child process terminated normally, then the low order byte of the status word will be set to 0. and the high order byte will contain the low order byte of the return code that the child process passed to the DOSEXIT function. The DOSEXIT function is called whenever main returns, or exit or _exit are explicity called.


If the child process did not terminate normally, then the high order byte of the status word will be set to 0, and the low order byte will contain one of the following values:

 Value  Meaning
 1  Hard-error abort
 2  Trap operation
 3  SIGTERM signal not intercepted

 

 

Returns : The wait function returns the child's process id if the child process terminated normally. Otherwise, wait returns -1 and sets errno to one of the following values:

 Constant  Meaning
 ECHILD  No child processes exist for the calling process.
 EINTR  The child process terminated abnormally.

 

 

See Also : cwait, exit, _exit, spawn Functions

 


Example :

#include <stdlib.h> 

#include <process.h>


void main( )

{
    int    process_id, status;


    process_id = spawnl( P_NOWAIT, "child.exe", "child", "parm", NULL );

    wait( &status );

}

 

Classification : OS/2
Systems : QNX, OS/2 1.x(all), OS/2 2.x, NT

 

 

 

 

 

 

 

wcstombs

 

Synopsis : #include <stdlib.h> 

              size_t wcstombs( char *s, const wchar_t *pwcs, size_t n );

 


Description : The wcstombs function converts a sequence of wide character codes from the array pointed to by pwcs into a sequence of multibyte characters and stores them in the array pointed to by s. The wcstombs function stops if a multibyte character would exceed the limit of n total bytes, or if the null character is stored. At most n bytes of the array pointed to by s will be modified.

 

 

Returns : If an invalid multibyte character is encountered, the wcstombs function returns (size_t)-1. Otherwise, the wcstombs function returns the number of array elements modified, not including the terminating zero code if present.

 

 

See Also : mblen, mbtowc, mbstowcs, wctomb

 


Example :

#include <stdio.h> 

#include <stdlib.h>


wchar_t     wbuffer[] = {
        0x0073,

        0x0074,

        0x0072,

        0x0069,

        0x006e,

        0x0067,
        0x0000 

};

 


void main( )

{
    char   mbsbuffer[50];

    int     i, len;


    len = wcstombs( mbsbuffer, wbuffer, 50 );

    if ( len != -1 ) {

        for ( i = 0; i < len; i++ )
            printf( "/%4.4x", wbuffer[i] );

        printf( "\n" );

        mbsbuffer[len] = '\0';

        printf( "%s (%d)\n", mbsbuffer, len );

    }

}

 


produces the following :
/0073/0074/0072/0069/006e/0067

string(6)

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

wctomb

 

Synopsis : #include <stdlib.h> 

              int wctomb( char *s, wchar_t wchar ) ;

 


Description : The wctomb function determines the number of bytes required to represent the multibyte character corresponding to the code contained in wchar. If s is not a NULL pointer, the multibyte character representation is stored in the array pointed to by s. At most MB_CUR_MAX characters will be stored.

 

 

Returns : If s is a NULL pointer, the wctomb function returns zero if multibyte character encodings do not have state-dependent encoding, and non-zero otherwise. If s is not a NULL pointer, the wctomb function returns:

 Value  Meaning
 -1  if the value of wchar does not correspond to a valid multibyte character
 len  the number of bytes that comprise the multibyte character corresponding to the value of wchar.

 


See Also : mblen, mbstowcs, mbtowc, wcstombs

 


Example :

#include <stdio.h> 

#include <stdlib.h>


wchar_t     wchar = { 0x0073 };

char         mbbuffer[MB_CUR_MAX];


void main( )

{
    int     len;


    printf( "Character encodings do %shave state-dependent encoding\n", 

            ( wctomb( NULL, 0 ) ) ? "" : "not " );


    len = wctomb( mbbuffer, wchar );

    mbbuffer[len] = '\0';

    printf( "%s(%d) \n", mbbuffer, len );

}

 


produces the following :
Character encodings do not have state-dependent encoding 

s(1)

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

_wrapon

 

Synopsis : #include <graph.h> 

              short _FAR _wrapon( short wrap );

 


Description : The _wrapon function is used to control the display of text when the text output reaches the right side of the text window. This is text displayed with the _outtext and _outmem functions. The wrap argument can take one of the following values:

 Value  Meaning
 _GWRAPON  causes lines to wrap at the window border
 _GWRAPOFF  causes lines to be truncated at the window border

 

 

Returns : The _wrapon function returns the previous setting for wrapping.

 

 

See Also : _outtext, _outmem, _settextwindow

 


Example :

#include <conio.h> 

#include <graph.h> 

#include <stdio.h>


void main( )

{
    int     i;

    char   buf[80];


    _setvideomode( _TEXTC80 );

    _settextwindow( 5, 20, 20, 30 );

    _wrapon( _GWRAPOFF );

    for( i = 1; i <= 3; ++i ) {
        _settextposition( 2 * i, 1 );

        sprintf( buf, "Very very long line %d", i );

        _outtext( buf );

    }


    _wrapon( _GWRAPON );

    for( i = 4; i <= 6; ++i ) {
        _settextposition( 2 * i, 1 );

        sprintf( buf, "Very very long line %d", i );

        _outtext( buf );

    }
   

    getch( );

    _setvideomode( _DEFAULTMODE );

}

 

Classification : PC Graphics
Systems : DOS, QNX

 

 

 

 

 

 

 

write

 

Synopsis : #include <io.h> 

              int write( int handle, void *buffer, unsigned len );

 


Description : The write function writes data at the operating system level. The number of bytes transmitted is given by len and the data to be transmitted is located at the address specified by buffer.


The handle value is returned by the open function. The access mode must have included either O_WRONLY or O_RDWR when the open function was invoked.


The data is written to the file at the end when the file was opened with O_APPEND included as part of the access mode; otherwise, it is written at the current file position for the file in question. This file position can be determined with the tell function and can be set with the lseek function.


When O_BINARY is included in the access mode, the data is transmitted unchanged. When O_TEXT is included in the access mode, the data is transmitted with extra carriage return characters inserted before each linefeed character encountered in the original data.


A file can be truncated under DOS and OS/2 2.0 by specifying 0 as the len argument. Note, however, that this doesn't work under OS/2 2.1, Windows NT, and other operating systems. To truncate a file in a portable manner, use the chsize function.

 

 

Returns : The write function returns the number of bytes (does not include any extra carriage-return characters transmitted) of data transmitted to the file. When there is no error, this is the number given by the len argument.

 

In the case of an error, such as there being no space available to contain the file data, the return value will be less than the number of bytes transmitted. A value of -1 may be returned in the case of some output errors. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

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

 


Example :

#include <stdio.h> 

#include <io.h> 

#include <fcntl.h>


char     buffer[] = { "A text record to be written" };

void main( )

{
    int     handle;

    int     size_written;


    /* open a file for output  replace existing file if it exists   */

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

 

    if( handle != -1 ) {
        /* write the text   */ 

        size_written = write( handle, buffer, sizeof( buffer ) );


        /* test for error   */

        if( size_written != sizeof( buffer ) ) {
            printf( "Error writing file\n" );

        }
        /* close the file   */

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