X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fgetpty.c;h=391d729f2232653e9d67f2a0e72cae5a2bcedde4;hb=1b280e46520420dad1ed1e985d11b7b2bea493e4;hp=c006e34f5f90a0aab8d94eb5174a27e6750318c4;hpb=b4a5087ee006bfee20c7272e92322f9f6377d042;p=oweals%2Fbusybox.git diff --git a/libbb/getpty.c b/libbb/getpty.c index c006e34f5..391d729f2 100644 --- a/libbb/getpty.c +++ b/libbb/getpty.c @@ -3,28 +3,38 @@ * Mini getpty implementation for busybox * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #include "libbb.h" #define DEBUG 0 -int getpty(char *line, int size) +int FAST_FUNC xgetpty(char *line) { int p; + #if ENABLE_FEATURE_DEVPTS p = open("/dev/ptmx", O_RDWR); - if (p > 0) { - const char *name; - grantpt(p); - unlockpt(p); - name = ptsname(p); - if (!name) { - bb_perror_msg("ptsname error (is /dev/pts mounted?)"); - return -1; + if (p >= 0) { + grantpt(p); /* chmod+chown corresponding slave pty */ + unlockpt(p); /* (what does this do?) */ +# ifndef HAVE_PTSNAME_R + { + const char *name; + name = ptsname(p); /* find out the name of slave pty */ + if (!name) { + 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?)"); } - safe_strncpy(line, name, size); + line[GETPTY_BUFSIZE-1] = '\0'; +# endif return p; } #else @@ -52,7 +62,5 @@ int getpty(char *line, int size) } } #endif /* FEATURE_DEVPTS */ - return -1; + bb_error_msg_and_die("can't find free pty"); } - -