From: Bruno Haible Date: Fri, 22 Jun 2012 10:36:47 +0000 (+0200) Subject: grantpt: Relax requirement regarding invalid file descriptors. X-Git-Tag: v0.1~594 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=74ccd5f4fb8bad9f914da3ba44b3d5cbfbc93f8e;p=gnulib.git grantpt: Relax requirement regarding invalid file descriptors. * lib/grantpt.c: Don't include . (grantpt): Don't verify the validity of the file descriptor. * modules/grantpt (Depends-on): Remove fcntl-h. * tests/test-grantpt.c (main): Allow grantpt to succeed for invalid file descriptors. * doc/posix-functions/grantpt.texi: Document more platforms on which grantpt succeeds for invalid file descriptors. Reported by Rich Felker . --- diff --git a/ChangeLog b/ChangeLog index 7d53a42e2..225cbfefa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2012-06-22 Bruno Haible + grantpt: Relax requirement regarding invalid file descriptors. + * lib/grantpt.c: Don't include . + (grantpt): Don't verify the validity of the file descriptor. + * modules/grantpt (Depends-on): Remove fcntl-h. + * tests/test-grantpt.c (main): Allow grantpt to succeed for invalid + file descriptors. + * doc/posix-functions/grantpt.texi: Document more platforms on which + grantpt succeeds for invalid file descriptors. + Reported by Rich Felker . + +2012-06-22 Bruno Haible + fbufmode test: Don't test unportable behaviour. * tests/test-fbufmode.c (test_mode): New function, extracted from main. (main): Invoke it three times. diff --git a/doc/posix-functions/grantpt.texi b/doc/posix-functions/grantpt.texi index eaba7f070..b431853cc 100644 --- a/doc/posix-functions/grantpt.texi +++ b/doc/posix-functions/grantpt.texi @@ -20,5 +20,5 @@ This function is not declared on some platforms: IRIX 5.3. @item This function reports success for invalid file descriptors on some platforms: -Cygwin 1.7.9. +OpenBSD, Cygwin 1.7.9, musl libc. @end itemize diff --git a/lib/grantpt.c b/lib/grantpt.c index ce80ad49f..79799086d 100644 --- a/lib/grantpt.c +++ b/lib/grantpt.c @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -50,8 +49,6 @@ grantpt (int fd) #if defined __OpenBSD__ /* On OpenBSD, master and slave of a pseudo-terminal are allocated together, through an ioctl on /dev/ptm. There is no need for grantpt(). */ - if (fcntl (fd, F_GETFD) < 0) - return -1; return 0; #else /* This function is most often called from a process without 'root' diff --git a/modules/grantpt b/modules/grantpt index 77c7bc332..2d63d2f77 100644 --- a/modules/grantpt +++ b/modules/grantpt @@ -9,7 +9,6 @@ m4/grantpt.m4 Depends-on: stdlib extensions -fcntl-h [test $HAVE_GRANTPT = 0] pt_chown [test $HAVE_GRANTPT = 0] waitpid [test $HAVE_GRANTPT = 0] configmake [test $HAVE_GRANTPT = 0] diff --git a/tests/test-grantpt.c b/tests/test-grantpt.c index f8ec72a92..5deedf0b3 100644 --- a/tests/test-grantpt.c +++ b/tests/test-grantpt.c @@ -28,22 +28,36 @@ SIGNATURE_CHECK (grantpt, int, (int)); int main (void) { - /* Test behaviour for invalid file descriptors. */ + /* Test behaviour for invalid file descriptors. + These calls don't fail on OpenBSD (with gnulib's replacement) and on + musl libc. */ { + int ret; + errno = 0; - ASSERT (grantpt (-1) == -1); - ASSERT (errno == EBADF - || errno == EINVAL /* seen on FreeBSD 6.4 */ - || errno == 0 /* seen on Solaris 8 */ - ); + ret = grantpt (-1); + if (ret != 0) + { + ASSERT (ret == -1); + ASSERT (errno == EBADF + || errno == EINVAL /* seen on FreeBSD 6.4 */ + || errno == 0 /* seen on Solaris 8 */ + ); + } } { + int ret; + errno = 0; - ASSERT (grantpt (99) == -1); - ASSERT (errno == EBADF - || errno == EINVAL /* seen on FreeBSD 6.4 */ - || errno == 0 /* seen on Solaris 8 */ - ); + ret = grantpt (99); + if (ret != 0) + { + ASSERT (ret == -1); + ASSERT (errno == EBADF + || errno == EINVAL /* seen on FreeBSD 6.4 */ + || errno == 0 /* seen on Solaris 8 */ + ); + } } return 0;