File: setbuf.c

package info (click to toggle)
iraf 2.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,000 kB
  • sloc: ansic: 115,890; fortran: 74,576; lisp: 18,888; yacc: 5,642; sh: 961; lex: 596; makefile: 509; asm: 159; csh: 54; xml: 33; sed: 4
file content (65 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
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
/* 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>

void setbuffer (FILE *fp, char *buf, int size);


/* 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
)
{
	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);


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