On all platforms, ptsname() sets errno when the argument is an invalid
file descriptor. Even through POSIX does not require it [1], it's safe to
check it.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/ptsname.html


2012-06-24  Bruno Haible  <br...@clisp.org>

        ptsname test: Extend test.
        * tests/test-ptsname.c: Include <errno.h>.
        (main): Test behaviour with invalid file descriptor.

--- tests/test-ptsname.c.orig   Sun Jun 24 14:51:29 2012
+++ tests/test-ptsname.c        Sun Jun 24 14:42:35 2012
@@ -21,6 +21,7 @@
 #include "signature.h"
 SIGNATURE_CHECK (ptsname, char *, (int));
 
+#include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
@@ -63,6 +64,17 @@
 #endif
 
   {
+    char *result;
+
+    errno = 0;
+    result = ptsname (-1);
+    ASSERT (result == NULL);
+    ASSERT (errno == EBADF
+            || errno == ENOTTY /* seen on glibc */
+           );
+  }
+
+  {
     int fd;
     char *result;
 


Reply via email to