From c8edb618208a854d121ff73c0d82d7cc467a3611 Mon Sep 17 00:00:00 2001
From: Ariadne Conill <ariadne@ariadne.space>
Date: Fri, 25 Jul 2025 02:13:19 -0700
Subject: [PATCH] ada: libgnarl: use posix_openpt instead of glibc-specific
 getpt to open a pty

musl only implements posix_openpt(3), not the older glibc-specific getpt()
and glibc implements both for ages.

Signed-off-by: Ariadne Conill <ariadne@ariadne.space>
---
 gcc/ada/terminals.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/terminals.c b/gcc/ada/terminals.c
index 89f887556c0..93557fe2631 100644
--- a/gcc/ada/terminals.c
+++ b/gcc/ada/terminals.c
@@ -1134,7 +1134,7 @@ __gnat_setup_winsize (void *desc ATTRIBUTE_UNUSED,
 /* POSIX does not specify how to open the master side of a terminal.Several
    methods are available (system specific):
       1- using a cloning device (USE_CLONE_DEVICE)
-      2- getpt                  (USE_GETPT)
+      2- posix_openpt           (USE_POSIX_OPENPT)
       3- openpty                (USE_OPENPTY)
 
    When using the cloning device method, the macro USE_CLONE_DEVICE should
@@ -1148,7 +1148,7 @@ __gnat_setup_winsize (void *desc ATTRIBUTE_UNUSED,
 #if defined (__APPLE__) || defined (BSD)
 #define USE_OPENPTY
 #elif defined (__linux__)
-#define USE_GETPT
+#define USE_POSIX_OPENPT
 #elif defined (__sun__)
 #define USE_CLONE_DEVICE "/dev/ptmx"
 #elif defined (_AIX)
@@ -1197,8 +1197,8 @@ allocate_pty_desc (pty_desc **desc) {
    int  master_fd   = -1;
    char *slave_name = NULL;
 
-#ifdef USE_GETPT
-  master_fd = getpt ();
+#if defined(USE_POSIX_OPENPT)
+  master_fd = posix_openpt(O_RDWR | O_NOCTTY);
 #elif defined (USE_OPENPTY)
   status = openpty (&master_fd, &slave_fd, NULL, NULL, NULL);
 #elif defined (USE_CLONE_DEVICE)
-- 
2.50.1

