$NetBSD: patch-exrecover_c,v 1.3 2019/01/18 03:34:28 mrg Exp $ - use standard headers - don't declare own perror - declare void functions void - avoid implicit int - silence signed/unsigned compiler warning - use const for string constants - silence warnings about assignments in conditionals - return values from non-void functions - silence warnings about unused arguments - don't declare own vsprintf, not even used anymore --- exrecover.c.orig 2019-01-17 19:26:42.451474122 -0800 +++ exrecover.c 2019-01-17 19:27:32.144598036 -0800 @@ -98,6 +98,8 @@ typedef int xFILE; #endif +#include + #define var #include "ex.h" @@ -193,30 +195,27 @@ #endif #endif -extern int perror __P((const char *)); char *getblock __P((line, int)); -int blkio __P((bloc, char *, ssize_t (*) __P((int, void *, size_t)))); +void blkio __P((bloc, char *, ssize_t (*) __P((int, void *, size_t)))); char *poolsbrk __P((intptr_t)); -int error __P((char *str, ...)); -int listfiles __P((char *)); -int enter __P((struct svfile *, char *, int)); +void error __P((const char *str, ...)); +void listfiles __P((const char *)); +void enter __P((struct svfile *, char *, int)); int qucmp __P((struct svfile *, struct svfile *)); -int findtmp __P((char *)); -int searchdir __P((char *)); -int yeah __P((char *)); +void findtmp __P((const char *)); +void searchdir __P((const char *)); +int yeah __P((const char *)); int preserve __P((void)); -int scrapbad __P((void)); -int putfile __P((int)); -int wrerror __P((void)); -int clrstats __P((void)); -int get_line __P((line)); -int syserror __P((void)); -int xvfprintf __P((xFILE *, char *, va_list)); -int xfprintf __P((xFILE *, char *, ...)); -#ifdef __STDC__ -int vsprintf(char *, const char *, va_list); -#endif +void scrapbad __P((void)); +void putfile __P((int)); +void wrerror __P((void)); +void clrstats __P((void)); +void get_line __P((line)); +void syserror __P((void)); +void xvfprintf __P((xFILE *, const char *, va_list)); +void xfprintf __P((xFILE *, const char *, ...)); +int main(argc, argv) int argc; char *argv[]; @@ -295,7 +294,7 @@ while (H.Flines > 0) { ignorl(lseek(tfile, (off_t) ((blocks[b] & BLKMSK) * BUFSIZ), SEEK_SET)); - i = H.Flines < BUFSIZ / sizeof (line) ? + i = H.Flines < (int)(BUFSIZ / sizeof (line)) ? H.Flines * sizeof (line) : BUFSIZ; if (read(tfile, (char *) dot, i) != i) { perror(nb); @@ -350,13 +349,14 @@ * a newline which would screw up the screen. */ /*VARARGS2*/ +void #ifndef __STDC__ error(str, inf) - char *str; + const char *str; int inf; { #else -error(char *str, ...) +error(const char *str, ...) { va_list ap; #endif @@ -384,8 +384,9 @@ exit(1); } +void listfiles(dirname) - char *dirname; + const char *dirname; { register DIR *dir; #ifndef POSIX_1 @@ -486,9 +487,11 @@ /* * Enter a new file into the saved file information. */ +void enter(fp, fname, count) struct svfile *fp; char *fname; + int count; { register char *cp, *cp2; register struct svfile *f, *fl; @@ -521,7 +524,7 @@ fp->sf_time = H.Time; fp->sf_lines = H.Flines; cp2 = fp->sf_name, cp = savedfile; - while (*cp2++ = *cp++); + while ((*cp2++ = *cp++) != 0); for (cp2 = fp->sf_entry, cp = fname; *cp && cp-fname < 14;) *cp2++ = *cp++; *cp2++ = 0; @@ -531,12 +534,13 @@ * Do the qsort compare to sort the entries first by file name, * then by modify time. */ +int qucmp(p1, p2) struct svfile *p1, *p2; { register int t; - if (t = strcmp(p1->sf_name, p2->sf_name)) + if ((t = strcmp(p1->sf_name, p2->sf_name)) != 0) return(t); if (p1->sf_time > p2->sf_time) return(-1); @@ -555,8 +559,9 @@ * (i.e. usually /tmp) and in /usr/preserve. * Want to find the newest so we search on and on. */ +void findtmp(dir) - char *dir; + const char *dir; { /* @@ -608,8 +613,9 @@ * name of the file we want to unlink is relative, rather than absolute * we won't be able to find it again. */ +void searchdir(dirname) - char *dirname; + const char *dirname; { #ifndef POSIX_1 struct direct *dirent; @@ -662,8 +668,9 @@ * if its really an editor temporary and of this * user and the file specified. */ +int yeah(name) - char *name; + const char *name; { tfile = open(name, O_RDWR); @@ -688,9 +695,10 @@ return (1); } +int preserve() { - + return 0; } /* @@ -707,6 +715,7 @@ * This only seems to happen on very heavily loaded systems, and * not very often. */ +void scrapbad() { register line *ip; @@ -791,6 +800,7 @@ * Aw shucks, if we only had a (void) cast. */ #ifdef lint +void Ignorl(a) long a; { @@ -798,6 +808,7 @@ a = a; } +void Ignore(a) char *a; { @@ -805,13 +816,15 @@ a = a; } +void Ignorf(a) - int (*a)(); + void (*a)(int); { a = a; } +void ignorl(a) long a; { @@ -824,12 +837,15 @@ /* * Following routines stolen mercilessly from ex. */ -putfile(unused) +void +putfile(int unused) { line *a1; register char *fp, *lp; register int nib; + (void)unused; + a1 = addr1; clrstats(); cntln = addr2 - a1 + 1; @@ -861,12 +877,14 @@ cntch += nib; } +void wrerror() { syserror(); } +void clrstats() { @@ -880,6 +898,7 @@ #define READ 0 #define WRITE 1 +void get_line(tl) line tl; { @@ -890,7 +909,7 @@ bp = getblock(tl, READ); nl = nleft; tl &= ~OFFMSK; - while (*lp++ = *bp++) + while ((*lp++ = *bp++) != 0) if (--nl == 0) { bp = getblock(tl += INCRMT, READ); nl = nleft; @@ -934,8 +953,8 @@ return (obuff + off); } +void #ifdef __STDC__ -int blkio(bloc b, char *buf, ssize_t (*iofcn)(int, void *, size_t)) #else /* !__STDC__ */ blkio(b, buf, iofcn) @@ -950,6 +969,7 @@ syserror(); } +void syserror() { @@ -964,10 +984,11 @@ * allocation and stdio uses malloc. */ #ifndef __STDC__ +void xfprintf(fp, fmt, a1, a2, a3, a4, a5) xFILE *fp; - char *fmt; - char *a1, *a2, *a3, *a4, *a5; + const char *fmt; + const char *a1, *a2, *a3, *a4, *a5; { char buf[BUFSIZ]; @@ -981,17 +1002,19 @@ * I do not know whether vsprintf() uses malloc() or not. * So this may be fail, too. */ -xvfprintf(xFILE *fp, char *fmt, va_list ap) +void +xvfprintf(xFILE *fp, const char *fmt, va_list ap) { char buf[BUFSIZ]; if (fp != xstderr) return; - vsprintf(buf, fmt, ap); + vsnprintf(buf, sizeof(buf), fmt, ap); write(2, buf, strlen(buf)); } -xfprintf(xFILE *fp, char *fmt, ...) +void +xfprintf(xFILE *fp, const char *fmt, ...) { va_list ap;