]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* src/misc.c (ttyname) [OS/2]: Add an implementation for OS/2 kLIBC
authorKO Myung-Hun <komh78@gmail.com>
Sat, 18 Feb 2023 18:43:16 +0000 (13:43 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 19 Feb 2023 06:02:16 +0000 (01:02 -0500)
src/misc.c

index 0d7a44e5696c2df5b6717703daeb33f63c33ec12..eb14f4051dfc99c93284e098b078e7cacef2ef4a 100644 (file)
@@ -28,6 +28,11 @@ this program.  If not, see <https://www.gnu.org/licenses/>.  */
 # include <io.h>
 #endif
 
+#ifdef __EMX__
+# define INCL_DOS
+# include <os2.h>
+#endif
+
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #else
@@ -781,6 +786,40 @@ get_tmpfile (char **name)
 }
 \f
 
+#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
+\f
+
 #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.  */