File tree Expand file tree Collapse file tree 11 files changed +135
-1
lines changed Expand file tree Collapse file tree 11 files changed +135
-1
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,8 @@ if(LLVM_LIBC_FULL_BUILD)
396
396
libc.src.stdio.fwrite
397
397
libc.src.stdio.fwrite_unlocked
398
398
libc.src.stdio.fprintf
399
+ libc.src.stdio.getchar
400
+ libc.src.stdio.getchar_unlocked
399
401
libc.src.stdio.printf
400
402
libc.src.stdio.putc
401
403
libc.src.stdio.putchar
Original file line number Diff line number Diff line change @@ -409,6 +409,8 @@ if(LLVM_LIBC_FULL_BUILD)
409
409
libc.src.stdio.fprintf
410
410
libc.src.stdio.getc
411
411
libc.src.stdio.getc_unlocked
412
+ libc.src.stdio.getchar
413
+ libc.src.stdio.getchar_unlocked
412
414
libc.src.stdio.printf
413
415
libc.src.stdio.sscanf
414
416
libc.src.stdio.scanf
Original file line number Diff line number Diff line change @@ -423,6 +423,8 @@ if(LLVM_LIBC_FULL_BUILD)
423
423
libc.src.stdio.fwrite_unlocked
424
424
libc.src.stdio.getc
425
425
libc.src.stdio.getc_unlocked
426
+ libc.src.stdio.getchar
427
+ libc.src.stdio.getchar_unlocked
426
428
libc.src.stdio.sscanf
427
429
libc.src.stdio.scanf
428
430
libc.src.stdio.fscanf
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ Function Name Available
83
83
============= =========
84
84
(f)getc |check |
85
85
fgets |check |
86
- getchar
86
+ getchar | check |
87
87
fread |check |
88
88
(f)putc |check |
89
89
(f)puts |check |
Original file line number Diff line number Diff line change @@ -1077,6 +1077,11 @@ def POSIX : StandardSpec<"POSIX"> {
1077
1077
RetValSpec<IntType>,
1078
1078
[ArgSpec<FILEPtr>]
1079
1079
>,
1080
+ FunctionSpec<
1081
+ "getchar_unlocked",
1082
+ RetValSpec<IntType>,
1083
+ [ArgSpec<VoidType>]
1084
+ >,
1080
1085
]
1081
1086
>;
1082
1087
Original file line number Diff line number Diff line change @@ -580,6 +580,11 @@ def StdC : StandardSpec<"stdc"> {
580
580
RetValSpec<IntType>,
581
581
[ArgSpec<FILEPtr>]
582
582
>,
583
+ FunctionSpec<
584
+ "getchar",
585
+ RetValSpec<IntType>,
586
+ [ArgSpec<VoidType>]
587
+ >,
583
588
FunctionSpec<
584
589
"putc",
585
590
RetValSpec<IntType>,
Original file line number Diff line number Diff line change @@ -154,6 +154,32 @@ add_entrypoint_object(
154
154
libc.src.__support.File.platform_file
155
155
)
156
156
157
+ add_entrypoint_object (
158
+ getchar
159
+ SRCS
160
+ getchar.cpp
161
+ HDRS
162
+ getchar.h
163
+ DEPENDS
164
+ libc.src.errno.errno
165
+ libc.include.stdio
166
+ libc.src.__support.File.file
167
+ libc.src.__support.File.platform_file
168
+ )
169
+
170
+ add_entrypoint_object (
171
+ getchar_unlocked
172
+ SRCS
173
+ getc_unlocked.cpp
174
+ HDRS
175
+ getc_unlocked.h
176
+ DEPENDS
177
+ libc.src.errno.errno
178
+ libc.include.stdio
179
+ libc.src.__support.File.file
180
+ libc.src.__support.File.platform_file
181
+ )
182
+
157
183
add_entrypoint_object (
158
184
fgets
159
185
SRCS
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation of getchar -----------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #include " src/stdio/getchar.h"
10
+ #include " src/__support/File/file.h"
11
+
12
+ #include " src/errno/libc_errno.h"
13
+ #include < stdio.h>
14
+
15
+ namespace __llvm_libc {
16
+
17
+ LLVM_LIBC_FUNCTION (int , getchar, ()) {
18
+ unsigned char c;
19
+ auto result = stdin->read (&c, 1 );
20
+ if (result.has_error ())
21
+ libc_errno = result.error ;
22
+
23
+ if (result.value != 1 )
24
+ return EOF;
25
+ return c;
26
+ }
27
+
28
+ } // namespace __llvm_libc
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation header of getchar ------------------------*- C++ -*-===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_LIBC_SRC_STDIO_GETCHAR_H
10
+ #define LLVM_LIBC_SRC_STDIO_GETCHAR_H
11
+
12
+ namespace __llvm_libc {
13
+
14
+ int getchar ();
15
+
16
+ } // namespace __llvm_libc
17
+
18
+ #endif // LLVM_LIBC_SRC_STDIO_GETCHAR_H
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation of getchar_unlocked --------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #include " src/stdio/getchar_unlocked.h"
10
+ #include " src/__support/File/file.h"
11
+
12
+ #include " src/errno/libc_errno.h"
13
+ #include < stdio.h>
14
+
15
+ namespace __llvm_libc {
16
+
17
+ LLVM_LIBC_FUNCTION (int , getchar_unlocked, ()) {
18
+ unsigned char c;
19
+ auto result = stdin->read_unlocked (&c, 1 );
20
+ if (result.has_error ())
21
+ libc_errno = result.error ;
22
+
23
+ if (result.value != 1 )
24
+ return EOF;
25
+ return c;
26
+ }
27
+
28
+ } // namespace __llvm_libc
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation header of getchar_unlocked ---------------*- C++ -*-===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_LIBC_SRC_STDIO_GETCHAR_UNLOCKED_H
10
+ #define LLVM_LIBC_SRC_STDIO_GETCHAR_UNLOCKED_H
11
+
12
+ namespace __llvm_libc {
13
+
14
+ int getchar_unlocked ();
15
+
16
+ } // namespace __llvm_libc
17
+
18
+ #endif // LLVM_LIBC_SRC_STDIO_GETCHAR_UNLOCKED_H
You can’t perform that action at this time.
0 commit comments