Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
u010088926
rt-thread
提交
e0f45a6c
R
rt-thread
项目概览
u010088926
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e0f45a6c
编写于
10月 28, 2021
作者:
G
guo
提交者:
GitHub
10月 28, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5239 from mysterywolf/POSIX
[libc] 消除代码中将RT_LIBC_USING_FILEIO的预编译判断条件
上级
ddaa8f3f
4b9fb8f3
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
61 addition
and
90 deletion
+61
-90
components/libc/compilers/armlibc/syscalls.c
components/libc/compilers/armlibc/syscalls.c
+21
-21
components/libc/compilers/dlib/SConscript
components/libc/compilers/dlib/SConscript
+1
-1
components/libc/compilers/dlib/syscall_close.c
components/libc/compilers/dlib/syscall_close.c
+2
-2
components/libc/compilers/dlib/syscall_lseek.c
components/libc/compilers/dlib/syscall_lseek.c
+2
-2
components/libc/compilers/dlib/syscall_open.c
components/libc/compilers/dlib/syscall_open.c
+2
-2
components/libc/compilers/dlib/syscall_read.c
components/libc/compilers/dlib/syscall_read.c
+2
-2
components/libc/compilers/dlib/syscall_write.c
components/libc/compilers/dlib/syscall_write.c
+6
-6
components/libc/compilers/gcc/newlib/libc.h
components/libc/compilers/gcc/newlib/libc.h
+2
-0
components/libc/compilers/gcc/newlib/stdio.c
components/libc/compilers/gcc/newlib/stdio.c
+6
-37
components/libc/compilers/gcc/newlib/syscalls.c
components/libc/compilers/gcc/newlib/syscalls.c
+17
-17
未找到文件。
components/libc/compilers/armlibc/syscalls.c
浏览文件 @
e0f45a6c
...
...
@@ -54,7 +54,7 @@ const char __stderr_name[] = "STDERR";
*/
FILEHANDLE
_sys_open
(
const
char
*
name
,
int
openmode
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
fd
;
int
mode
=
O_RDONLY
;
#endif
...
...
@@ -67,7 +67,7 @@ FILEHANDLE _sys_open(const char *name, int openmode)
if
(
strcmp
(
name
,
__stderr_name
)
==
0
)
return
(
STDERR
);
#ifndef RT_
LIBC_USING_FILEIO
#ifndef RT_
USING_POSIX
return
0
;
/* error */
#else
/* Correct openmode from fopen to open */
...
...
@@ -101,19 +101,19 @@ FILEHANDLE _sys_open(const char *name, int openmode)
return
0
;
/* error */
else
return
fd
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_sys_close
(
FILEHANDLE
fh
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
if
(
fh
<=
STDERR
)
return
0
;
/* error */
return
close
(
fh
);
#else
return
0
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
/*
...
...
@@ -143,7 +143,7 @@ int _sys_close(FILEHANDLE fh)
*/
int
_sys_read
(
FILEHANDLE
fh
,
unsigned
char
*
buf
,
unsigned
len
,
int
mode
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
size
;
if
(
fh
==
STDIN
)
...
...
@@ -168,7 +168,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
return
0
;
/* error */
#else
return
0
;
/* error */
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
/*
...
...
@@ -178,13 +178,13 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
*/
int
_sys_write
(
FILEHANDLE
fh
,
const
unsigned
char
*
buf
,
unsigned
len
,
int
mode
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
size
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
if
((
fh
==
STDOUT
)
||
(
fh
==
STDERR
))
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
if
(
libc_stdio_get_console
()
<
0
)
{
LOG_W
(
"Do not invoke standard input before initializing libc"
);
...
...
@@ -199,14 +199,14 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
}
return
0
;
/* error */
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
else
if
(
fh
==
STDIN
)
{
return
0
;
/* error */
}
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
size
=
write
(
fh
,
buf
,
len
);
if
(
size
>=
0
)
return
len
-
size
;
...
...
@@ -214,7 +214,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
return
0
;
/* error */
#else
return
0
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
/*
...
...
@@ -223,7 +223,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
*/
int
_sys_seek
(
FILEHANDLE
fh
,
long
pos
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
if
(
fh
<
STDERR
)
return
0
;
/* error */
...
...
@@ -231,7 +231,7 @@ int _sys_seek(FILEHANDLE fh, long pos)
return
lseek
(
fh
,
pos
,
0
);
#else
return
0
;
/* error */
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
/**
...
...
@@ -276,7 +276,7 @@ RT_WEAK void _sys_exit(int return_code)
*/
long
_sys_flen
(
FILEHANDLE
fh
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
struct
stat
stat
;
if
(
fh
<
STDERR
)
...
...
@@ -286,7 +286,7 @@ long _sys_flen(FILEHANDLE fh)
return
stat
.
st_size
;
#else
return
0
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_sys_istty
(
FILEHANDLE
fh
)
...
...
@@ -299,11 +299,11 @@ int _sys_istty(FILEHANDLE fh)
int
remove
(
const
char
*
filename
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
return
unlink
(
filename
);
#else
return
0
;
/* error */
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
#ifdef __MICROLIB
...
...
@@ -324,7 +324,7 @@ int fputc(int c, FILE *f)
int
fgetc
(
FILE
*
f
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
char
ch
;
if
(
libc_stdio_get_console
()
<
0
)
...
...
@@ -335,7 +335,7 @@ int fgetc(FILE *f)
if
(
read
(
STDIN_FILENO
,
&
ch
,
1
)
==
1
)
return
ch
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
return
0
;
/* error */
}
...
...
components/libc/compilers/dlib/SConscript
浏览文件 @
e0f45a6c
...
...
@@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC']
if
rtconfig
.
PLATFORM
==
'iar'
:
if
GetDepend
(
'RT_
LIBC_USING_FILEIO
'
):
if
GetDepend
(
'RT_
USING_POSIX
'
):
from
distutils.version
import
LooseVersion
from
iar
import
IARVersion
...
...
components/libc/compilers/dlib/syscall_close.c
浏览文件 @
e0f45a6c
...
...
@@ -18,9 +18,9 @@ int __close(int handle)
handle
==
_LLIO_STDERR
||
handle
==
_LLIO_STDIN
)
return
_LLIO_ERROR
;
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
return
close
(
handle
);
#else
return
_LLIO_ERROR
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
components/libc/compilers/dlib/syscall_lseek.c
浏览文件 @
e0f45a6c
...
...
@@ -18,9 +18,9 @@ long __lseek(int handle, long offset, int whence)
handle
==
_LLIO_STDERR
||
handle
==
_LLIO_STDIN
)
return
_LLIO_ERROR
;
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
return
lseek
(
handle
,
offset
,
whence
);
#else
return
_LLIO_ERROR
;
#endif
#endif
/* RT_USING_POSIX */
}
components/libc/compilers/dlib/syscall_open.c
浏览文件 @
e0f45a6c
...
...
@@ -16,7 +16,7 @@
int
__open
(
const
char
*
filename
,
int
mode
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
handle
;
int
open_mode
=
O_RDONLY
;
...
...
@@ -68,5 +68,5 @@ int __open(const char *filename, int mode)
return
handle
;
#else
return
_LLIO_ERROR
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
components/libc/compilers/dlib/syscall_read.c
浏览文件 @
e0f45a6c
...
...
@@ -20,7 +20,7 @@
#pragma module_name = "?__read"
size_t
__read
(
int
handle
,
unsigned
char
*
buf
,
size_t
len
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
size
;
if
(
handle
==
_LLIO_STDIN
)
...
...
@@ -41,5 +41,5 @@ size_t __read(int handle, unsigned char *buf, size_t len)
return
size
;
#else
return
_LLIO_ERROR
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
components/libc/compilers/dlib/syscall_write.c
浏览文件 @
e0f45a6c
...
...
@@ -21,13 +21,13 @@
size_t
__write
(
int
handle
,
const
unsigned
char
*
buf
,
size_t
len
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
size
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
if
((
handle
==
_LLIO_STDOUT
)
||
(
handle
==
_LLIO_STDERR
))
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
if
(
libc_stdio_get_console
()
<
0
)
{
LOG_W
(
"Do not invoke standard output before initializing libc"
);
...
...
@@ -46,17 +46,17 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
return
len
;
#else
return
_LLIO_ERROR
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
else
if
(
handle
==
_LLIO_STDIN
)
{
return
_LLIO_ERROR
;
}
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
size
=
write
(
handle
,
buf
,
len
);
return
size
;
#else
return
_LLIO_ERROR
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
components/libc/compilers/gcc/newlib/libc.h
浏览文件 @
e0f45a6c
...
...
@@ -15,11 +15,13 @@ extern "C" {
#endif
int
libc_system_init
(
void
);
#ifdef RT_USING_POSIX
int
libc_stdio_get_console
(
void
);
int
libc_stdio_set_console
(
const
char
*
device_name
,
int
mode
);
#endif
/* RT_USING_POSIX */
#ifdef __cplusplus
}
#endif
...
...
components/libc/compilers/gcc/newlib/stdio.c
浏览文件 @
e0f45a6c
...
...
@@ -7,16 +7,14 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#include <rtthread.h>
#include <rtconfig.h>
#ifdef RT_USING_POSIX
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "libc.h"
#define STDIO_DEVICE_NAME_MAX 32
#ifdef RT_LIBC_USING_FILEIO
#include <stdlib.h>
static
FILE
*
std_console
=
NULL
;
int
libc_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
...
...
@@ -76,7 +74,8 @@ int libc_stdio_set_console(const char* device_name, int mode)
_GLOBAL_REENT
->
__sdidinit
=
1
;
}
if
(
std_console
)
return
fileno
(
std_console
);
if
(
std_console
)
return
fileno
(
std_console
);
return
-
1
;
}
...
...
@@ -89,34 +88,4 @@ int libc_stdio_get_console(void)
return
-
1
;
}
#elif defined(RT_USING_POSIX)
#include <unistd.h>
static
int
std_fd
=
-
1
;
int
libc_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
{
int
fd
;
char
name
[
STDIO_DEVICE_NAME_MAX
];
snprintf
(
name
,
sizeof
(
name
)
-
1
,
"/dev/%s"
,
device_name
);
name
[
STDIO_DEVICE_NAME_MAX
-
1
]
=
'\0'
;
fd
=
open
(
name
,
mode
,
0
);
if
(
fd
>=
0
)
{
if
(
std_fd
>=
0
)
{
close
(
std_fd
);
}
std_fd
=
fd
;
}
return
std_fd
;
}
int
libc_stdio_get_console
(
void
)
{
return
std_fd
;
}
#endif
/* RT_LIBC_USING_FILEIO */
#endif
/* RT_USING_POSIX */
components/libc/compilers/gcc/newlib/syscalls.c
浏览文件 @
e0f45a6c
...
...
@@ -14,6 +14,7 @@
#include <reent.h>
#include <rtthread.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
...
...
@@ -175,7 +176,7 @@ int flock(int fd, int operation)
_off_t
_lseek_r
(
struct
_reent
*
ptr
,
int
fd
,
_off_t
pos
,
int
whence
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
_off_t
rc
;
rc
=
lseek
(
fd
,
pos
,
whence
);
...
...
@@ -183,12 +184,12 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_mkdir_r
(
struct
_reent
*
ptr
,
const
char
*
name
,
int
mode
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
rc
;
rc
=
mkdir
(
name
,
mode
);
...
...
@@ -196,25 +197,24 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode)
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_open_r
(
struct
_reent
*
ptr
,
const
char
*
file
,
int
flags
,
int
mode
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
rc
;
rc
=
open
(
file
,
flags
,
mode
);
return
rc
;
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
_ssize_t
_read_r
(
struct
_reent
*
ptr
,
int
fd
,
void
*
buf
,
size_t
nbytes
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
_ssize_t
rc
;
if
(
libc_stdio_get_console
()
<
0
&&
fd
==
STDIN_FILENO
)
{
...
...
@@ -226,12 +226,12 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_rename_r
(
struct
_reent
*
ptr
,
const
char
*
old
,
const
char
*
new
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
rc
;
rc
=
rename
(
old
,
new
);
...
...
@@ -239,12 +239,12 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new)
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_stat_r
(
struct
_reent
*
ptr
,
const
char
*
file
,
struct
stat
*
pstat
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
int
rc
;
rc
=
stat
(
file
,
pstat
);
...
...
@@ -252,22 +252,22 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
int
_unlink_r
(
struct
_reent
*
ptr
,
const
char
*
file
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
return
unlink
(
file
);
#else
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
}
_ssize_t
_write_r
(
struct
_reent
*
ptr
,
int
fd
,
const
void
*
buf
,
size_t
nbytes
)
{
#ifdef RT_
LIBC_USING_FILEIO
#ifdef RT_
USING_POSIX
_ssize_t
rc
;
if
(
libc_stdio_get_console
()
<
0
&&
fd
==
STDOUT_FILENO
)
{
...
...
@@ -285,7 +285,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
if
(
console
)
return
rt_device_write
(
console
,
-
1
,
buf
,
nbytes
);
}
#endif
/* RT_
LIBC_USING_FILEIO
*/
#endif
/* RT_
USING_POSIX
*/
ptr
->
_errno
=
ENOTSUP
;
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录