Watcom C Library Reference : stackavail, stat, _status87, strcat, _fstrcat, strchr, _fstrchr

 

 

 

 

stackavail

 

Synopsis : #include <malloc.h> 

              size_t stackavail( void );

 


Description :  The stackavail function returns the number of bytes currently available in the stack. This value is usually used to determine an appropriate amount to allocate using alloca.

 

 

Returns : The stackavail function returns the number of bytes currently available in the stack.

 

 

See Also : alloca, calloc Functions, malloc Functions

 


Example :

#include <stdio.h> 

#include <string.h> 

#include <malloc.h> 

#include <fcntㅣ.h>

#include <io.h>


long char_count( FILE *fp )

{
    char     *buffer;

    size_t    bufsiz;

    long     count;


    /* allocate half of stack for temp buffer */

    bufsiz = stackavail( ) >> 1;

    buffer = (char *) alloca( bufsiz );

    setvbuf( fp, buffer, _IOFBF, bufsiz );

    count = 0L;

    while( fgetc( fp ) != EOF ) ++count;

    fclose( fp );

    return( count );

}

 


void main( )

{
    FILE     *fp;


    fp = fopen( "file", "rb" );

    if( fp != NULL ) {
        setmode( fileno( fp ), O_BINARY );

        printf( "File contains %lu characters\n", char_count( fp ) );

        fclose( fp );

    }

}

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

 

stat

 

Synopsis : #include <sys\stat.h> 

              int stat( const char *path, struct stat *buf );

 


Description : The stat function obtains information about the file or directory referenced in path. This information is placed in the structure located at the address indicated by buf.


The file <sys\stat.h> contains definitions for the structure stat.
struct stat {
    dev_t    st_dev;                 /* disk drive file resides on

    ino_t     st_ino;                  /* this inode's number

    unsigned short st_mode;         /* file mode

    short     st_nlink;                /* # of hard links
    short     st_uid;                  /* user-id, always 'root'

    short     st_gid;                  /* group-id, always 'root'

    dev_t     st_rdev;                /* drive #, same as st_dev

    off_t      st_size;                 /* total file size
    time_t    st_atime;                /* time of last access

    time_t    st_mtime;               /* time of last modification */

    time_t    st_ctime;               /* time of last status change */
};


At least the following macros are defined in the <sys\stat.h> header file.

 Macro  Meaning
 S ISFIFO(m)  Test for FIFO.
 S_ISCHR(m)  Test for character special file.
 S_ISDIR(m)  Test for directory file.
 S_ISBLK(m)  Test for block special file.
 S_ISREG(m)  Test for regular file.


The value m supplied to the macros is the value of the st_mode field of a stat structure. The macro evaluates to a non-zero value if the test is true and zero if the test is false.


The following bits are encoded within the st_mode field of a stat structure.

 Mask  Owner Permissions
 S_IRWXU  Read, write, search (if a directory), or execute (otherwise)
 S_IRUSR  Read permission bit
 S_IWUSR  Write permission bit
 S_IXUSR  Search/execute permission bit
 S_IREAD  == S_IRUSR (for Microsoft compatibility)
 S_IWRITE  == S_IWUSR (for Microsoft compatibility)
 S_IEXEC  == S_IXUSR (for Microsoft compatibility)

 

