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:
Spencer Oliver 2010-01-27 21:20:18 +00:00
parent 3172be80a3
commit 465a06dfdc
2 changed files with 6 additions and 8 deletions

View File

@ -50,6 +50,8 @@
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
// --- platform specific headers ---

View File

@ -230,18 +230,14 @@ static int do_semihosting(struct target *target)
return retval;
else {
int fd = target_buffer_get_u32(target, params+0);
off_t cur = lseek(fd, 0, SEEK_CUR);
if (cur == (off_t)-1) {
struct stat buf;
result = fstat(fd, &buf);
if (result == -1) {
armv4_5->semihosting_errno = errno;
result = -1;
break;
}
result = lseek(fd, 0, SEEK_END);
armv4_5->semihosting_errno = errno;
if (lseek(fd, cur, SEEK_SET) == (off_t)-1) {
armv4_5->semihosting_errno = errno;
result = -1;
}
result = buf.st_size;
}
break;