Skip to content

Commit 7b1f65a

Browse files
committed
[libc][keil] fix the bug of _sys_read and _sys_write
1 parent 43ebe09 commit 7b1f65a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

components/libc/compilers/armlibc/syscalls.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,26 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
156156
return 0; /* error, but keep going */
157157
}
158158
size = read(STDIN_FILENO, buf, len);
159-
return 0; /* success */
159+
return len - size; /* success */
160160
#else
161161
return 0; /* error */
162162
#endif /* RT_USING_POSIX_DEVIO */
163163
}
164164
else if (fh == STDOUT || fh == STDERR)
165165
{
166-
return 0; /* error */
166+
return -1; /* 100% error */
167167
}
168168
else
169169
{
170170
size = read(fh, buf, len);
171171
if (size >= 0)
172+
{
172173
return len - size; /* success */
174+
}
173175
else
176+
{
174177
return 0; /* error */
178+
}
175179
}
176180
#else
177181
return 0; /* error */
@@ -209,16 +213,20 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
209213
}
210214
else if (fh == STDIN)
211215
{
212-
return 0; /* error */
216+
return -1; /* 100% error */
213217
}
214218
else
215219
{
216220
#ifdef DFS_USING_POSIX
217221
size = write(fh, buf, len);
218222
if (size >= 0)
219-
return 0; /* success */
223+
{
224+
return len - size; /* success */
225+
}
220226
else
227+
{
221228
return 0; /* error */
229+
}
222230
#else
223231
return 0; /* error */
224232
#endif /* DFS_USING_POSIX */

0 commit comments

Comments
 (0)