Fixed issues with _read_r in MK22FN512xx libc integration code

replace/a4548a0ef9e0ce0156baeb5ae6624ddbd2456ff2
Silvano Seva 2020-12-27 09:18:58 +01:00
rodzic aad19cc41c
commit efb235ae4e
2 zmienionych plików z 15 dodań i 6 usunięć

Wyświetl plik

@ -213,19 +213,28 @@ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
*/
int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
{
int ret = -1;
if(fd == STDIN_FILENO)
{
for(;;)
{
ssize_t r = vcom_readBlock(buf, cnt);
if((r < 0) || (r == (ssize_t)(cnt))) return r;
if((r < 0) || (r == ((ssize_t) cnt)))
{
ret = ((int) r);
break;
}
}
}
else
{
/* If fd is not stdin */
ptr->_errno = EBADF;
ret = -1;
}
/* If fd is not stdin */
ptr->_errno = EBADF;
return -1;
return ret;
}
int _read(int fd, void *buf, size_t cnt)

Wyświetl plik

@ -649,12 +649,12 @@ ssize_t vcom_writeBlock(const void *buf, size_t len)
ssize_t vcom_readBlock(void* buf, size_t len)
{
if((cdcVcom.attach == 1) && (cdcVcom.startTransactions == 1))
if(recvSize != 0)
{
size_t toTransfer = (len < recvSize) ? len : recvSize;
memcpy(buf, recvBuf, toTransfer);
recvSize = 0;
return toTransfer;
return ((ssize_t) toTransfer);
}
return 0;