Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>setvbuf() control stream buffering and buffer size</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 setvbuf()               Control Stream Buffering and Buffer Size

 #include   <stdio.h>

 int        setvbuf(stream,buf,type,size);
 FILE       *stream;                     Pointer to FILE structure
 char       *buf;                        User-allocated buffer
 int        type;                        Type of buffer:
 size_t size;                            Size of buffer

    setvbuf() causes 'buf' to be used for I/O buffering instead of the
    automatically allocated buffer, thereby giving the user a way to
    control both buffering and buffer size for a given stream.  'stream'
    must refer to an open file which has not been accessed since being
    opened.  If 'buf' is NULL, and 'type' is _IOFBF or _IOLBF, an
    automatically allocated buffer is used.  It is 'size' bytes long. If
    'type' is _IONBF, the stream is unbuffered; and 'size' and 'buf' are
    ignored.

    If 'buf' is not NULL, 'stream' is buffered and 'type' must be set to
    one of the following:

         _IONBF     No buffer, regardless of arguments 'buf' or 'size'
         _IOFBF     Full buffering (unless 'buf' is NULL); 'buf' is the
                    address of the buffer and 'size' is the buffer size
         _IOLBF     Same as _IOFBF, except it uses line buffering instead
                    of full buffering.

     If 'type' is _IOFBF or _IOLBF, 'size' must be greater than 0 and
    less than the maximum integer size.  If _IONBF is specified, then the
    stream is unbuffered and 'size' and 'buf' are ignored.

    Returns:    Zero if successful.  Non-zero is returned if an illegal
                type or buffer size is specified.

 Compatibility: MSC version 4.0 provided no buffering if 'buf' == NULL.

   -------------------------------- Example ---------------------------------
 The following statements open two files and assign a user-specified buffer
 to one.

           #include <stdio.h>

           FILE *stream1, *stream2;
           char *buf;
           int ret;

           main()
           {
               if ((stream1 = fopen("data","w+")) != NULL &&
                   (stream2 = fopen("update","w+")) != NULL) {
                   if ((ret = setvbuf(stream2,buf,_IOFBF,100)) == 0)
                       printf("stream successfully buffered\n");
                   else printf("unable to buffer stream\n");
               }
           }



See Also: setbuf() fflush() fopen() fclose()

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