PatchworkOS
Loading...
Searching...
No Matches
fputc.c
Go to the documentation of this file.
1
#include <
stdio.h
>
2
#include <
stdlib.h
>
3
4
#include "
user/common/file.h
"
5
#include "
user/common/syscalls.h
"
6
7
int
fputc
(
int
c,
FILE
* stream)
8
{
9
mtx_lock
(&stream->
mtx
);
10
11
if
(
_file_prepare_write
(stream) ==
ERR
)
12
{
13
mtx_unlock
(&stream->
mtx
);
14
return
EOF
;
15
}
16
17
stream->
buf
[stream->
bufIndex
++] = (char)c;
18
if
((stream->
bufIndex
== stream->
bufSize
) || ((stream->
flags
&
_FILE_LINE_BUFFERED
) && ((
char
)c ==
'\n'
)) ||
19
(stream->
flags
&
_FILE_UNBUFFERED
))
20
{
21
// buffer filled, unbuffered stream, or end-of-line.
22
c = (
_file_flush_buffer
(stream) !=
ERR
) ? c :
EOF
;
23
}
24
25
mtx_unlock
(&stream->
mtx
);
26
27
return
c;
28
}
fputc
int fputc(int c, FILE *stream)
Definition
fputc.c:7
ERR
#define ERR
Integer error value.
Definition
ERR.h:17
_file_prepare_write
uint64_t _file_prepare_write(FILE *stream)
Definition
file.c:239
_file_flush_buffer
uint64_t _file_flush_buffer(FILE *stream)
Definition
file.c:158
file.h
_FILE_UNBUFFERED
@ _FILE_UNBUFFERED
Definition
file.h:18
_FILE_LINE_BUFFERED
@ _FILE_LINE_BUFFERED
Definition
file.h:17
syscalls.h
stdio.h
EOF
#define EOF
Definition
stdio.h:25
stdlib.h
FILE
Definition
file.h:34
FILE::buf
uint8_t * buf
Definition
file.h:37
FILE::bufIndex
uint64_t bufIndex
Definition
file.h:39
FILE::bufSize
uint64_t bufSize
Definition
file.h:38
FILE::flags
_file_flags_t flags
Definition
file.h:44
FILE::mtx
mtx_t mtx
Definition
file.h:45
mtx_lock
_PUBLIC int mtx_lock(mtx_t *mtx)
Definition
mtx_lock.c:11
mtx_unlock
_PUBLIC int mtx_unlock(mtx_t *mtx)
Definition
mtx_unlock.c:10
src
libstd
user
functions
stdio
fputc.c
Generated by
1.9.8