usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-posix_openpt.c
blob95d69cd7ae513647427e7fd9e66fea9859fb5cfe
1 /* Test of posix_openpt function.
2 Copyright (C) 2011-2024 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <eblake@redhat.com>, 2011. */
19 #include <config.h>
21 #include <stdlib.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (posix_openpt, int, (int));
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <unistd.h>
31 #if defined __sun || defined __hpux /* Solaris, HP-UX */
32 # include <stropts.h>
33 #endif
35 #include "macros.h"
37 int
38 main (void)
40 int master;
41 int slave;
42 char *name;
44 /* Open the master of a pseudo-terminal pair. */
45 master = posix_openpt (O_RDWR | O_NOCTTY);
46 if (master < 0 && errno == ENOSYS)
48 fputs ("skipping: platform lacks pty support\n", stderr);
49 return 77;
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);
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
68 ASSERT (isatty (slave));
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);
75 return test_exit_status;