1 --- grantpt.c.orig 2004-09-14 19:06:46.000000000 -0700
2 +++ grantpt.c 2004-09-14 19:11:31.000000000 -0700
5 #include "un-namespace.h"
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 */
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.
18 -#define PT_DEV1 "pqrsPQRS"
19 -#define PT_DEV2 "0123456789abcdefghijklmnopqrstuv"
21 +#define PT_DEV1 "pqrstuvw"
22 +#define PT_DEV2 "0123456789abcdef"
25 * grantpt(3) support utility.
27 #define _PATH_PTCHOWN "/usr/libexec/pt_chown"
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.
33 +#define _PATH_A_PTY (_PATH_DEV PTM_PREFIX "p0")
35 +static int _ptm_major = -1;
42 + if (_ptm_major >= 0)
44 + if (stat(_PATH_A_PTY, &st) < 0)
45 + return -1; /* should never happen */
46 + _ptm_major = major(st.st_rdev);
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.
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)
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]);