aboutsummaryrefslogtreecommitdiff
path: root/libbb/getpty.c
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2008-08-17 12:47:19 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2008-08-17 12:47:19 +0000
commiteb084779d7f3feba414d679006d4f1633451677f (patch)
treefa0da9fae09951ed955e9f2e695541b235618d9d /libbb/getpty.c
parent34c73c499bae67c1a81482c1ff5c263c85e51f1d (diff)
downloadbusybox-eb084779d7f3feba414d679006d4f1633451677f.tar.gz
busybox-eb084779d7f3feba414d679006d4f1633451677f.tar.bz2
libbb: use ptsname_r, it's smaller
function old new delta xgetpty 91 81 -10 ptsname 33 - -33 text data bss dec hex filename 793828 592 6692 801112 c3958 busybox_old 793796 592 6660 801048 c3918 busybox_unstripped
Diffstat (limited to 'libbb/getpty.c')
-rw-r--r--libbb/getpty.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/libbb/getpty.c b/libbb/getpty.c
index bc143c291..4bffd9ae6 100644
--- a/libbb/getpty.c
+++ b/libbb/getpty.c
@@ -13,18 +13,26 @@
int FAST_FUNC xgetpty(char *line)
{
int p;
+
#if ENABLE_FEATURE_DEVPTS
p = open("/dev/ptmx", O_RDWR);
if (p > 0) {
+ grantpt(p); /* chmod+chown corresponding slave pty */
+ unlockpt(p); /* (what does this do?) */
+#if 0 /* if ptsname_r is not available... */
const char *name;
- grantpt(p);
- unlockpt(p);
- name = ptsname(p);
+ name = ptsname(p); /* find out the name of slave pty */
if (!name) {
- bb_perror_msg("ptsname error (is /dev/pts mounted?)");
- goto fail;
+ bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
}
safe_strncpy(line, name, GETPTY_BUFSIZE);
+#else
+ /* find out the name of slave pty */
+ if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) {
+ bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
+ }
+ line[GETPTY_BUFSIZE-1] = '\0';
+#endif
return p;
}
#else
@@ -52,9 +60,5 @@ int FAST_FUNC xgetpty(char *line)
}
}
#endif /* FEATURE_DEVPTS */
-USE_FEATURE_DEVPTS( fail:)
- bb_error_msg_and_die("open pty");
- return -1; /* never get here */
+ bb_error_msg_and_die("can't find free pty");
}
-
-