-/* $OpenBSD: tty_subs.c,v 1.12 2003/06/02 23:32:09 millert Exp $ */
+/* $OpenBSD: tty_subs.c,v 1.13 2009/06/01 13:02:46 ray Exp $ */
/* $NetBSD: tty_subs.c,v 1.5 1995/03/21 09:07:52 cgd Exp $ */
/*-
#if 0
static const char sccsid[] = "@(#)tty_subs.c 8.2 (Berkeley) 4/18/94";
#else
-static const char rcsid[] = "$OpenBSD: tty_subs.c,v 1.12 2003/06/02 23:32:09 millert Exp $";
+static const char rcsid[] = "$OpenBSD: tty_subs.c,v 1.13 2009/06/01 13:02:46 ray Exp $";
#endif
#endif /* not lint */
int
tty_read(char *str, int len)
{
- char *pt;
-
- if ((--len <= 0) || (ttyinf == NULL) || (fgets(str,len,ttyinf) == NULL))
+ if (ttyinf == NULL || fgets(str, len, ttyinf) == NULL)
return(-1);
- *(str + len) = '\0';
/*
* strip off that trailing newline
*/
- if ((pt = strchr(str, '\n')) != NULL)
- *pt = '\0';
+ str[strcspn(str, "\n")] = '\0';
return(0);
}