X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-fclose.c;h=3fbecf12bde49877322862b47859d2b1ca5af1d1;hb=9f4d76b6042f8ed87009331f2ca0a5b7492027d5;hp=a11eca96e39d29ddf7785d3921a06143786b69ef;hpb=1fc3525d1fd7dafbc946dab4c754c593f448c21c;p=gnulib.git diff --git a/tests/test-fclose.c b/tests/test-fclose.c index a11eca96e..3fbecf12b 100644 --- a/tests/test-fclose.c +++ b/tests/test-fclose.c @@ -1,5 +1,5 @@ /* Test of fclose module. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011-2013 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -12,8 +12,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program; if not, see . */ /* Written by Eric Blake. */ @@ -76,12 +75,37 @@ main (int argc, char **argv) /* Test that fclose() sets errno if someone else closes the stream fd behind the back of stdio. */ - f = fdopen (fd, "w+"); - ASSERT (f); - ASSERT (close (fd) == 0); - errno = 0; - ASSERT (fclose (f) == EOF); - ASSERT (errno == EBADF); + { + FILE *fp = fdopen (fd, "w+"); + ASSERT (fp != NULL); + ASSERT (close (fd) == 0); + errno = 0; + ASSERT (fclose (fp) == EOF); + ASSERT (errno == EBADF); + } + + /* Test that fclose() sets errno if the stream was constructed with + an invalid file descriptor. */ + { + FILE *fp = fdopen (-1, "r"); + if (fp != NULL) + { + errno = 0; + ASSERT (fclose (fp) == EOF); + ASSERT (errno == EBADF); + } + } + { + FILE *fp; + close (99); + fp = fdopen (99, "r"); + if (fp != NULL) + { + errno = 0; + ASSERT (fclose (fp) == EOF); + ASSERT (errno == EBADF); + } + } /* Clean up. */ ASSERT (remove (BASE) == 0);