swaponoff: add support for -e
[oweals/busybox.git] / libbb / getpty.c
index 4bffd9ae635ff56fcba524d8230420eecd0b846a..391d729f2232653e9d67f2a0e72cae5a2bcedde4 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"
@@ -16,23 +16,25 @@ int FAST_FUNC xgetpty(char *line)
 
 #if ENABLE_FEATURE_DEVPTS
        p = open("/dev/ptmx", O_RDWR);
-       if (p > 0) {
+       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;
-               name = ptsname(p); /* find out the name of slave pty */
-               if (!name) {
-                       bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
+# 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);
                }
-               safe_strncpy(line, name, GETPTY_BUFSIZE);
-#else
+# 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
+# endif
                return p;
        }
 #else