tar: support -T - and -X -
[oweals/busybox.git] / libbb / getpty.c
index bc143c291b8695fbe0ba788232ad2e56afbe56b7..6a15cff2fb36bcddd0ad2e58ebf119cba8c4660a 100644 (file)
@@ -3,7 +3,7 @@
  * 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"
 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?) */
+#ifndef HAVE_PTSNAME_R
                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");
 }
-
-