1 /* vi: set sw=4 ts=4: */
3 * Mini getpty implementation for busybox
4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 int FAST_FUNC xgetpty(char *line)
16 #if ENABLE_FEATURE_DEVPTS
17 p = open("/dev/ptmx", O_RDWR);
19 grantpt(p); /* chmod+chown corresponding slave pty */
20 unlockpt(p); /* (what does this do?) */
21 # ifndef HAVE_PTSNAME_R
24 name = ptsname(p); /* find out the name of slave pty */
26 bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
28 safe_strncpy(line, name, GETPTY_BUFSIZE);
31 /* find out the name of slave pty */
32 if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) {
33 bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
35 line[GETPTY_BUFSIZE-1] = '\0';
44 strcpy(line, "/dev/ptyXX");
46 for (i = 0; i < 16; i++) {
47 line[8] = "pqrstuvwxyzabcde"[i];
49 if (stat(line, &stb) < 0) {
52 for (j = 0; j < 16; j++) {
53 line[9] = j < 10 ? j + '0' : j - 10 + 'a';
55 fprintf(stderr, "Trying to open device: %s\n", line);
56 p = open(line, O_RDWR | O_NOCTTY);
63 #endif /* FEATURE_DEVPTS */
64 bb_error_msg_and_die("can't find free pty");