tests: don't assume fd 99 is closed
[gnulib.git] / tests / test-grantpt.c
1 /* Test acquiring ownership of the slave side of a pseudo-terminal.
2    Copyright (C) 2011-2013 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 #include <config.h>
18
19 #include <stdlib.h>
20
21 #include "signature.h"
22 SIGNATURE_CHECK (grantpt, int, (int));
23
24 #include <errno.h>
25
26 #include "macros.h"
27
28 int
29 main (void)
30 {
31   /* Test behaviour for invalid file descriptors.
32      These calls don't fail on OpenBSD (with gnulib's replacement) and on
33      musl libc.  */
34   {
35     int ret;
36
37     errno = 0;
38     ret = grantpt (-1);
39     if (ret != 0)
40       {
41         ASSERT (ret == -1);
42         ASSERT (errno == EBADF
43                 || errno == EINVAL /* seen on FreeBSD 6.4 */
44                 || errno == 0 /* seen on Solaris 8 */
45                );
46       }
47   }
48   {
49     int ret;
50
51     close (99);
52     errno = 0;
53     ret = grantpt (99);
54     if (ret != 0)
55       {
56         ASSERT (ret == -1);
57         ASSERT (errno == EBADF
58                 || errno == EINVAL /* seen on FreeBSD 6.4 */
59                 || errno == 0 /* seen on Solaris 8 */
60                );
61       }
62   }
63
64   return 0;
65 }