]> git.saurik.com Git - apple/libc.git/blob - stdlib/FreeBSD/grantpt.c.patch
a41355beb5dab1c269d3807f272c9e35b86ab343
[apple/libc.git] / stdlib / FreeBSD / grantpt.c.patch
1 --- grantpt.c.orig 2004-09-14 19:06:46.000000000 -0700
2 +++ grantpt.c 2004-09-14 19:11:31.000000000 -0700
3 @@ -54,18 +54,16 @@
4 #include <unistd.h>
5 #include "un-namespace.h"
6
7 -#define PTM_MAJOR 6 /* pseudo tty master major */
8 -#define PTS_MAJOR 5 /* pseudo tty slave major */
9 #define PTM_PREFIX "pty" /* pseudo tty master naming convention */
10 #define PTS_PREFIX "tty" /* pseudo tty slave naming convention */
11
12 /*
13 * The following are range values for pseudo TTY devices. Pseudo TTYs have a
14 - * name of /dev/[pt]ty[p-sP-S][0-9a-v], yielding 256 combinations per major.
15 + * name of /dev/[pt]ty[p-w][0-9a-f], yielding 128 combinations per major.
16 */
17 -#define PT_MAX 256
18 -#define PT_DEV1 "pqrsPQRS"
19 -#define PT_DEV2 "0123456789abcdefghijklmnopqrstuv"
20 +#define PT_MAX 128
21 +#define PT_DEV1 "pqrstuvw"
22 +#define PT_DEV2 "0123456789abcdef"
23
24 /*
25 * grantpt(3) support utility.
26 @@ -73,11 +71,32 @@
27 #define _PATH_PTCHOWN "/usr/libexec/pt_chown"
28
29 /*
30 + * On Mac OS X, the major device number may not be the same between reboots.
31 + * So we need to determine the major device number the first time.
32 + */
33 +#define _PATH_A_PTY (_PATH_DEV PTM_PREFIX "p0")
34 +
35 +static int _ptm_major = -1;
36 +
37 +static int
38 +_init_major(void)
39 +{
40 + struct stat st;
41 +
42 + if (_ptm_major >= 0)
43 + return _ptm_major;
44 + if (stat(_PATH_A_PTY, &st) < 0)
45 + return -1; /* should never happen */
46 + _ptm_major = major(st.st_rdev);
47 + return _ptm_major;
48 +}
49 +/*
50 * ISPTM(x) returns 0 for struct stat x if x is not a pty master.
51 * The bounds checking may be unnecessary but it does eliminate doubt.
52 */
53 -#define ISPTM(x) (S_ISCHR((x).st_mode) && \
54 - major((x).st_rdev) == PTM_MAJOR && \
55 +#define ISPTM(x) (_init_major() >= 0 && \
56 + S_ISCHR((x).st_mode) && \
57 + major((x).st_rdev) == _ptm_major && \
58 minor((x).st_rdev) >= 0 && \
59 minor((x).st_rdev) < PT_MAX)
60
61 @@ -227,8 +246,8 @@
62 errno = EINVAL;
63 else {
64 (void)sprintf(slave, _PATH_DEV PTS_PREFIX "%c%c",
65 - PT_DEV1[minor(sbuf.st_rdev) / 32],
66 - PT_DEV2[minor(sbuf.st_rdev) % 32]);
67 + PT_DEV1[minor(sbuf.st_rdev) / 16],
68 + PT_DEV2[minor(sbuf.st_rdev) % 16]);
69 retval = slave;
70 }
71 }