Watcom C Library Reference : _exit, exit, exp, _expand Functions 

 

 

 

 

_exit

 

Synopsis : #include <stdlib.h> 

              void _exit ( int status );

 


Description : The _exit function causes normal program termination to occur.

 1. The functions registered by the atexit or onexit functions are not called.
 2. Any unopened files are not closed and any buffered output is not flushed to the associated files or devices.
 3. Any files created by tmpfile are not removed.
 4. The return status is made available to the parent process. Only the low order byte of status is available on DOS systems. The status value is typically set to 0 to indicate successful termination and set to some other value to indicate an error.

 


Returns : The _exit function does not return to its caller.

 

 

See Also : abort, atexit, _bgetcmd, exec Functions, exit, getcmd, getenv, main, onexit, putenv, spawn Functions, system

 


Example :

#include <stdio.h> 

#include <stdlib.h>


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

{
    FILE     *fp;
   

    if( argc <= 1 ) {
        fprintf( stderr, "Missing argument\n" );

        exit( EXIT_FAILURE );

    }


    fp = fopen( argv[1], "r" );

    if( fp == NULL ) {
        fprintf( stderr, "Unable to open '%s'\n", argv[1] );

        _exit( EXIT_FAILURE );

    }
    fclose( fp );

    _exit( EXIT_SUCCESS );

}

 

Classification : POSIX 1003.1
Systems : All

 

 

 

 

 

exit

 

Synopsis : #include <stdlib.h> 

              void exit( int status );

 


Description : The exit function causes normal program termination to occur.

First, all functions registered by the at exit function are called in the reverse order of their registration. Next, all open files are flushed and closed, and all files created by the tmpfile function are removed. Finally, the return status is made available to the parent process. Only the low order byte of status is available on DOS systems. The status value is typically set to 0 to indicate successful termination and set to some other value to indicate an error.

 

 

Returns : The exit function does not return to its caller.

 

 

See Also : abort, atexit, _exit, onexit

 


Example :

#include <stdio.h> 

#include <stdlib.h>


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

{
    FILE     *fp;


    if( argc <= 1 ) {
        fprintf ( stderr, "Missing argument\n" );

        exit ( EXIT_FAILURE );

    }


    fp = fopen( argv[1], "r" );

    if( fp == NULL ) {
        fprintf( stderr, "Unable to open '%s'\n", argv[1] );

        exit( EXIT_FAILURE );

    }
    fclose( fp );

    exit ( EXIT_SUCCESS );

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

exp

 

Synopsis : #include <math.h> 

              double exp ( double x );

 


Description : The exp function computes the exponential function of x. A range error occurs if the magnitude of x is too large.

 

 

Returns : The exp function returns the exponential value. 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 ERANGE, and print a "RANGE error" diagnostic message using the stderr stream.

 

 

See Also : log, matherr

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )

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

}

 


produces the following :
1.648721

 

Classification : ANSI
Systems : All

 

 

 

 

 

_expand Functions

 

Synopsis : #include <malloc.h> 

              void *_expand( void *mem_blk, size_t size );

              void __based (void) *_bexpand( __segment seg, void __based (void) *mem_blk, size_t size. ); 

              void __far *_fexpand( void __far *mem_blk, size_t size); 

              void __near *_nexpand( void __near *mem_blk, size_t size);


Description : The _expand functions change the size of the previously allocated block pointed to by mem_blk by attempting to expand or contract the memory block without moving its location in the heap. The argument size specifies the new desired size for the memory block. The contents of the memory block are unchanged up to the shorter of the new and old sizes.


Each function expands the memory from a particular heap, as listed below:

 

 Function  Heap Expanded
 _expand  Depends on data model of the program
 _bexpand  Based heap specified by seg value
 _fexpand  Far heap (outside the default data segment)
 _nexpand  Near heap (inside the default data segment)

 

In a small data memory model, the _expand function is equivalent to the _nexpand function; in a large data memory model, the _expand function is equivalent to the _fexpand function.

 

 

Returns : The _expand functions return the value mem_blk if it was successful in changing the size of the block. The return value is NULL( _NULLOFF for _bexpand ) if the memory block could not be expanded to the desired size. It will be expanded as much as possible in this case.


The appropriate _msize function can be used to determine the new size of the expanded block.

 

 

See Also : calloc Functions, free Functions, halloc, hfree, malloc Functions, _msize Functions, realloc Functions, sbrk

 


Example :

#include <stdio.h> 

#include <malloc.h>


void main( )

{
    char       *buf;

    char __far *buf2;

 

    buf = (char *) malloc ( 80 );

    printf( "Size of buffer is %u\n", _msize (buf) );

 

    if( _expand ( buf, 100 ) == NULL ) {
        printf( "Unable to expand buffer\n" );

    }   

    printf( "New size of buffer is %u\n", _msize (buf) );

 

    buf2 = (char __far *) _fmalloc( 2000 );

    printf( "Size of far buffer is %u\n", _fmsize (buf2) );

    if( _fexpand ( buf2, 8000 ) == NULL ) {
        printf( "Unable to expand far buffer\n" );

    }
    printf( "New size of far buffer is %u\n", _fmsize (buf2) );

}

 


produces the following :
Size of buffer is 80

Unable to expand buffer

New size of buffer is 80

Size of far buffer is 2000

New size of far buffer is 8000

 

Classification : WATCOM
Systems : _expand - All 

             _bexpand - DOS/16, Win/16, QNX/16, OS/2 1.x(all)

             _fexpand - DOS/16, Win/16, QNX/16, OS/2 1.x(all)

             _nexpand - DOS, Win, QNX, OS/2 1.x, OS/2 1.x(MT), OS/2 2.x, NT

 

 

 

 

 

 

 

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