Skip to content

Commit 7e871b0

Browse files
committed
[LIBC] fix the open mode when using fopen in arm libc.
1 parent a00cc57 commit 7e871b0

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

Diff for: components/libc/armlibc/stubs.c

+32-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ FILEHANDLE _sys_open(const char *name, int openmode)
4848
{
4949
#ifdef RT_USING_DFS
5050
int fd;
51+
int mode = O_RDONLY;
5152
#endif
5253

5354
/* Register standard Input Output devices. */
@@ -61,8 +62,33 @@ FILEHANDLE _sys_open(const char *name, int openmode)
6162
#ifndef RT_USING_DFS
6263
return -1;
6364
#else
64-
/* TODO: adjust open file mode */
65-
fd = open(name, openmode, 0);
65+
/* Correct openmode from fopen to open */
66+
if (openmode & OPEN_PLUS)
67+
{
68+
if (openmode & OPEN_W)
69+
{
70+
mode |= (O_RDWR | O_TRUNC | O_CREAT);
71+
}
72+
else if (openmode & OPEN_A)
73+
{
74+
mode |= (O_RDWR | O_APPEND | O_CREAT);
75+
}
76+
else
77+
mode |= O_RDWR;
78+
}
79+
else
80+
{
81+
if (openmode & OPEN_W)
82+
{
83+
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
84+
}
85+
else if (openmode & OPEN_A)
86+
{
87+
mode |= (O_WRONLY | O_APPEND | O_CREAT);
88+
}
89+
}
90+
91+
fd = open(name, mode, 0);
6692
if(fd < 0)
6793
return -1;
6894
else
@@ -196,7 +222,10 @@ char *_sys_command_string(char *cmd, int len)
196222

197223
void _ttywrch(int ch)
198224
{
199-
/* TODO */
225+
char c;
226+
227+
c = (char)ch;
228+
rt_kprintf(&c);
200229
}
201230

202231
void _sys_exit(int return_code)

0 commit comments

Comments
 (0)