changeset 15979:69cc1dcd696b

unlockpt: Detect invalid argument. * lib/unlockpt.c: Include <fcntl.h>. (unlockpt): Check whether fd is valid, using fcntl(). * modules/unlockpt (Depends-on): Add fcntl-h.
author Bruno Haible <bruno@clisp.org>
date Fri, 21 Oct 2011 02:22:04 +0200
parents da5b835b2356
children ca99be30d00b
files ChangeLog lib/unlockpt.c modules/unlockpt
diffstat 3 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-10-20  Bruno Haible  <bruno@clisp.org>
+
+	unlockpt: Detect invalid argument.
+	* lib/unlockpt.c: Include <fcntl.h>.
+	(unlockpt): Check whether fd is valid, using fcntl().
+	* modules/unlockpt (Depends-on): Add fcntl-h.
+
 2011-10-20  Bruno Haible  <bruno@clisp.org>
 
 	openpty: Avoid compilation error on AIX 6.1.
--- a/lib/unlockpt.c
+++ b/lib/unlockpt.c
@@ -19,6 +19,7 @@
 
 #include <stdlib.h>
 
+#include <fcntl.h>
 #include <unistd.h>
 
 int
@@ -36,6 +37,8 @@
 #else
   /* Assume that the slave side of a pseudo-terminal is already unlocked
      by default.  */
+  if (fcntl (fd, F_GETFD) < 0)
+    return -1;
   return 0;
 #endif
 }
--- a/modules/unlockpt
+++ b/modules/unlockpt
@@ -9,6 +9,7 @@
 Depends-on:
 stdlib
 extensions
+fcntl-h         [test $HAVE_UNLOCKPT = 0]
 ptsname         [test $HAVE_UNLOCKPT = 0]
 
 configure.ac: