Don't use .Xo/.Xc. Fix date format.
[netbsd-mini2440.git] / regress / lib / libc / pty / ptmx / ptmx.c
blobb9960ca5f4d725c16fad4608f96bc3634e1142f0
1 /* $NetBSD: ptmx.c,v 1.4 2004/11/11 15:57:47 christos Exp $ */
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: ptmx.c,v 1.4 2004/11/11 15:57:47 christos Exp $");
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <grp.h>
37 #include <errno.h>
38 #include <fcntl.h>
39 #include <sys/stat.h>
42 * On NetBSD /dev/ptyp0 == /dev/pts/0 so we can check for major
43 * and minor device numbers. This check is non-portable. This
44 * check is now disabled because we might not have /dev/ptyp0
45 * at all.
47 #undef PTY_DEVNO_CHECK
49 int
50 main(int argc, char *argv[])
52 struct stat stm, sts;
53 char *pty;
54 int fdm, fds;
55 struct group *gp;
57 if ((fdm = posix_openpt(O_RDWR|O_NOCTTY)) == -1) {
58 if (errno == ENOENT || errno == ENODEV)
59 return 0;
60 err(1, "open master");
63 if (fstat(fdm, &stm) == -1)
64 err(1, "fstat master");
66 #ifdef PTY_DEVNO_CHECK
67 if (stat("/dev/ptyp0", &sts) == -1)
68 err(1, "stat `%s'", /dev/ptyp0);
70 if (major(stm.st_rdev) != major(sts.st_rdev))
71 errx(1, "bad master major number %d", major(stm.st_rdev));
72 #endif
74 if (grantpt(fdm) == -1)
75 err(1, "grantpt");
77 if (unlockpt(fdm) == -1)
78 err(1, "unlockpt");
80 if ((pty = ptsname(fdm)) == NULL)
81 err(1, "ptsname");
83 if ((fds = open(pty, O_RDWR|O_NOCTTY)) == -1)
84 err(1, "open slave");
86 if (fstat(fds, &sts) == -1)
87 err(1, "fstat slave");
89 #ifdef PTY_DEVNO_CHECK
90 if (minor(stm.st_rdev) != minor(sts.st_rdev))
91 errx(1, "bad slave minor number %d", major(stm.st_rdev));
92 #endif
94 if (sts.st_uid != getuid())
95 errx(1, "bad slave uid %lu != %lu", (unsigned long)stm.st_uid,
96 getuid());
98 if ((gp = getgrnam("tty")) == NULL)
99 errx(1, "cannot find `tty' group");
101 if (sts.st_gid != gp->gr_gid)
102 errx(1, "bad slave gid %lu != %lu", (unsigned long)stm.st_gid,
103 gp->gr_gid);
104 return 0;