PatchworkOS
966e257
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
puts.c
Go to the documentation of this file.
1
#include <
stdio.h
>
2
3
#include "
user/common/file.h
"
4
5
int
puts
(
const
char
*
_RESTRICT
s)
6
{
7
mtx_lock
(&
stdout
->
mtx
);
8
9
if
(
_file_prepare_write
(
stdout
) ==
ERR
)
10
{
11
mtx_unlock
(&
stdout
->
mtx
);
12
return
EOF
;
13
}
14
15
while
(*s !=
'\0'
)
16
{
17
stdout
->
buf
[
stdout
->
bufIndex
++] = *s++;
18
19
if
(
stdout
->
bufIndex
==
stdout
->
bufSize
)
20
{
21
if
(
_file_flush_buffer
(
stdout
) ==
ERR
)
22
{
23
mtx_unlock
(&
stdout
->
mtx
);
24
return
EOF
;
25
}
26
}
27
}
28
29
stdout
->
buf
[
stdout
->
bufIndex
++] =
'\n'
;
30
31
if
((
stdout
->
bufIndex
==
stdout
->
bufSize
) || (
stdout
->
flags
& (
_FILE_LINE_BUFFERED
|
_FILE_UNBUFFERED
)))
32
{
33
uint64_t
result =
_file_flush_buffer
(
stdout
);
34
mtx_unlock
(&
stdout
->
mtx
);
35
return
result ==
ERR
?
EOF
: 0;
36
}
37
else
38
{
39
mtx_unlock
(&
stdout
->
mtx
);
40
return
0;
41
}
42
}
ERR
#define ERR
Integer error value.
Definition
ERR.h:17
_RESTRICT
#define _RESTRICT
Definition
config.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
puts
int puts(const char *_RESTRICT s)
Definition
puts.c:5
file.h
_FILE_UNBUFFERED
@ _FILE_UNBUFFERED
Definition
file.h:18
_FILE_LINE_BUFFERED
@ _FILE_LINE_BUFFERED
Definition
file.h:17
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
stdio.h
EOF
#define EOF
Definition
stdio.h:25
stdout
FILE * stdout
Definition
std_streams.c:18
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
puts.c
Generated on Mon Dec 15 2025 21:55:53 for PatchworkOS by
1.9.8