more careful about clobbering the supposed newline at the end of the string
[unix-history] / usr / src / usr.bin / mail / tty.c
index a5e9a51..20f6d36 100644 (file)
@@ -9,7 +9,7 @@
 #include "rcv.h"
 #include <sgtty.h>
 
 #include "rcv.h"
 #include <sgtty.h>
 
-static char *SccsId = "@(#)tty.c       1.1 %G%";
+static char *SccsId = "@(#)tty.c       1.2 %G%";
 
 static int     c_erase;                /* Current erase char */
 static int     c_kill;                 /* Current kill char */
 
 static int     c_erase;                /* Current erase char */
 static int     c_kill;                 /* Current kill char */
@@ -131,9 +131,12 @@ readtty(pr, src)
                ioctl(0, TIOCSTI, &c);
        }
        cp = canonb;
                ioctl(0, TIOCSTI, &c);
        }
        cp = canonb;
+       *cp = 0;
 #endif
        cp2 = fgets(cp, BUFSIZ - (cp - canonb), stdin);
 #endif
        cp2 = fgets(cp, BUFSIZ - (cp - canonb), stdin);
-       canonb[strlen(canonb) - 1] = '\0';
+       cp = index(canonb, '\n');
+       if (cp != NOSTR)
+               *cp = 0;
 #ifndef TIOCSTI
        if (cp2 == NOSTR || *cp2 == '\0')
                return(src);
 #ifndef TIOCSTI
        if (cp2 == NOSTR || *cp2 == '\0')
                return(src);