From 62194015fa250e62b5534783cdcc2337c3ce6834 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Sat, 18 Feb 2023 13:43:16 -0500 Subject: [PATCH] * src/misc.c (ttyname) [OS/2]: Add an implementation for OS/2 kLIBC --- src/misc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/misc.c b/src/misc.c index 0d7a44e5..eb14f405 100644 --- a/src/misc.c +++ b/src/misc.c @@ -28,6 +28,11 @@ this program. If not, see . */ # include #endif +#ifdef __EMX__ +# define INCL_DOS +# include +#endif + #ifdef HAVE_FCNTL_H # include #else @@ -781,6 +786,40 @@ get_tmpfile (char **name) } +#if HAVE_TTYNAME && defined(__EMX__) +/* OS/2 kLIBC has a declaration for ttyname(), so configure finds it. + But, it is not implemented! Roll our own. */ +char *ttyname (int fd) +{ + ULONG type; + ULONG attr; + ULONG rc; + + rc = DosQueryHType (fd, &type, &attr); + if (rc) + { + errno = EBADF; + return NULL; + } + + if (type == HANDTYPE_DEVICE) + { + if (attr & 3) /* 1 = KBD$, 2 = SCREEN$ */ + return (char *) "/dev/con"; + + if (attr & 4) /* 4 = NUL */ + return (char *) "/dev/nul"; + + if (attr & 8) /* 8 = CLOCK$ */ + return (char *) "/dev/clock$"; + } + + errno = ENOTTY; + return NULL; +} +#endif + + #if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI /* If we don't have strcasecmp() (from POSIX), or anything that can substitute for it, define our own version. */