ARM semihosting: fix writing to stdout
authorSpencer Oliver <ntfreak@users.sourceforge.net>
Wed, 27 Jan 2010 21:20:18 +0000 (21:20 +0000)
committerSpencer Oliver <ntfreak@users.sourceforge.net>
Thu, 28 Jan 2010 20:21:31 +0000 (20:21 +0000)
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>
src/helper/system.h
src/target/arm_semihosting.c

index 169df1cb4f28945d062263cd79fe7f5cab479782..af19d018db1dfc41c16e6cfc9b033d107f05a0bc 100644 (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 ---
 
index f4244c84d11c15985590e2abda59317f1db34fb3..1d0acd63142f1aa840ec9278ca4ab4c56b2e39c9 100644 (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;
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)