6.18.41 setbuf Function
Defines how a stream is buffered.
Include
<stdio.h>
Prototype
void setbuf(FILE * restrict stream, char * restrict buf);
Arguments
stream- pointer to the open stream
buf- user allocated buffer
Remarks
The setbuf function must be called after fopen but before
any other function calls that operate on the stream. If buf is a null
pointer, setbuf calls the function setvbuf(stream, 0, _IONBF,
BUFSIZ) for no buffering; otherwise setbuf calls
setvbuf(stream, buf, _IOFBF, BUFSIZ) for full buffering with a buffer of
size BUFSIZ. See setvbuf.
When building with MPLAB XC16 or XC-DSC, this function requires a heap.
Example
#include <stdio.h>
int main(void)
{
FILE *myfile1, *myfile2;
char buf[BUFSIZ];
if ((myfile1 = fopen("afile1", "w+")) != NULL)
{
setbuf(myfile1, NULL);
printf("myfile1 has no buffering\n");
fclose(myfile1);
}
if ((myfile2 = fopen("afile2", "w+")) != NULL)
{
setbuf(myfile2, buf);
printf("myfile2 has full buffering");
fclose(myfile2);
}
}
Example Output
myfile1 has no buffering
myfile2 has full buffering
This macro is used by the function setbuf.
