[libc][keil] fix the bug of _sys_read and _sys_write

This commit is contained in:
Meco Man 2021-12-01 02:19:15 -05:00
parent 43ebe094e3
commit 7b1f65a690
1 changed files with 12 additions and 4 deletions

View File

@ -156,22 +156,26 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
return 0; /* error, but keep going */ return 0; /* error, but keep going */
} }
size = read(STDIN_FILENO, buf, len); size = read(STDIN_FILENO, buf, len);
return 0; /* success */ return len - size; /* success */
#else #else
return 0; /* error */ return 0; /* error */
#endif /* RT_USING_POSIX_DEVIO */ #endif /* RT_USING_POSIX_DEVIO */
} }
else if (fh == STDOUT || fh == STDERR) else if (fh == STDOUT || fh == STDERR)
{ {
return 0; /* error */ return -1; /* 100% error */
} }
else else
{ {
size = read(fh, buf, len); size = read(fh, buf, len);
if (size >= 0) if (size >= 0)
{
return len - size; /* success */ return len - size; /* success */
}
else else
{
return 0; /* error */ return 0; /* error */
}
} }
#else #else
return 0; /* error */ return 0; /* error */
@ -209,16 +213,20 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
} }
else if (fh == STDIN) else if (fh == STDIN)
{ {
return 0; /* error */ return -1; /* 100% error */
} }
else else
{ {
#ifdef DFS_USING_POSIX #ifdef DFS_USING_POSIX
size = write(fh, buf, len); size = write(fh, buf, len);
if (size >= 0) if (size >= 0)
return 0; /* success */ {
return len - size; /* success */
}
else else
{
return 0; /* error */ return 0; /* error */
}
#else #else
return 0; /* error */ return 0; /* error */
#endif /* DFS_USING_POSIX */ #endif /* DFS_USING_POSIX */