From 9f23a1d7c1e27c556ef9787b9d3f263f5c1ecf24 Mon Sep 17 00:00:00 2001 From: Marek Vrbka Date: Tue, 30 May 2023 14:16:38 +0200 Subject: [PATCH 1/1] semihosting: fix non-zero value on Windows isatty() On Windows, isatty() can return any non-zero value if it's an interactive device. Which diverges from the ARM semihosting specification. This patch introduces a fix to make the SYS_ISTTY operation conform to spec. Change-Id: I9bc4f3cb82370812825d52419851910b3e3f35cc Signed-off-by: Marek Vrbka Reviewed-on: https://review.openocd.org/c/openocd/+/7725 Reviewed-by: Antonio Borneo Tested-by: jenkins Reviewed-by: Jan Matyas --- src/target/semihosting_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index 3ed112ba94..6c91876c73 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -779,7 +779,8 @@ int semihosting_common(struct target *target) if (retval != ERROR_OK) return retval; int fd = semihosting_get_field(target, 0, fields); - semihosting->result = isatty(fd); + // isatty() on Windows may return any non-zero value if fd is a terminal + semihosting->result = isatty(fd) ? 1 : 0; semihosting->sys_errno = errno; LOG_DEBUG("isatty(%d)=%" PRId64, fd, semihosting->result); } -- 2.30.2