Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
35d83be6
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
提交
35d83be6
编写于
11月 24, 2013
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #204 from aozima/pulls
fixed _sys_read()/_sys_write() issues.
上级
6c58f80a
e037d2e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
15 deletion
+44
-15
components/libc/armlibc/stubs.c
components/libc/armlibc/stubs.c
+44
-15
未找到文件。
components/libc/armlibc/stubs.c
浏览文件 @
35d83be6
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
* Change Logs:
* Change Logs:
* Date Author Notes
* Date Author Notes
* 2012-11-23 Yihui The first version
* 2012-11-23 Yihui The first version
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
*/
*/
#include <string.h>
#include <string.h>
...
@@ -45,6 +46,8 @@ const char __stderr_name[] = "STDERR";
...
@@ -45,6 +46,8 @@ const char __stderr_name[] = "STDERR";
*/
*/
FILEHANDLE
_sys_open
(
const
char
*
name
,
int
openmode
)
FILEHANDLE
_sys_open
(
const
char
*
name
,
int
openmode
)
{
{
int
fd
;
/* Register standard Input Output devices. */
/* Register standard Input Output devices. */
if
(
strcmp
(
name
,
__stdin_name
)
==
0
)
if
(
strcmp
(
name
,
__stdin_name
)
==
0
)
return
(
STDIN
);
return
(
STDIN
);
...
@@ -57,7 +60,11 @@ FILEHANDLE _sys_open(const char *name, int openmode)
...
@@ -57,7 +60,11 @@ FILEHANDLE _sys_open(const char *name, int openmode)
return
-
1
;
return
-
1
;
#else
#else
/* TODO: adjust open file mode */
/* TODO: adjust open file mode */
return
open
(
name
,
openmode
,
0
);
fd
=
open
(
name
,
openmode
,
0
);
if
(
fd
<
0
)
return
-
1
;
else
return
fd
+
STDERR
+
1
;
#endif
#endif
}
}
...
@@ -66,10 +73,10 @@ int _sys_close(FILEHANDLE fh)
...
@@ -66,10 +73,10 @@ int _sys_close(FILEHANDLE fh)
#ifndef RT_USING_DFS
#ifndef RT_USING_DFS
return
0
;
return
0
;
#else
#else
if
(
fh
<
3
)
if
(
fh
<
STDERR
)
return
0
;
return
0
;
return
close
(
fh
);
return
close
(
fh
-
STDERR
-
1
);
#endif
#endif
}
}
...
@@ -80,21 +87,30 @@ int _sys_close(FILEHANDLE fh)
...
@@ -80,21 +87,30 @@ int _sys_close(FILEHANDLE fh)
* @param buf - buffer to save read data
* @param buf - buffer to save read data
* @param len - max length of data buffer
* @param len - max length of data buffer
* @param mode - useless, for historical reasons
* @param mode - useless, for historical reasons
* @return
actual read data length
* @return
The number of bytes not read.
*/
*/
int
_sys_read
(
FILEHANDLE
fh
,
unsigned
char
*
buf
,
unsigned
len
,
int
mode
)
int
_sys_read
(
FILEHANDLE
fh
,
unsigned
char
*
buf
,
unsigned
len
,
int
mode
)
{
{
int
size
;
if
(
fh
==
STDIN
)
if
(
fh
==
STDIN
)
{
{
/* TODO */
/* TODO */
return
0
;
return
0
;
}
}
if
((
fh
==
STDOUT
)
||
(
fh
==
STDERR
))
return
-
1
;
#ifndef RT_USING_DFS
#ifndef RT_USING_DFS
return
0
;
return
0
;
#else
#else
return
read
(
fh
,
buf
,
len
);
size
=
read
(
fh
-
STDERR
-
1
,
buf
,
len
);
if
(
size
>=
0
)
return
len
-
size
;
else
return
-
1
;
#endif
#endif
}
}
...
@@ -105,10 +121,12 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
...
@@ -105,10 +121,12 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
* @param buf - data buffer
* @param buf - data buffer
* @param len - buffer length
* @param len - buffer length
* @param mode - useless, for historical reasons
* @param mode - useless, for historical reasons
* @return a
ctual written data length
* @return a
positive number representing the number of characters not written.
*/
*/
int
_sys_write
(
FILEHANDLE
fh
,
const
unsigned
char
*
buf
,
unsigned
len
,
int
mode
)
int
_sys_write
(
FILEHANDLE
fh
,
const
unsigned
char
*
buf
,
unsigned
len
,
int
mode
)
{
{
int
size
;
if
((
fh
==
STDOUT
)
||
(
fh
==
STDERR
))
if
((
fh
==
STDOUT
)
||
(
fh
==
STDERR
))
{
{
#ifndef RT_USING_CONSOLE
#ifndef RT_USING_CONSOLE
...
@@ -122,11 +140,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
...
@@ -122,11 +140,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
return
len
;
return
len
;
#endif
#endif
}
}
if
(
fh
==
STDIN
)
return
-
1
;
#ifndef RT_USING_DFS
#ifndef RT_USING_DFS
return
0
;
return
0
;
#else
#else
return
write
(
fh
,
buf
,
len
);
size
=
write
(
fh
-
STDERR
-
1
,
buf
,
len
);
if
(
size
>=
0
)
return
len
-
size
;
else
return
-
1
;
#endif
#endif
}
}
...
@@ -138,11 +163,15 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
...
@@ -138,11 +163,15 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
*/
*/
int
_sys_seek
(
FILEHANDLE
fh
,
long
pos
)
int
_sys_seek
(
FILEHANDLE
fh
,
long
pos
)
{
{
if
(
fh
<
STDERR
)
return
-
1
;
#ifndef RT_USING_DFS
#ifndef RT_USING_DFS
return
-
1
;
return
-
1
;
#else
#else
/* position is relative to the start of file fh */
/* position is relative to the start of file fh */
return
lseek
(
fh
,
pos
,
0
);
return
lseek
(
fh
-
STDERR
-
1
,
pos
,
0
);
#endif
#endif
}
}
...
@@ -162,7 +191,7 @@ char *_sys_command_string(char *cmd, int len)
...
@@ -162,7 +191,7 @@ char *_sys_command_string(char *cmd, int len)
void
_ttywrch
(
int
ch
)
void
_ttywrch
(
int
ch
)
{
{
/* TODO */
/* TODO */
}
}
void
_sys_exit
(
int
return_code
)
void
_sys_exit
(
int
return_code
)
...
@@ -172,7 +201,7 @@ void _sys_exit(int return_code)
...
@@ -172,7 +201,7 @@ void _sys_exit(int return_code)
}
}
/**
/**
* return current length of file.
* return current length of file.
*
*
* @param fh - file handle
* @param fh - file handle
* @return file length, or -1 on failed
* @return file length, or -1 on failed
...
@@ -208,7 +237,7 @@ int rename(const char *old, const char *new)
...
@@ -208,7 +237,7 @@ int rename(const char *old, const char *new)
int
system
(
const
char
*
string
)
int
system
(
const
char
*
string
)
{
{
RT_ASSERT
(
0
);
RT_ASSERT
(
0
);
for
(;;);
for
(;;);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录