Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
b08d8672
R
rt-thread
项目概览
RT-Thread
/
rt-thread
8 个月 前同步成功
通知
750
Star
8909
Fork
4735
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
b08d8672
编写于
8月 07, 2023
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[libc][posix/io/stdio] rename libc.c as posix/stdio.c
上级
d862816a
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
130 addition
and
180 deletion
+130
-180
bsp/allwinner/libraries/libos/include/misc/support.h
bsp/allwinner/libraries/libos/include/misc/support.h
+0
-2
bsp/allwinner/libraries/sunxi-hal/hal/source/usb/include/usb_list.h
...ner/libraries/sunxi-hal/hal/source/usb/include/usb_list.h
+0
-1
components/dfs/dfs_v1/src/dfs.c
components/dfs/dfs_v1/src/dfs.c
+1
-1
components/libc/compilers/armlibc/syscalls.c
components/libc/compilers/armlibc/syscalls.c
+3
-3
components/libc/compilers/common/cstdio.c
components/libc/compilers/common/cstdio.c
+0
-87
components/libc/compilers/common/cunistd.c
components/libc/compilers/common/cunistd.c
+34
-0
components/libc/compilers/dlib/syscall_read.c
components/libc/compilers/dlib/syscall_read.c
+2
-2
components/libc/compilers/newlib/syscalls.c
components/libc/compilers/newlib/syscalls.c
+2
-2
components/libc/posix/io/stdio/SConscript
components/libc/posix/io/stdio/SConscript
+2
-18
components/libc/posix/io/stdio/libc.h
components/libc/posix/io/stdio/libc.h
+0
-30
components/libc/posix/io/stdio/posix/stdio.h
components/libc/posix/io/stdio/posix/stdio.h
+9
-7
components/libc/posix/io/stdio/stdio.c
components/libc/posix/io/stdio/stdio.c
+77
-27
未找到文件。
bsp/allwinner/libraries/libos/include/misc/support.h
浏览文件 @
b08d8672
...
...
@@ -21,8 +21,6 @@
#define __SUPPORT_H__
#include <typedef.h>
#include <kapi.h>
#include <libc.h>
/*
* Generic macro to convert pointers to values for comparison purposes.
*/
...
...
bsp/allwinner/libraries/sunxi-hal/hal/source/usb/include/usb_list.h
浏览文件 @
b08d8672
...
...
@@ -25,7 +25,6 @@
#ifndef _USB_LIST_H_
#define _USB_LIST_H_
#include <libc.h>
#include <log.h>
#include <hal_osal.h>
//#include "usb_host_config.h"
...
...
components/dfs/dfs_v1/src/dfs.c
浏览文件 @
b08d8672
...
...
@@ -19,7 +19,7 @@
#endif
#ifdef RT_USING_POSIX_STDIO
#include <
libc
.h>
#include <
posix/stdio
.h>
#endif
/* RT_USING_POSIX_STDIO */
/* Global variables */
...
...
components/libc/compilers/armlibc/syscalls.c
浏览文件 @
b08d8672
...
...
@@ -23,7 +23,7 @@
#include <sys/stat.h>
#include <compiler_private.h>
#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
#include <posix/stdio.h>
#endif
/* RT_USING_POSIX_STDIO */
#define DBG_TAG "armlibc.syscalls"
...
...
@@ -153,7 +153,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
if
(
fh
==
STDIN
)
{
#ifdef RT_USING_POSIX_STDIO
if
(
libc
_stdio_get_console
()
<
0
)
if
(
rt_posix
_stdio_get_console
()
<
0
)
{
LOG_W
(
"Do not invoke standard output before initializing Compiler"
);
return
0
;
/* error, but keep going */
...
...
@@ -375,7 +375,7 @@ int fgetc(FILE *f)
#ifdef RT_USING_POSIX_STDIO
char
ch
;
if
(
libc
_stdio_get_console
()
<
0
)
if
(
rt_posix
_stdio_get_console
()
<
0
)
{
LOG_W
(
"Do not invoke standard output before initializing Compiler"
);
return
0
;
...
...
components/libc/compilers/common/cstdio.c
已删除
100644 → 0
浏览文件 @
d862816a
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2014-05-22 ivanrad implement getline
*/
#include "posix/stdio.h"
#include <stdlib.h>
#include <limits.h>
#include <sys/errno.h>
#ifdef DFS_USING_POSIX
ssize_t
getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
)
{
char
*
cur_pos
,
*
new_lineptr
;
size_t
new_lineptr_len
;
int
c
;
if
(
lineptr
==
NULL
||
n
==
NULL
||
stream
==
NULL
)
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
*
lineptr
==
NULL
)
{
*
n
=
128
;
/* init len */
if
((
*
lineptr
=
(
char
*
)
malloc
(
*
n
))
==
NULL
)
{
errno
=
ENOMEM
;
return
-
1
;
}
}
cur_pos
=
*
lineptr
;
for
(;;)
{
c
=
getc
(
stream
);
if
(
ferror
(
stream
)
||
(
c
==
EOF
&&
cur_pos
==
*
lineptr
))
return
-
1
;
if
(
c
==
EOF
)
break
;
if
((
*
lineptr
+
*
n
-
cur_pos
)
<
2
)
{
if
(
LONG_MAX
/
2
<
*
n
)
{
#ifdef EOVERFLOW
errno
=
EOVERFLOW
;
#else
errno
=
ERANGE
;
/* no EOVERFLOW defined */
#endif
return
-
1
;
}
new_lineptr_len
=
*
n
*
2
;
if
((
new_lineptr
=
(
char
*
)
realloc
(
*
lineptr
,
new_lineptr_len
))
==
NULL
)
{
errno
=
ENOMEM
;
return
-
1
;
}
cur_pos
=
new_lineptr
+
(
cur_pos
-
*
lineptr
);
*
lineptr
=
new_lineptr
;
*
n
=
new_lineptr_len
;
}
*
cur_pos
++
=
(
char
)
c
;
if
(
c
==
delim
)
break
;
}
*
cur_pos
=
'\0'
;
return
(
ssize_t
)(
cur_pos
-
*
lineptr
);
}
ssize_t
getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
return
getdelim
(
lineptr
,
n
,
'\n'
,
stream
);
}
#endif
/* DFS_USING_POSIX */
components/libc/compilers/common/cunistd.c
0 → 100644
浏览文件 @
b08d8672
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-08-16 Meco Man first version
*/
#include <rtthread.h>
#include <unistd.h>
#include <sys/errno.h>
int
isatty
(
int
fd
)
{
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
if
(
fd
==
STDOUT_FILENO
||
fd
==
STDERR_FILENO
)
{
return
1
;
}
#endif
/* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
#ifdef RT_USING_POSIX_STDIO
if
(
fd
==
STDIN_FILENO
)
{
return
1
;
}
#endif
/* RT_USING_POSIX_STDIO */
rt_set_errno
(
ENOTTY
);
return
0
;
}
RTM_EXPORT
(
isatty
);
components/libc/compilers/dlib/syscall_read.c
浏览文件 @
b08d8672
...
...
@@ -12,7 +12,7 @@
#include <LowLevelIOInterface.h>
#include <unistd.h>
#ifdef RT_USING_POSIX_STDIO
#include
"libc.h"
#include
<posix/stdio.h>
#endif
/* RT_USING_POSIX_STDIO */
#include <compiler_private.h>
#define DBG_TAG "dlib.syscall.read"
...
...
@@ -40,7 +40,7 @@ size_t __read(int handle, unsigned char *buf, size_t len)
if
(
handle
==
_LLIO_STDIN
)
{
#ifdef RT_USING_POSIX_STDIO
if
(
libc
_stdio_get_console
()
<
0
)
if
(
rt_posix
_stdio_get_console
()
<
0
)
{
LOG_W
(
"Do not invoke standard input before initializing Compiler"
);
return
0
;
/* error, but keep going */
...
...
components/libc/compilers/newlib/syscalls.c
浏览文件 @
b08d8672
...
...
@@ -21,7 +21,7 @@
#include <sys/errno.h>
#include <sys/stat.h>
#ifdef RT_USING_POSIX_STDIO
#include
"libc.h"
#include
<posix/stdio.h>
#endif
/* RT_USING_POSIX_STDIO */
#ifdef RT_USING_MODULE
#include <dlmodule.h>
...
...
@@ -225,7 +225,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
if
(
fd
==
STDIN_FILENO
)
{
#ifdef RT_USING_POSIX_STDIO
if
(
libc
_stdio_get_console
()
<
0
)
if
(
rt_posix
_stdio_get_console
()
<
0
)
{
LOG_W
(
"Do not invoke standard input before initializing Compiler"
);
return
0
;
...
...
components/libc/posix/io/stdio/SConscript
浏览文件 @
b08d8672
# RT-Thread building script for component
import
os
from
building
import
*
src
=
[]
cwd
=
GetCurrentDir
()
CPPPATH
=
[
cwd
]
group
=
[]
if
GetDepend
(
'RT_USING_POSIX_STDIO'
):
src
+=
[
'libc.c'
]
group
=
DefineGroup
(
'POSIX'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
list
=
os
.
listdir
(
cwd
)
for
d
in
list
:
path
=
os
.
path
.
join
(
cwd
,
d
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
d
,
'SConscript'
))
src
=
[
'stdio.c'
]
group
=
DefineGroup
(
'POSIX'
,
src
,
depend
=
[
'RT_USING_POSIX_STDIO'
],
CPPPATH
=
[
GetCurrentDir
()])
Return
(
'group'
)
components/libc/posix/io/stdio/libc.h
已删除
100644 → 0
浏览文件 @
d862816a
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
#include <rtconfig.h>
#ifdef __cplusplus
extern
"C"
{
#endif
int
libc_system_init
(
void
);
#ifdef RT_USING_POSIX_STDIO
int
libc_stdio_get_console
(
void
);
int
libc_stdio_set_console
(
const
char
*
device_name
,
int
mode
);
#endif
/* RT_USING_POSIX_STDIO */
#ifdef __cplusplus
}
#endif
#endif
components/libc/
compilers/common/include
/posix/stdio.h
→
components/libc/
posix/io/stdio
/posix/stdio.h
浏览文件 @
b08d8672
/*
* Copyright (c) 2006-202
2
, RT-Thread Development Team
* Copyright (c) 2006-202
1
, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 20
22-06-07 Meco Man
first version
* 20
17/10/15 bernard the
first version
*/
#ifndef __POSIX_STDIO_H__
#define __POSIX_STDIO_H__
#include <rtconfig.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef __cplusplus
extern
"C"
{
#endif
#include <stdio.h>
#include <sys/types.h>
#ifdef DFS_USING_POSIX
int
rt_posix_stdio_init
(
void
);
int
rt_posix_stdio_get_console
(
void
);
int
rt_posix_stdio_set_console
(
const
char
*
device_name
,
int
mode
);
ssize_t
getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
);
ssize_t
getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
#endif
/* DFS_USING_POSIX */
#ifdef __cplusplus
}
...
...
components/libc/posix/io/stdio/
libc
.c
→
components/libc/posix/io/stdio/
stdio
.c
浏览文件 @
b08d8672
...
...
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
* 2023/08/07 Meco Man rename as posix/stdio.c
*/
#include <rtthread.h>
...
...
@@ -13,24 +14,24 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/errno.h>
#include "
libc
.h"
#include "
posix/stdio
.h"
#define STDIO_DEVICE_NAME_MAX 32
int
sys_dup2
(
int
oldfd
,
int
new
);
int
libc_system
_init
(
void
)
int
rt_posix_stdio
_init
(
void
)
{
#ifdef RT_USING_POSIX_STDIO
rt_device_t
dev_console
;
dev_console
=
rt_console_get_device
();
if
(
dev_console
)
{
int
fd
=
libc
_stdio_set_console
(
dev_console
->
parent
.
name
,
O_RDWR
);
int
fd
=
rt_posix
_stdio_set_console
(
dev_console
->
parent
.
name
,
O_RDWR
);
if
(
fd
<
0
)
{
return
-
1
;
...
...
@@ -40,15 +41,14 @@ int libc_system_init(void)
sys_dup2
(
fd
,
1
);
sys_dup2
(
fd
,
2
);
}
#endif
/* RT_USING_POSIX_STDIO */
return
0
;
}
INIT_ENV_EXPORT
(
libc_system
_init
);
INIT_ENV_EXPORT
(
rt_posix_stdio
_init
);
#if defined(RT_USING_
POSIX_STDIO) && defined(RT_USING_
NEWLIBC)
#if defined(RT_USING_NEWLIBC)
static
FILE
*
std_console
=
NULL
;
int
libc
_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
int
rt_posix
_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
{
FILE
*
fp
;
char
name
[
STDIO_DEVICE_NAME_MAX
];
...
...
@@ -111,7 +111,7 @@ int libc_stdio_set_console(const char* device_name, int mode)
return
-
1
;
}
int
libc
_stdio_get_console
(
void
)
int
rt_posix
_stdio_get_console
(
void
)
{
if
(
std_console
)
return
fileno
(
std_console
);
...
...
@@ -119,11 +119,11 @@ int libc_stdio_get_console(void)
return
-
1
;
}
#elif defined(RT_USING_
POSIX_STDIO) && defined(RT_USING_
MUSLLIBC)
#elif defined(RT_USING_MUSLLIBC)
static
FILE
*
std_console
=
NULL
;
int
libc
_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
int
rt_posix
_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
{
FILE
*
fp
;
char
name
[
STDIO_DEVICE_NAME_MAX
];
...
...
@@ -159,7 +159,7 @@ int libc_stdio_set_console(const char* device_name, int mode)
return
-
1
;
}
int
libc
_stdio_get_console
(
void
)
int
rt_posix
_stdio_get_console
(
void
)
{
int
ret
=
-
1
;
if
(
std_console
)
...
...
@@ -170,10 +170,10 @@ int libc_stdio_get_console(void)
return
ret
;
}
#el
if defined(RT_USING_POSIX_STDIO)
#el
se
static
int
std_fd
=
-
1
;
int
libc
_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
int
rt_posix
_stdio_set_console
(
const
char
*
device_name
,
int
mode
)
{
int
fd
;
char
name
[
STDIO_DEVICE_NAME_MAX
];
...
...
@@ -194,28 +194,78 @@ int libc_stdio_set_console(const char* device_name, int mode)
return
std_fd
;
}
int
libc
_stdio_get_console
(
void
)
{
int
rt_posix
_stdio_get_console
(
void
)
{
return
std_fd
;
}
#endif
/* defined(RT_USING_
POSIX_STDIO) && defined(RT_USING_
NEWLIBC) */
#endif
/* defined(RT_USING_NEWLIBC) */
int
isatty
(
int
fd
)
ssize_t
getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
)
{
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
if
(
fd
==
STDOUT_FILENO
||
fd
==
STDERR_FILENO
)
char
*
cur_pos
,
*
new_lineptr
;
size_t
new_lineptr_len
;
int
c
;
if
(
lineptr
==
NULL
||
n
==
NULL
||
stream
==
NULL
)
{
return
1
;
errno
=
EINVAL
;
return
-
1
;
}
#endif
#ifdef RT_USING_POSIX_STDIO
if
(
fd
==
STDIN_FILENO
)
if
(
*
lineptr
==
NULL
)
{
return
1
;
*
n
=
128
;
/* init len */
if
((
*
lineptr
=
(
char
*
)
malloc
(
*
n
))
==
NULL
)
{
errno
=
ENOMEM
;
return
-
1
;
}
}
cur_pos
=
*
lineptr
;
for
(;;)
{
c
=
getc
(
stream
);
if
(
ferror
(
stream
)
||
(
c
==
EOF
&&
cur_pos
==
*
lineptr
))
return
-
1
;
if
(
c
==
EOF
)
break
;
if
((
*
lineptr
+
*
n
-
cur_pos
)
<
2
)
{
if
(
LONG_MAX
/
2
<
*
n
)
{
#ifdef EOVERFLOW
errno
=
EOVERFLOW
;
#else
errno
=
ERANGE
;
/* no EOVERFLOW defined */
#endif
return
-
1
;
}
new_lineptr_len
=
*
n
*
2
;
if
((
new_lineptr
=
(
char
*
)
realloc
(
*
lineptr
,
new_lineptr_len
))
==
NULL
)
{
errno
=
ENOMEM
;
return
-
1
;
}
cur_pos
=
new_lineptr
+
(
cur_pos
-
*
lineptr
);
*
lineptr
=
new_lineptr
;
*
n
=
new_lineptr_len
;
}
rt_set_errno
(
ENOTTY
);
return
0
;
*
cur_pos
++
=
(
char
)
c
;
if
(
c
==
delim
)
break
;
}
*
cur_pos
=
'\0'
;
return
(
ssize_t
)(
cur_pos
-
*
lineptr
);
}
ssize_t
getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
return
getdelim
(
lineptr
,
n
,
'\n'
,
stream
);
}
RTM_EXPORT
(
isatty
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录