aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-27 14:33:28 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-27 14:33:28 +0000
commitc8f2f74ddd518ab3d5dedbd6fa75ee2d89b09e85 (patch)
tree05e759953e75b25e136d6a58d69be32067de163a
parent5014dada3fa0bb6f6873e28fe6491f0789239cdc (diff)
downloadbusybox-w32-c8f2f74ddd518ab3d5dedbd6fa75ee2d89b09e85.tar.gz
busybox-w32-c8f2f74ddd518ab3d5dedbd6fa75ee2d89b09e85.tar.bz2
busybox-w32-c8f2f74ddd518ab3d5dedbd6fa75ee2d89b09e85.zip
libbb: add forgotten part of "script" applet change
-rw-r--r--libbb/getpty.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libbb/getpty.c b/libbb/getpty.c
new file mode 100644
index 000000000..4b65188fb
--- /dev/null
+++ b/libbb/getpty.c
@@ -0,0 +1,56 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini getpty implementation for busybox
4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
5 *
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */
8
9#include "libbb.h"
10
11int getpty(char *line, int size)
12{
13 int p;
14#if ENABLE_FEATURE_DEVPTS
15 p = open("/dev/ptmx", O_RDWR);
16 if (p > 0) {
17 const char *name;
18 grantpt(p);
19 unlockpt(p);
20 name = ptsname(p);
21 if (!name) {
22 bb_perror_msg("ptsname error (is /dev/pts mounted?)");
23 return -1;
24 }
25 safe_strncpy(line, name, size);
26 return p;
27 }
28#else
29 struct stat stb;
30 int i;
31 int j;
32
33 strcpy(line, "/dev/ptyXX");
34
35 for (i = 0; i < 16; i++) {
36 line[8] = "pqrstuvwxyzabcde"[i];
37 line[9] = '0';
38 if (stat(line, &stb) < 0) {
39 continue;
40 }
41 for (j = 0; j < 16; j++) {
42 line[9] = j < 10 ? j + '0' : j - 10 + 'a';
43 if (DEBUG)
44 fprintf(stderr, "Trying to open device: %s\n", line);
45 p = open(line, O_RDWR | O_NOCTTY);
46 if (p >= 0) {
47 line[5] = 't';
48 return p;
49 }
50 }
51 }
52#endif /* FEATURE_DEVPTS */
53 return -1;
54}
55
56