Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ setvbuf(DOS) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          setvbuf - Allow user control over stream buffering and size.

     Syntax
          #include <stdio.h>

          int setvbuf(stream, buffer, type, size)
          FILE *stream;
          char *buffer;
          int type;
          size_t size;


     Description
          The setvbuf function allows the user to control both
          buffering and buffer size for stream.  The stream must refer
          to an open file that has not been read from or written to
          since it was opened.  The array that buf points to is used
          as the buffer, unless it is NULL, and an automatically
          allocated buffer size -bytes long is used.  The type must be
          _IOLBF, _IOFBF, or _IONBF.  If type is _IOFBF or _IOLBF,
          then size is used as the size of the buffer.  If type is
          _IONBF, then the stream is unbuffered, and size and buf are
          ignored.

          Type     Meaning
          _IOFBF   Full buffering; that is, buffer is used
                   as the buffer and size is used as the
                   size of the buffer.  If buffer is NULL,
                   an automatically allocated buffer size
                   bytes long is used.

          _IOLBF   Same as _IOFBF.

          _IONBF   No buffer is used, regardless of buffer
                   or size.

          The legal values for size are greater than zero and less
          than the maximum integer size.

     Return Value
          The return value for setvbuf is zero if successful, and
          nonzero if an illegal type or buffer size is specified.

     See Also
          setbuf(S), fclose(DOS), fflush(S), fopen(DOS)

     Example
          #include <stdio.h>

          char buf[1024]; FILE *stream1, *stream2; int result;

          main()
           {
                  stream1 = fopen("data1","r");
                  stream2 = fopen("data2","w");
                  if (result = setvbuf(stream1, buf, _IOFBF,
          sizeof(buf)) != 0)

                          printf("Incorrect type or size of
          buffer1\n");
                  else
                          printf("'stream1' now has a buffer of 1024
          bytes\n");

                  if (setvbuf(stream2, NULL, _IONBF, 0) != 0)
                          printf("Incorrect type or size of
          buffer1\n");
                  else
                          printf("'stream2' now has no buffer\n");
           }

          This program opens two streams named stream1 and stream2.
          setvbuf is used to give stream1 a user-defined buffer of
          1024 bytes and stream2 no buffer at all.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026