aboutsummaryrefslogtreecommitdiff
path: root/sys/libc/setbuf.c
blob: 845c9f9dd216bd079057980ba130134b607af49d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/

#define	import_spp
#define	import_libc
#define	import_stdio
#define	import_fset
#include <iraf.h>


/* SETBUF -- Assign a buffer to be used by the i/o system to access a file.
** Should be called after opening the file but before doing any i/o.
*/
void
setbuf (
  FILE	*fp,
  char	*buf
)
{
	void setbuffer();

	setbuffer (fp, buf, BUFSIZ);
}


/* SETBUFFER -- Assign a buffer of arbitrary size to be used by the i/o system
** to access a file.  Should be called after opening the file but before doing
** any i/o.  If the the pointer buf has the value NULL, i/o is unbuffered
** (or as close to unbuffered as we can manage).
*/
void
setbuffer (
  FILE	*fp,
  char	*buf,
  int	size
)
{
	register XINT	fd = fileno(fp);


	if (buf == NULL)
	    c_fseti (fd, F_BUFSIZE, 1);
	else {
	    c_fseti (fd, F_BUFPTR, Memcptr(buf));
	    c_fseti (fd, F_BUFSIZE, size);
	}
}


/* SETLINEBUF -- Set line buffered mode for a file.  A line buffered file
 * buffers each line and flushes it to the output device when newline is
 * seen.  We may be even after doing i/o to the file.
 */
void
setlinebuf (
  FILE	*fp
)
{
	register XINT	fd = fileno(fp);

	extern int  c_fstati();
	extern void c_fseti();


	if (c_fstati (fd, F_BUFSIZE) < SZ_LINE)
	    c_fseti (fd, F_BUFSIZE, SZ_LINE);
	c_fseti (fd, F_FLUSHNL, YES);
}