blob: f3714af83a520b1d0bf654f3afe3814456c96083 (
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
49
50
51
52
53
54
55
56
|
#include <stdio.h>
#include "_stdio.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;
SIGNAL_SAFE(0);
ASSERT_NONNULL(stream);
if (stream->operation == OP_INPUT) {
UNDEFINED("attempted output on stream immediately after input");
}
stream->operation = OP_OUTPUT;
if (stream->buf == NULL) {
if (write(stream->fd, &ch, 1) != 1) {
stream->err = 1;
return EOF;
}
return ch;
}
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)
*/
|