S_IRWXU is the bitwise inclusive OR of S_IRUSRS_IWUSR, and S_IXUSR.

 

 

 Mask  Group Permissions (same as owner's on DOS, OS/2 or Windows NT)
 S_IRWXG  Read, write, search (if a directory), or execute (otherwise)
 S_IRGRP  Read permission bit
 S_IWGRP  Write permission bit
 S_IXGRP  Search/execute permission bit

 

S_IRWXG is the bitwise inclusive OR of S_IRGRPS_IWGRP, and S_IXGRP.

 

 

 Mask  Other Permissions (same as owner's on DOS, OS/2 or Windows NT)
 S_IRWXO  Read, write, search (if a directory), or execute (otherwise)
 S_IROTH  Read permission bit
 S_IWOTH  Write permission bit
 S_IXOTH  Search/execute permission bit

 

S_IRWXO is the bitwise inclusive OR of S_IROTH, S_IWOTH, and S_IXOTH.

 

 

 Mask  Meaning
 S_ISUID  (Not supported by DOS, OS/2 or Windows NT) Set user ID on execution. The process's effective user ID shall be set to that of the owner of the file when the file is run as a program. On a regular file, this bit should be cleared on any write. 
 S_ISGID  (Not supported by DOS, OS/2 or Windows NT) Set group ID on execution. Set effective group ID on the process to the file's group when the file is run as a program. On a regular file, this bit should be cleared on any write.

 


Returns : The stat function returns zero when the information is successfully obtained. Otherwise, -1 is returned.

 

 

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

 Constant  Meaning
 EACCES  Search permission is denied for a component of path.

 

 

See Also : fstat

 


Example :

#include <stdio.h> 

#include <sys\stat.h>


void main( )

{
    struct stat buf;


    if( stat( "file", &buf ) != -1 ) {
        printf( "File size = %d\n", buf.st_size );

    }

}

 

Classification : POSIX 1003.1
Systems : All

 

 

 

 

 

 

 

_status87

 

Synopsis : #include <float.h> 

              unsigned int _status87( void );

 


Description : The _status87 function returns the floating-point status word which is used to record the status of 8087/80287/80387/80486 floating-point operations.

 

 

Returns : The _status87 function returns the floating-point status word which is used to record the status of 8087/80287/80387/80486 floating-point operations. The description of this status is found in the <float.h> header file.

 

 

See Also : _clear87, _control87, _fpreset

 


Example :

#include <stdio.h> 

#include <float.h>


char *status[2] = { "No", " " };


void main( )

{
    unsigned int fp_status;


    fp_status = _status87( );


    printf( "80x87 status\n" );

    printf( "%s invalid operation\n", status[ (fp_status & SW_INVALID) == 0 ] ); 

    printf( "%s denormalized operand\n", status[ (fp_status & SW_DENORMAL) == 0 ] ); 

    printf( "%s divide by zero\n", status[ (fp_status & SW_ZERODIVIDE) == 0 ] ); 

    printf( "%s overflow\n", status[ (fp_status & SW_OVERFLOW) == 0 ] ); 

    printf( "%s underflow\n", status[ (fp_status & SW_UNDERFLOW) == 0 ] ); 

    printf( "%s inexact result\n", status[ (fp_status & SW_INEXACT) == 0 ] );

}

 

Classification : Intel
Systems : All

 

 

 

 

 

 

 

strcat, _fstrcat

 

Synopsis : #include <string.h> 

              char *strcat( char *dst, const char *src );

              char __far *_fstrcat( char  __far *dst, const char __far *src );

 


Description : The strcat and _fstrcat functions append a copy of the string pointed to by src (including the terminating null character) to the end of the string pointed to by dst. The first character of src overwrites the null character at the end of dst.

 

The _fstrcat function is a data model independent form of the strcat function. It accepts far pointer arguments and returns a far pointer. It is most useful in mixed memory model applications.

 

 

Returns : The value of dst is returned.

 

 

See Also : strncat

 


Example :

#include <stdio.h> 

#include <string.h>


void main( )

{
    char buffer[80];


    strcpy( buffer, "Hello " );

    strcat( buffer, "world" );

    printf( "%s\n", buffer );

}

 


produces the following :
Hello world

 

Classification : strcat is ANSI, _fstrcat is not ANSI
Systems : strcat - All

             _fstrcat - All

 

 

 

 

 

 

 

strchr, _fstrchr

 

Synopsis : #include <string.h> 

              char *strchr( const char *s, int c );

              char __far *_fstrchr( const char __far *s, int c );

 


Description : The strchr and _fstrchr functions locate the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string.

The _fstrchr function is a data model independent form of the strchr function. It accepts far pointer arguments and returns a far pointer. It is most useful in mixed memory model applications.

 

 

Returns : The strchr and _fstrchr functions return a pointer to the located character, or NULL if the character does not occur in the string.

 

 

See Also : memchr, strcspn, strrchr, strspn, strstr, strtok

 


Example :

#include <stdio.h> 

#include <string.h>


void main( )

{
    char     buffer[80];

    char     *where;


    strcpy( buffer, "video x-rays" );

    where = strchr( buffer, 'x' );

    if( where == NULL ) {
        printf( "'x' not found\n" );

    }

}

 

Classification : strchr is ANSI, _fstrchr is not ANSI
Systems : strchr - All 

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