maint: update copyright
[gnulib.git] / tests / test-posix_openpt.c
1 /* Test of posix_openpt function.
2    Copyright (C) 2011-2014 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 /* Written by Eric Blake <eblake@redhat.com>, 2011.  */
18
19 #include <config.h>
20
21 #include <stdlib.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (posix_openpt, int, (int));
25
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <unistd.h>
30
31 #if defined __sun || defined __hpux /* Solaris, HP-UX */
32 # include <stropts.h>
33 #endif
34
35 #include "macros.h"
36
37 int
38 main (void)
39 {
40   int master;
41   int slave;
42   char *name;
43
44   /* Open the master of a pseudo-terminal pair.  */
45   master = posix_openpt (O_RDWR | O_NOCTTY);
46   if (master < 0 && errno == ENOSYS)
47     {
48       fputs ("skipping: platform lacks pty support\n", stderr);
49       return 77;
50     }
51
52   ASSERT (0 <= master);
53   name = ptsname (master);
54   ASSERT (name);
55   ASSERT (grantpt (master) == 0);
56   ASSERT (unlockpt (master) == 0);
57   slave = open (name, O_RDWR);
58   ASSERT (0 <= slave);
59
60 #if defined __sun || defined __hpux /* Solaris, HP-UX */
61   ASSERT (ioctl (slave, I_PUSH, "ptem") == 0);
62   ASSERT (ioctl (slave, I_PUSH, "ldterm")  == 0);
63 # if defined __sun
64   ASSERT (ioctl (slave, I_PUSH, "ttcompat") == 0);
65 # endif
66 #endif
67
68   ASSERT (isatty (slave));
69
70   /* Close the master side before the slave side gets closed.
71      This is necessary on Mac OS X 10.4.11.  */
72   ASSERT (close (master) == 0);
73   ASSERT (close (slave) == 0);
74
75   return 0;
76 }