X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=tty_subs.c;h=6b6e13423ee3fe5e2bc3ebd5aeb840b3b634d8d3;hb=HEAD;hp=d70cd7894c01eab89ed27fc3266ee1759b6a62d8;hpb=def03712042d935b1238542b15d62f5121b9d5d2;p=debian%2Fpax diff --git a/tty_subs.c b/tty_subs.c index d70cd78..6b6e134 100644 --- a/tty_subs.c +++ b/tty_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_subs.c,v 1.5 1997/07/25 18:58:39 mickey 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 $ */ /*- @@ -17,11 +17,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)tty_subs.c 8.2 (Berkeley) 4/18/94"; +static const char sccsid[] = "@(#)tty_subs.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: tty_subs.c,v 1.5 1997/07/25 18:58:39 mickey Exp $"; +static const char rcsid[] = "$OpenBSD: tty_subs.c,v 1.13 2009/06/01 13:02:46 ray Exp $"; #endif #endif /* not lint */ @@ -58,11 +54,7 @@ static char rcsid[] = "$OpenBSD: tty_subs.c,v 1.5 1997/07/25 18:58:39 mickey Exp #include #include "pax.h" #include "extern.h" -#ifdef __STDC__ #include -#else -#include -#endif /* * routines that deal with I/O to and from the user @@ -74,17 +66,12 @@ static FILE *ttyinf = NULL; /* input pointing at control tty */ /* * tty_init() - * try to open the controlling termina (if any) for this process. if the + * try to open the controlling terminal (if any) for this process. if the * open fails, future ops that require user input will get an EOF */ -#ifdef __STDC__ int tty_init(void) -#else -int -tty_init() -#endif { int ttyfd; @@ -110,24 +97,16 @@ tty_init() * if there is no controlling terminal, just return. */ -#ifdef __STDC__ void -tty_prnt(char *fmt, ...) -#else -void -tty_prnt(fmt, va_alist) - char *fmt; - va_dcl -#endif +tty_prnt(const char *fmt, ...) { va_list ap; -# ifdef __STDC__ + va_start(ap, fmt); -# else - va_start(ap); -# endif - if (ttyoutf == NULL) + if (ttyoutf == NULL) { + va_end(ap); return; + } (void)vfprintf(ttyoutf, fmt, ap); va_end(ap); (void)fflush(ttyoutf); @@ -141,27 +120,16 @@ tty_prnt(fmt, va_alist) * 0 if data was read, -1 otherwise. */ -#ifdef __STDC__ int tty_read(char *str, int len) -#else -int -tty_read(str, len) - char *str; - int len; -#endif { - register 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); } @@ -171,23 +139,12 @@ tty_read(str, len) * will be non-zero. */ -#ifdef __STDC__ void -paxwarn(int set, char *fmt, ...) -#else -void -paxwarn(set, fmt, va_alist) - int set; - char *fmt; - va_dcl -#endif +paxwarn(int set, const char *fmt, ...) { va_list ap; -# ifdef __STDC__ + va_start(ap, fmt); -# else - va_start(ap); -# endif if (set) exit_val = 1; /* @@ -195,6 +152,7 @@ paxwarn(set, fmt, va_alist) * line by itself */ if (vflag && vfpart) { + (void)fflush(listf); (void)fputc('\n', stderr); vfpart = 0; } @@ -210,24 +168,12 @@ paxwarn(set, fmt, va_alist) * will be non-zero. */ -#ifdef __STDC__ -void -syswarn(int set, int errnum, char *fmt, ...) -#else void -syswarn(set, errnum, fmt, va_alist) - int set; - int errnum; - char *fmt; - va_dcl -#endif +syswarn(int set, int errnum, const char *fmt, ...) { va_list ap; -# ifdef __STDC__ + va_start(ap, fmt); -# else - va_start(ap); -# endif if (set) exit_val = 1; /* @@ -235,6 +181,7 @@ syswarn(set, errnum, fmt, va_alist) * line by itself */ if (vflag && vfpart) { + (void)fflush(listf); (void)fputc('\n', stderr); vfpart = 0; } @@ -246,6 +193,6 @@ syswarn(set, errnum, fmt, va_alist) * format and print the errno */ if (errnum > 0) - (void)fprintf(stderr, " <%s>", strerror(errnum)); + (void)fprintf(stderr, ": %s", strerror(errnum)); (void)fputc('\n', stderr); }