summaryrefslogtreecommitdiff
path: root/src/stdio/putc_unlocked.c
blob: 4ff4c2e23b19238ebabc01102e4f86d52e784e15 (plain)
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
#if 0

#include <stdio.h>
#include "_stdio.h"
#include "_assert.h"

#ifdef _POSIX_SOURCE
#include <sys/types.h>
#include <unistd.h>
#else
#include "_syscall.h"
#define write(_fd, _buf, _size) __scall3(write, _fd, _buf, _size)
#endif

/** write a character to a file stream with explicit client locking **/

int putc_unlocked(int c, FILE *stream)
{
	unsigned char ch = (unsigned char)c;

	ASSERT_NONNULL(stream);
	
	stream->buf[stream->bpos++] = ch;
	if (stream->bpos == stream->bsize ||
		(stream->bmode == _IOLBF && ch == '\n') ||
		(stream->bmode == _IONBF)) {
		if (write(stream->fd, stream->buf, stream->bpos) < 0) {
			/* errno handled by write() */
			stream->err = 1;
			return EOF;
		}
		stream->bpos = 0;
	}

	return ch;
}

/***
***/

/*
RETURN_SUCCESS(ARGUMENT(c))
RETURN_FAILURE(CONSTANT(EOF))
POSIX(199506)
*/


#endif