diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-17 12:47:19 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-17 12:47:19 +0000 |
commit | eb084779d7f3feba414d679006d4f1633451677f (patch) | |
tree | fa0da9fae09951ed955e9f2e695541b235618d9d | |
parent | 34c73c499bae67c1a81482c1ff5c263c85e51f1d (diff) | |
download | busybox-w32-eb084779d7f3feba414d679006d4f1633451677f.tar.gz busybox-w32-eb084779d7f3feba414d679006d4f1633451677f.tar.bz2 busybox-w32-eb084779d7f3feba414d679006d4f1633451677f.zip |
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
-rw-r--r-- | libbb/getpty.c | 24 |
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 @@ | |||
13 | int FAST_FUNC xgetpty(char *line) | 13 | int FAST_FUNC xgetpty(char *line) |
14 | { | 14 | { |
15 | int p; | 15 | int p; |
16 | |||
16 | #if ENABLE_FEATURE_DEVPTS | 17 | #if ENABLE_FEATURE_DEVPTS |
17 | p = open("/dev/ptmx", O_RDWR); | 18 | p = open("/dev/ptmx", O_RDWR); |
18 | if (p > 0) { | 19 | if (p > 0) { |
20 | grantpt(p); /* chmod+chown corresponding slave pty */ | ||
21 | unlockpt(p); /* (what does this do?) */ | ||
22 | #if 0 /* if ptsname_r is not available... */ | ||
19 | const char *name; | 23 | const char *name; |
20 | grantpt(p); | 24 | name = ptsname(p); /* find out the name of slave pty */ |
21 | unlockpt(p); | ||
22 | name = ptsname(p); | ||
23 | if (!name) { | 25 | if (!name) { |
24 | bb_perror_msg("ptsname error (is /dev/pts mounted?)"); | 26 | bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); |
25 | goto fail; | ||
26 | } | 27 | } |
27 | safe_strncpy(line, name, GETPTY_BUFSIZE); | 28 | safe_strncpy(line, name, GETPTY_BUFSIZE); |
29 | #else | ||
30 | /* find out the name of slave pty */ | ||
31 | if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) { | ||
32 | bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); | ||
33 | } | ||
34 | line[GETPTY_BUFSIZE-1] = '\0'; | ||
35 | #endif | ||
28 | return p; | 36 | return p; |
29 | } | 37 | } |
30 | #else | 38 | #else |
@@ -52,9 +60,5 @@ int FAST_FUNC xgetpty(char *line) | |||
52 | } | 60 | } |
53 | } | 61 | } |
54 | #endif /* FEATURE_DEVPTS */ | 62 | #endif /* FEATURE_DEVPTS */ |
55 | USE_FEATURE_DEVPTS( fail:) | 63 | bb_error_msg_and_die("can't find free pty"); |
56 | bb_error_msg_and_die("open pty"); | ||
57 | return -1; /* never get here */ | ||
58 | } | 64 | } |
59 | |||
60 | |||