ARM semihosting: fix writing to stdout
SYS_FLEN would be called before a write on a descriptor to check its size. Currently lseek would fail with -1 when given the stdout/stderr descriptor. Changing to use fstat seems to be the standard way of handling this. Signed-off-by: Spencer Oliver <ntfreak@users.sourceforge.net>
This commit is contained in:
parent
3172be80a3
commit
465a06dfdc
|
@ -50,6 +50,8 @@
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
// --- platform specific headers ---
|
// --- platform specific headers ---
|
||||||
|
|
||||||
|
|
|
@ -230,18 +230,14 @@ static int do_semihosting(struct target *target)
|
||||||
return retval;
|
return retval;
|
||||||
else {
|
else {
|
||||||
int fd = target_buffer_get_u32(target, params+0);
|
int fd = target_buffer_get_u32(target, params+0);
|
||||||
off_t cur = lseek(fd, 0, SEEK_CUR);
|
struct stat buf;
|
||||||
if (cur == (off_t)-1) {
|
result = fstat(fd, &buf);
|
||||||
|
if (result == -1) {
|
||||||
armv4_5->semihosting_errno = errno;
|
armv4_5->semihosting_errno = errno;
|
||||||
result = -1;
|
result = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = lseek(fd, 0, SEEK_END);
|
result = buf.st_size;
|
||||||
armv4_5->semihosting_errno = errno;
|
|
||||||
if (lseek(fd, cur, SEEK_SET) == (off_t)-1) {
|
|
||||||
armv4_5->semihosting_errno = errno;
|
|
||||||
result = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue