1 | /* |
---|
2 | * Copyright (c) 1990 The Regents of the University of California. |
---|
3 | * All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms are permitted |
---|
6 | * provided that the above copyright notice and this paragraph are |
---|
7 | * duplicated in all such forms and that any documentation, |
---|
8 | * advertising materials, and other materials related to such |
---|
9 | * distribution and use acknowledge that the software was developed |
---|
10 | * by the University of California, Berkeley. The name of the |
---|
11 | * University may not be used to endorse or promote products derived |
---|
12 | * from this software without specific prior written permission. |
---|
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | FUNCTION |
---|
20 | <<setbuf>>---specify full buffering for a file or stream |
---|
21 | |
---|
22 | INDEX |
---|
23 | setbuf |
---|
24 | |
---|
25 | SYNOPSIS |
---|
26 | #include <stdio.h> |
---|
27 | void setbuf(FILE *<[fp]>, char *<[buf]>); |
---|
28 | |
---|
29 | DESCRIPTION |
---|
30 | <<setbuf>> specifies that output to the file or stream identified by <[fp]> |
---|
31 | should be fully buffered. All output for this file will go to a |
---|
32 | buffer (of size <<BUFSIZ>>, specified in `<<stdio.h>>'). Output will |
---|
33 | be passed on to the host system only when the buffer is full, or when |
---|
34 | an input operation intervenes. |
---|
35 | |
---|
36 | You may, if you wish, supply your own buffer by passing a pointer to |
---|
37 | it as the argument <[buf]>. It must have size <<BUFSIZ>>. You can |
---|
38 | also use <<NULL>> as the value of <[buf]>, to signal that the |
---|
39 | <<setbuf>> function is to allocate the buffer. |
---|
40 | |
---|
41 | WARNINGS |
---|
42 | You may only use <<setbuf>> before performing any file operation other |
---|
43 | than opening the file. |
---|
44 | |
---|
45 | If you supply a non-null <[buf]>, you must ensure that the associated |
---|
46 | storage continues to be available until you close the stream |
---|
47 | identified by <[fp]>. |
---|
48 | |
---|
49 | RETURNS |
---|
50 | <<setbuf>> does not return a result. |
---|
51 | |
---|
52 | PORTABILITY |
---|
53 | Both ANSI C and the System V Interface Definition (Issue 2) require |
---|
54 | <<setbuf>>. However, they differ on the meaning of a <<NULL>> buffer |
---|
55 | pointer: the SVID issue 2 specification says that a <<NULL>> buffer |
---|
56 | pointer requests unbuffered output. For maximum portability, avoid |
---|
57 | <<NULL>> buffer pointers. |
---|
58 | |
---|
59 | Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
---|
60 | <<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
---|
61 | */ |
---|
62 | |
---|
63 | #include <_ansi.h> |
---|
64 | #include <stdio.h> |
---|
65 | #include "local.h" |
---|
66 | |
---|
67 | void |
---|
68 | setbuf (FILE *__restrict fp, |
---|
69 | char *__restrict buf) |
---|
70 | { |
---|
71 | (void) setvbuf (fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); |
---|
72 | } |
---|