Skip to content

Commit c8c6325

Browse files
committed
[libc][syscall]移除libc_stdio_read/write函数,优化syscall
1 parent 13b0b60 commit c8c6325

File tree

8 files changed

+30
-60
lines changed

8 files changed

+30
-60
lines changed

components/libc/compilers/armlibc/libc.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@
1010
#ifndef __RTT_LIBC_H__
1111
#define __RTT_LIBC_H__
1212

13-
#include <stddef.h>
14-
1513
#ifdef __cplusplus
1614
extern "C" {
1715
#endif
18-
int libc_system_init(void);
1916

20-
int libc_stdio_set_console(const char* device_name, int mode);
17+
int libc_system_init(void);
2118
int libc_stdio_get_console(void);
22-
int libc_stdio_read(void* buffer, size_t size);
23-
int libc_stdio_write(const void* buffer, size_t size);
19+
int libc_stdio_set_console(const char* device_name, int mode);
20+
2421
#ifdef __cplusplus
2522
}
2623
#endif

components/libc/compilers/armlibc/stdio.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define STDIO_DEVICE_NAME_MAX 32
2222

2323
static int std_fd = -1;
24+
2425
int libc_stdio_set_console(const char* device_name, int mode)
2526
{
2627
int fd;
@@ -47,29 +48,4 @@ int libc_stdio_get_console(void)
4748
return std_fd;
4849
}
4950

50-
int libc_stdio_read(void *buffer, size_t size)
51-
{
52-
if (std_fd >= 0)
53-
{
54-
return read(std_fd, buffer, size);
55-
}
56-
else
57-
{
58-
rt_kprintf("Illegal stdio input!\n");
59-
return 0;
60-
}
61-
}
62-
63-
int libc_stdio_write(const void *buffer, size_t size)
64-
{
65-
if (std_fd >= 0)
66-
{
67-
return write(std_fd, buffer, size);
68-
}
69-
else
70-
{
71-
rt_kprintf("Illegal stdio output!\n");
72-
return size;
73-
}
74-
}
7551
#endif

components/libc/compilers/armlibc/syscalls.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,17 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
146146
if (fh == STDIN)
147147
{
148148
#ifdef RT_USING_POSIX
149-
size = libc_stdio_read(buf, len);
149+
size = read(STDIN_FILENO, buf, len);
150150
return len - size;
151151
#else
152152
/* no stdin */
153153
return -1;
154154
#endif
155155
}
156-
157-
if ((fh == STDOUT) || (fh == STDERR))
156+
else if ((fh == STDOUT) || (fh == STDERR))
157+
{
158158
return -1;
159+
}
159160

160161
#ifndef RT_USING_DFS
161162
return 0;
@@ -185,7 +186,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
185186
return 0;
186187
#else
187188
#ifdef RT_USING_POSIX
188-
size = libc_stdio_write(buf, len);
189+
size = write(STDOUT_FILENO, buf, len);
189190
return len - size;
190191
#else
191192
if (rt_console_get_device())
@@ -198,8 +199,10 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
198199
#endif
199200
#endif
200201
}
201-
202-
if (fh == STDIN) return -1;
202+
else if (fh == STDIN)
203+
{
204+
return -1;
205+
}
203206

204207
#ifndef RT_USING_DFS
205208
return 0;

components/libc/compilers/dlib/libc.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
#ifndef __RTT_LIBC_H__
1212
#define __RTT_LIBC_H__
1313

14-
#include <stddef.h>
15-
1614
#ifdef __cplusplus
1715
extern "C" {
1816
#endif
19-
int libc_system_init(void);
2017

21-
int libc_stdio_set_console(const char* device_name, int mode);
18+
int libc_system_init(void);
2219
int libc_stdio_get_console(void);
23-
int libc_stdio_read(void* buffer, size_t size);
24-
int libc_stdio_write(const void* buffer, size_t size);
20+
int libc_stdio_set_console(const char* device_name, int mode);
21+
2522
#ifdef __cplusplus
2623
}
2724
#endif

components/libc/compilers/dlib/stdio.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,4 @@ int libc_stdio_get_console(void) {
4646
return std_fd;
4747
}
4848

49-
int libc_stdio_read(void *buffer, size_t size)
50-
{
51-
return read(std_fd, buffer, size);
52-
}
53-
54-
int libc_stdio_write(const void *buffer, size_t size)
55-
{
56-
return write(std_fd, buffer, size);
57-
}
5849
#endif

components/libc/compilers/dlib/syscall_read.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ size_t __read(int handle, unsigned char *buf, size_t len)
2525
if (handle == _LLIO_STDIN)
2626
{
2727
#ifdef RT_USING_POSIX
28-
return libc_stdio_read(buf, len);
28+
return read(STDIN_FILENO, buf, len);
2929
#else
3030
return _LLIO_ERROR;
3131
#endif
3232
}
33-
34-
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
33+
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
34+
{
3535
return _LLIO_ERROR;
36+
}
3637

3738
#ifndef RT_USING_DFS
3839
return _LLIO_ERROR;

components/libc/compilers/dlib/syscall_write.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,24 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
3030
#else
3131

3232
#ifdef RT_USING_POSIX
33-
return libc_stdio_write((void*)buf, len);
33+
return write(STDOUT_FILENO, (void*)buf, len);
3434
#else
3535
rt_device_t console_device;
3636

3737
console_device = rt_console_get_device();
38-
if (console_device != 0) rt_device_write(console_device, 0, buf, len);
38+
if (console_device != 0)
39+
{
40+
rt_device_write(console_device, 0, buf, len);
41+
}
3942

4043
return len;
4144
#endif
4245
#endif
4346
}
44-
45-
if (handle == _LLIO_STDIN) return _LLIO_ERROR;
47+
else if (handle == _LLIO_STDIN)
48+
{
49+
return _LLIO_ERROR;
50+
}
4651

4752
#ifndef RT_USING_DFS
4853
return _LLIO_ERROR;

components/libc/compilers/newlib/libc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
extern "C" {
1919
#endif
2020
int libc_system_init(void);
21-
int libc_stdio_set_console(const char* device_name, int mode);
2221
int libc_stdio_get_console(void);
22+
int libc_stdio_set_console(const char* device_name, int mode);
2323

2424
#ifdef __cplusplus
2525
}

0 commit comments

Comments
 (0)