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 <marek.vrbka@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7725
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Reviewed-by: Jan Matyas <jan.matyas@codasip.com>
This commit is contained in:
Marek Vrbka 2023-05-30 14:16:38 +02:00 committed by Antonio Borneo
parent 71180e6753
commit 9f23a1d7c1
1 changed files with 2 additions and 1 deletions

View File

@ -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);
}