[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Implement ttyname() for OS/2
From: |
KO Myung-Hun |
Subject: |
[PATCH] Implement ttyname() for OS/2 |
Date: |
Tue, 17 Jan 2023 20:54:19 +0900 |
OS/2 kLIBC has a declaration, but has not implemented.
* Makefile.am [OS/2]: define OS2ENV.
* configure.ac [OS/2]: define os2_SRCS.
* src/os2_ttyname.c: Implement ttyname() for OS/2.
---
Makefile.am | 6 ++++++
configure.ac | 9 ++++++++
src/os2_ttyname.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+)
create mode 100644 src/os2_ttyname.c
diff --git a/Makefile.am b/Makefile.am
index 686851ff..e8570985 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,6 +51,8 @@ vms_SRCS = src/vms_exit.c src/vms_export_symbol.c
src/vms_progname.c \
amiga_SRCS = src/amiga.c src/amiga.h
+os2_SRCS = src/os2_ttyname.c
+
glob_SRCS = lib/fnmatch.c lib/fnmatch.h lib/glob.c lib/glob.h
alloca_SRCS = lib/alloca.c
@@ -90,6 +92,10 @@ else
make_SOURCES += src/posixos.c
endif
+if OS2ENV
+ make_SOURCES += $(os2_SRCS)
+endif
+
if USE_CUSTOMS
make_SOURCES += src/remote-cstms.c
else
diff --git a/configure.ac b/configure.ac
index f5781853..e0eca7e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -449,6 +449,15 @@ AS_CASE([$host],
AC_DEFINE([HAVE_DOS_PATHS], [1], [Support DOS-style pathnames.])
])
+os2_target_env=no
+AM_CONDITIONAL([OS2ENV], [false])
+
+AS_CASE([$host],
+ [*-*-os2*],
+ [AM_CONDITIONAL([OS2ENV], [true])
+ os2_target_env=yes
+ ])
+
AC_DEFINE_UNQUOTED([PATH_SEPARATOR_CHAR],['$PATH_SEPARATOR'],
[Define to the character that separates directories in PATH.])
diff --git a/src/os2_ttyname.c b/src/os2_ttyname.c
new file mode 100644
index 00000000..36a79599
--- /dev/null
+++ b/src/os2_ttyname.c
@@ -0,0 +1,53 @@
+/* ttyname() implementation for OS/2
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+This file is part of GNU Make.
+
+GNU Make is free software; you can redistribute it and/or modify it under the
+terms of the GNU General Public License as published by the Free Software
+Foundation; either version 3 of the License, or (at your option) any later
+version.
+
+GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include "makeint.h"
+
+#define INCL_DOS
+#include <os2.h>
+
+#include <unistd.h>
+
+/* OS/2 kLIBC has a declaration for ttyname(), but has not implemented. */
+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) == 3)
+ return (char *) "/dev/con";
+
+ if ((attr & 4) == 4)
+ return (char *) "/dev/nul";
+
+ if ((attr & 8) == 8)
+ return (char *) "/dev/clock$";
+ }
+
+ errno = ENOTTY;
+ return NULL;
+}
--
2.30.0
- [PATCH] Implement ttyname() for OS/2,
KO Myung-Hun <=