This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FreeBSD port (31): grantpt error code


Hi,

The tst-grantpt fails on FreeBSD, because when the file descriptor is
invalid or points to a regular file, the function __ptsname_r fails with
error code ENOTTY, whereas the test expect the error codes EBADF and EINVAL
from the grantpt() function.

Since neither the SUSV3 nor the glibc manual specifies an explicit error
codes for ptsname(), I believe it's the duty of grantpt() function to provide
the necessary error code. Here is a patch.


2002-07-06  Bruno Haible  <bruno@clisp.org>

	* sysdeps/unix/grantpt.c (grantpt): Provide the right error code
	if pts_name fails.

diff -r -c3 glibc-20020627.bak/sysdeps/unix/grantpt.c glibc-20020627/sysdeps/unix/grantpt.c
--- glibc-20020627.bak/sysdeps/unix/grantpt.c	Mon Apr 15 20:55:47 2002
+++ glibc-20020627/sysdeps/unix/grantpt.c	Fri Jul  5 01:17:11 2002
@@ -19,6 +19,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <grp.h>
 #include <limits.h>
 #include <stdlib.h>
@@ -107,7 +108,16 @@
   pid_t pid;
 
   if (pts_name (fd, &buf, sizeof (_buf)))
-    return -1;
+    {
+      if (errno == ENOTTY)
+	{
+	  if (__fcntl (fd, F_GETFD, 0) < 0)
+	    __set_errno (EBADF);
+	  else
+	    __set_errno (EINVAL);
+	}
+      return -1;
+    }
 
   if (__xstat64 (_STAT_VER, buf, &st) < 0)
     goto cleanup;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]