File: setvbuf.inc

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (55 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download | duplicates (2)
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
#include <stdio.h>
#include <alloc.h>

#ifdef __cplusplus
extern "C"{
#endif

extern void _Cdecl (*_Cdecl _exitbuf)();
extern void _Cdecl	    _xfflush ();

#ifdef __cplusplus
}
#endif

/* "Check for stack overflow" off for BC++ 3.1 */
/* "Suppress redundant load" on for BC++ 3.1 */
#pragma option -N- -Z

#ifdef __cplusplus
extern "C"
#endif
int _Cdecl setvbuf (FILE *fp, char *buf, int type, size_t sz) {
	if (type == _IONBF)
		sz = 0;

/*	if (fp->token != (short)fp || type > _IONBF || sz > MAX_INT)
 *		return EOF;
 */
	fflush (fp); /* Ensure in no loss of characters */

	if (fp->flags & _F_BUF)
		free (fp->buffer);

	fp->flags &= ~(_F_BUF | _F_LBUF | _F_IN | _F_OUT | _F_EOF),
/*	fp->curp = fp->buffer = &fp->hold,
 */	fp->level = fp->bsize = 0;

	if (sz) {
		if (buf == NULL) {
			if ((buf = (char*) malloc (sz)) == NULL)
				return EOF;
			fp->flags |= _F_BUF;
		}

		if (type == _IOLBF)
			fp->flags |= _F_LBUF;
		fp->curp = fp->buffer = (unsigned char*) buf,
		fp->bsize = sz,
		_exitbuf = _xfflush;
	}

	return 0;
}

#pragma option -N. -Z.