Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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.

Example:
    #include <stdio.h>
    #include <string.h>
    #include <malloc.h>
    #include <fcntl.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, Netware

See Also:
    alloca, calloc Functions, malloc Functions

See Also: alloca

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson