diff --git a/src/configure.in b/src/configure.in
index 23f668239840606d92244651fd15bb770b875991..81404eb6e0487e99889d12f1ed53470718d66376 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -4576,6 +4576,7 @@ AC_CHECK_FUNCS( \
  setsid \
  initgroups setgroups \
  socketpair \
+ openpty \
  fpclass \
  fp_class_d \
  isinf \
diff --git a/src/fdlib.h b/src/fdlib.h
index 39a1a2901706b522dc7c4d51e42fd3d6cb6d4d26..d13624f01eb28a13bf996f20b803dfa0888ddf00 100644
--- a/src/fdlib.h
+++ b/src/fdlib.h
@@ -580,6 +580,10 @@ typedef struct my_fd_set_s my_fd_set;
 #define SOCKET_CAPABILITIES (fd_INTERPROCESSABLE | fd_BIDIRECTIONAL | fd_CAN_NONBLOCK | fd_CAN_SHUTDOWN)
 #define TTY_CAPABILITIES (fd_TTY | fd_INTERPROCESSABLE | fd_BIDIRECTIONAL | fd_CAN_NONBLOCK)
 
+#ifdef HAVE_OPENPTY
+#define fd_openpty	openpty	/* FIXME */
+#endif
+
 #endif /* Don't HAVE_WINSOCK */
 
 #ifndef SEEK_SET
diff --git a/src/modules/_Stdio/file.c b/src/modules/_Stdio/file.c
index 3ecd5f4eafa2e51c287073a0a4e8849e00d8c665..969e0213ff2f0422efccb5183442a3f62a3f5bed 100644
--- a/src/modules/_Stdio/file.c
+++ b/src/modules/_Stdio/file.c
@@ -2564,8 +2564,12 @@ static int my_grantpt(int m)
 #define unlockpt(m)	0
 #endif
 
-#if !defined(HAVE_OPENPTY) && defined(HAVE_PTSNAME) && defined(HAVE_POSIX_OPENPT)
-static int my_openpty(int *master, int *slave, void *ignored_name,
+#ifdef fd_openpty
+#ifndef HAVE_OPENPTY
+#define HAVE_OPENPTY
+#endif
+#elif defined(HAVE_POSIX_OPENPT)
+static int fd_openpty(int *master, int *slave, void *ignored_name,
 		      void *ignored_termp, void *ignored_winp)
 {
   int m;
@@ -2599,7 +2603,6 @@ static int my_openpty(int *master, int *slave, void *ignored_name,
   return -1;
 }
 #define HAVE_OPENPTY
-#define openpty(M, S, N, T, W)	my_openpty(M, S, N, T, W)
 #endif
 
 /*! @decl string grantpt()
@@ -4606,7 +4609,7 @@ static void file_pipe(INT32 args)
 #ifdef HAVE_OPENPTY
     if (!(type & ~(TTY_CAPABILITIES)))
     {
-      i = openpty(inout, inout + 1, NULL, NULL, NULL);
+      i = fd_openpty(inout, inout + 1, NULL, NULL, NULL);
       if (i >= 0) {
 	type = TTY_CAPABILITIES;
 	break;