Module Name: src Committed By: rillig Date: Sat Aug 26 14:50:53 UTC 2023
Modified Files: src/usr.bin/error: Makefile error.h input.c main.c pi.c subr.c touch.c Log Message: error: enable lint's strict bool mode This cleans up the inconsistencies between 'int', 'boolean' and 'bool'. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/error/Makefile cvs rdiff -u -r1.19 -r1.20 src/usr.bin/error/error.h \ src/usr.bin/error/input.c cvs rdiff -u -r1.24 -r1.25 src/usr.bin/error/main.c cvs rdiff -u -r1.21 -r1.22 src/usr.bin/error/pi.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/error/subr.c cvs rdiff -u -r1.30 -r1.31 src/usr.bin/error/touch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/error/Makefile diff -u src/usr.bin/error/Makefile:1.10 src/usr.bin/error/Makefile:1.11 --- src/usr.bin/error/Makefile:1.10 Sat Aug 26 11:38:14 2023 +++ src/usr.bin/error/Makefile Sat Aug 26 14:50:53 2023 @@ -1,5 +1,5 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $NetBSD: Makefile,v 1.10 2023/08/26 11:38:14 rillig Exp $ +# $NetBSD: Makefile,v 1.11 2023/08/26 14:50:53 rillig Exp $ PROG= error SRCS= main.c input.c pi.c subr.c filter.c touch.c @@ -8,5 +8,6 @@ DPADD+= ${LIBUTIL} LDADD+= -lutil LINTFLAGS+= -w # treat warnings as errors +LINTFLAGS+= -T # strict bool mode .include <bsd.prog.mk> Index: src/usr.bin/error/error.h diff -u src/usr.bin/error/error.h:1.19 src/usr.bin/error/error.h:1.20 --- src/usr.bin/error/error.h:1.19 Wed Feb 29 23:37:07 2012 +++ src/usr.bin/error/error.h Sat Aug 26 14:50:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: error.h,v 1.19 2012/02/29 23:37:07 joerg Exp $ */ +/* $NetBSD: error.h,v 1.20 2023/08/26 14:50:53 rillig Exp $ */ /* * Copyright (c) 1980, 1993 @@ -33,8 +33,6 @@ #include <stdbool.h> -typedef int boolean; - /* * Descriptors for the various languages we know about. * If you touch these, also touch lang_table @@ -112,8 +110,8 @@ extern char *scriptname; extern const char *suffixlist; -extern boolean query; -extern boolean terse; +extern bool query; +extern bool terse; int inquire(const char *, ...) __printflike(1, 2); /* inquire for yes/no */ /* @@ -195,7 +193,7 @@ extern char **cur_wordv; */ extern int nfiles; extern Eptr **files; /* array of pointers into errors */ -extern boolean *touchedfiles; /* which files we touched */ +extern bool *touchedfiles; /* which files we touched */ /* * The language the compilation is in, as intuited from Index: src/usr.bin/error/input.c diff -u src/usr.bin/error/input.c:1.19 src/usr.bin/error/input.c:1.20 --- src/usr.bin/error/input.c:1.19 Sat Aug 26 12:43:28 2023 +++ src/usr.bin/error/input.c Sat Aug 26 14:50:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: input.c,v 1.19 2023/08/26 12:43:28 rillig Exp $ */ +/* $NetBSD: input.c,v 1.20 2023/08/26 14:50:53 rillig Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: input.c,v 1.19 2023/08/26 12:43:28 rillig Exp $"); +__RCSID("$NetBSD: input.c,v 1.20 2023/08/26 14:50:53 rillig Exp $"); #endif /* not lint */ #include <stdio.h> @@ -104,7 +104,7 @@ eaterrors(int *r_errorc, Eptr **r_errorv ) ; else errorclass = catchall(); - if (cur_wordc) + if (cur_wordc > 0) erroradd(cur_wordc, cur_wordv+1, errorclass, C_UNKNOWN); } #ifdef FULLDEBUG @@ -125,7 +125,8 @@ erroradd(int errorlength, char **errorv, if (errorclass == C_TRUE) { /* check canonicalization of the second argument*/ - for (cp = errorv[1]; *cp && isdigit((unsigned char)*cp); cp++) + for (cp = errorv[1]; + *cp != '\0' && isdigit((unsigned char)*cp); cp++) continue; errorclass = (*cp == '\0') ? C_TRUE : C_NONSPEC; #ifdef FULLDEBUG @@ -431,14 +432,10 @@ lint1(void) return C_TRUE; } } - if (file2) - free(file2); - if (file1) - free(file1); - if (line2) - free(line2); - if (line1) - free(line1); + free(file2); + free(file1); + free(line2); + free(line1); return C_UNKNOWN; } /* end of lint 1*/ Index: src/usr.bin/error/main.c diff -u src/usr.bin/error/main.c:1.24 src/usr.bin/error/main.c:1.25 --- src/usr.bin/error/main.c:1.24 Sat Aug 26 13:52:10 2023 +++ src/usr.bin/error/main.c Sat Aug 26 14:50:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.24 2023/08/26 13:52:10 rillig Exp $ */ +/* $NetBSD: main.c,v 1.25 2023/08/26 14:50:53 rillig Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: main.c,v 1.24 2023/08/26 13:52:10 rillig Exp $"); +__RCSID("$NetBSD: main.c,v 1.25 2023/08/26 14:50:53 rillig Exp $"); #endif /* not lint */ #include <signal.h> @@ -65,17 +65,17 @@ static Eptr *errors; int nfiles = 0; Eptr **files; /* array of pointers into errors*/ -boolean *touchedfiles; /* which files we touched */ +bool *touchedfiles; /* which files we touched */ int language = INCC; char default_currentfilename[] = "????"; char *currentfilename = default_currentfilename; -boolean query = false; /* query the operator if touch files */ -boolean terse = false; /* Terse output */ +bool query = false; /* query the operator if touch files */ +bool terse = false; /* Terse output */ static char im_on[] = _PATH_TTY; /* my tty name */ -static boolean notouch = false; /* don't touch ANY files */ +static bool notouch = false; /* don't touch ANY files */ const char *suffixlist = ".*"; /* initially, can touch any file */ @@ -91,10 +91,10 @@ main(int argc, char **argv) char *ignorename = 0; int ed_argc; char **ed_argv; /* return from touchfiles */ - boolean show_errors = false; - boolean Show_Errors = false; - boolean pr_summary = false; - boolean edit_files = false; + bool show_errors = false; + bool Show_Errors = false; + bool pr_summary = false; + bool edit_files = false; setprogname(argv[0]); @@ -168,27 +168,27 @@ main(int argc, char **argv) findfiles(nerrors, errors, &nfiles, &files); #define P(msg, arg) fprintf(stdout, msg, arg) if (pr_summary) { - if (nunknown) + if (nunknown > 0) P("%d Errors are unclassifiable.\n", nunknown); - if (nignore) + if (nignore > 0) P("%d Errors are classifiable, but totally " "discarded.\n", nignore); - if (nsyncerrors) + if (nsyncerrors > 0) P("%d Errors are synchronization errors.\n", nsyncerrors); - if (nignore) + if (nignore > 0) P("%d Errors are discarded because they refer to " "sacrosinct files.\n", ndiscard); - if (nnulled) + if (nnulled > 0) P("%d Errors are nulled because they refer to specific " "functions.\n", nnulled); - if (nnonspec) + if (nnonspec > 0) P("%d Errors are not specific to any file.\n", nnonspec); - if (nthisfile) + if (nthisfile > 0) P("%d Errors are specific to a given file, but not " "to a line.\n", nthisfile); - if (ntrue) + if (ntrue > 0) P("%d Errors are true errors, and can be inserted " "into the files.\n", ntrue); } Index: src/usr.bin/error/pi.c diff -u src/usr.bin/error/pi.c:1.21 src/usr.bin/error/pi.c:1.22 --- src/usr.bin/error/pi.c:1.21 Sat Aug 26 12:43:28 2023 +++ src/usr.bin/error/pi.c Sat Aug 26 14:50:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pi.c,v 1.21 2023/08/26 12:43:28 rillig Exp $ */ +/* $NetBSD: pi.c,v 1.22 2023/08/26 14:50:53 rillig Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)pi.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: pi.c,v 1.21 2023/08/26 12:43:28 rillig Exp $"); +__RCSID("$NetBSD: pi.c,v 1.22 2023/08/26 14:50:53 rillig Exp $"); #endif /* not lint */ #include <stdio.h> @@ -52,10 +52,10 @@ DECL_STRINGS_3(static, unk_hdr, "In", "p static char *c_linenumber; static char **c_header = &unk_hdr[0]; -static boolean alldigits(const char *); -static boolean isdateformat(int, char **); -static boolean instringset(const char *, const char **); -static boolean piptr(const char *); +static bool alldigits(const char *); +static bool isdateformat(int, char **); +static bool instringset(const char *, const char **); +static bool piptr(const char *); /* @@ -154,7 +154,7 @@ static const char *Piroutines[] = { }; -static boolean structured, multiple; +static bool structured, multiple; #if 0 /* not const-correct */ static char *pi_Endmatched[] = {"End", "matched"}; @@ -184,25 +184,24 @@ DECL_STRINGS_4(static, pi_imp2, "imprope #endif -static boolean +static bool alldigits(const char *string) { - for (; *string && isdigit((unsigned char)*string); string++) + for (; *string != '\0' && isdigit((unsigned char)*string); string++) continue; return *string == '\0'; } -static boolean +static bool instringset(const char *member, const char **set) { - for (; *set; set++) { + for (; *set != NULL; set++) if (strcmp(*set, member) == 0) return true; - } return false; } -static boolean +static bool isdateformat(int wordc, char **wordv) { return wordc == 5 @@ -212,7 +211,7 @@ isdateformat(int wordc, char **wordv) && alldigits(wordv[4]); } -static boolean +static bool piptr(const char *string) { if (*string != '-') @@ -239,7 +238,7 @@ pi(void) && ( cur_wordv[1][0] == 'e' || cur_wordv[1][0] == 'E') && piptr(cur_wordv[2]) ) { - boolean longpiptr = 0; + bool longpiptr = false; /* * We have recognized a first pass error of the form: @@ -326,7 +325,7 @@ pi(void) * %s undefined on line%s * %s improperly used on line%s */ - boolean undefined = 0; + bool undefined = false; int wordindex; language = INPI; @@ -338,7 +337,7 @@ pi(void) for (wordindex = undefined ? 5 : 6; wordindex <= cur_wordc; wordindex++) { - if (nwordv) { + if (nwordv != NULL) { free(nwordv[0]); free(nwordv); } @@ -363,7 +362,7 @@ pi(void) cur_wordc += 1 + 3; return C_THISFILE; } - if (strcmp(cur_wordv[1], "...") == 0 && c_linenumber && + if (strcmp(cur_wordv[1], "...") == 0 && c_linenumber != NULL && currentfilename != default_currentfilename) { /* * have a continuation error message @@ -417,7 +416,7 @@ pi(void) * End matched %s on line %d * Inserted keyword end matching %s on line %d */ - multiple = structured = 0; + multiple = structured = false; if ( (cur_wordc == 6 && wordvcmp(cur_wordv+1, 2, pi_Endmatched) == 0) || (cur_wordc == 8 && wordvcmp(cur_wordv+1, 4, pi_Inserted) == 0) Index: src/usr.bin/error/subr.c diff -u src/usr.bin/error/subr.c:1.22 src/usr.bin/error/subr.c:1.23 --- src/usr.bin/error/subr.c:1.22 Sat Aug 26 12:43:28 2023 +++ src/usr.bin/error/subr.c Sat Aug 26 14:50:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr.c,v 1.22 2023/08/26 12:43:28 rillig Exp $ */ +/* $NetBSD: subr.c,v 1.23 2023/08/26 14:50:53 rillig Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: subr.c,v 1.22 2023/08/26 12:43:28 rillig Exp $"); +__RCSID("$NetBSD: subr.c,v 1.23 2023/08/26 14:50:53 rillig Exp $"); #endif /* not lint */ #include <ctype.h> @@ -56,7 +56,7 @@ arrayify(int *e_length, Eptr **e_array, int listindex; for (errorp = header, listlength = 0; - errorp; errorp = errorp->error_next, listlength++) + errorp != NULL; errorp = errorp->error_next, listlength++) continue; array = Calloc(listlength+1, sizeof (Eptr)); for (listindex = 0, errorp = header; @@ -100,13 +100,10 @@ Strdup(const char *s) int position(const char *string, char ch) { - int i; - - if (string) - for (i=1; *string; string++, i++) { + if (string != NULL) + for (int i = 1; *string != '\0'; string++, i++) if (*string == ch) return i; - } return -1; } @@ -118,8 +115,8 @@ substitute(char *string, char chold, cha { char *cp = string; - if (cp) - while (*cp) { + if (cp != NULL) + while (*cp != '\0') { if (*cp == chold) { *cp = chnew; break; @@ -146,7 +143,7 @@ lastchar(const char *string) char firstchar(const char *string) { - if (string) + if (string != NULL) return string[0]; else return '\0'; @@ -206,7 +203,7 @@ persperdexplode(char *string, char **r_p * parse a quoted string that is the result of a format \"%s\"(%d) * return TRUE if this is of the proper format */ -static boolean +static bool qpersperdexplode(char *string, char **r_perd, char **r_pers) { char *cp; @@ -299,7 +296,7 @@ wordvprint(FILE *fyle, int wordc, char * const char *sep = ""; for (i = 0; i < wordc; i++) - if (wordv[i]) { + if (wordv[i] != NULL) { fprintf(fyle, "%s%s",sep,wordv[i]); sep = " "; } @@ -317,22 +314,22 @@ wordvbuild(char *string, int *r_wordc, c int wordcount; int wordindex; - for (wordcount = 0, cp = string; *cp; wordcount++) { - while (*cp && isspace((unsigned char)*cp)) + for (wordcount = 0, cp = string; *cp != '\0'; wordcount++) { + while (isspace((unsigned char)*cp)) cp++; if (*cp == '\0') break; - while (*cp && !isspace((unsigned char)*cp)) + while (*cp != '\0' && !isspace((unsigned char)*cp)) cp++; } wordv = Calloc(wordcount + 1, sizeof (char *)); - for (cp=string, wordindex=0; wordcount; wordindex++, --wordcount) { - while (*cp && isspace((unsigned char)*cp)) + for (cp=string, wordindex=0; wordcount > 0; wordindex++, --wordcount) { + while (isspace((unsigned char)*cp)) cp++; if (*cp == '\0') break; wordv[wordindex] = cp; - while (*cp && !isspace((unsigned char)*cp)) + while (*cp != '\0' && !isspace((unsigned char)*cp)) cp++; *cp++ = '\0'; } Index: src/usr.bin/error/touch.c diff -u src/usr.bin/error/touch.c:1.30 src/usr.bin/error/touch.c:1.31 --- src/usr.bin/error/touch.c:1.30 Sat Aug 26 12:43:28 2023 +++ src/usr.bin/error/touch.c Sat Aug 26 14:50:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: touch.c,v 1.30 2023/08/26 12:43:28 rillig Exp $ */ +/* $NetBSD: touch.c,v 1.31 2023/08/26 14:50:53 rillig Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: touch.c,v 1.30 2023/08/26 12:43:28 rillig Exp $"); +__RCSID("$NetBSD: touch.c,v 1.31 2023/08/26 14:50:53 rillig Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -72,20 +72,20 @@ static int touchstatus = Q_YES; #define F_TOUCHIT 4 static int countfiles(Eptr *); -static int nopertain(Eptr **); +static bool nopertain(Eptr **); static void hackfile(const char *, Eptr **, int, int); -static boolean preview(int, Eptr **, int); +static bool preview(int, Eptr **, int); static int settotouch(const char *); -static void diverterrors(const char *, int, Eptr **, int, boolean, int); -static int oktotouch(const char *); +static void diverterrors(const char *, int, Eptr **, int, bool, int); +static bool oktotouch(const char *); static void execvarg(int, int *, char ***); -static boolean edit(const char *); +static bool edit(const char *); static void insert(int); -static void text(Eptr, boolean); -static boolean writetouched(int); -static int mustoverwrite(FILE *, FILE *); -static int mustwrite(const char *, size_t, FILE *); -static void errorprint(FILE *, Eptr, boolean); +static void text(Eptr, bool); +static bool writetouched(bool); +static bool mustoverwrite(FILE *, FILE *); +static bool mustwrite(const char *, size_t, FILE *); +static void errorprint(FILE *, Eptr, bool); static int probethisfile(const char *); static const char * @@ -120,7 +120,7 @@ findfiles(int my_nerrors, Eptr *my_error my_nfiles = countfiles(my_errors); my_files = Calloc(my_nfiles + 3, sizeof (Eptr*)); - touchedfiles = Calloc(my_nfiles+3, sizeof(boolean)); + touchedfiles = Calloc(my_nfiles+3, sizeof(touchedfiles[0])); /* * Now, partition off the error messages * into those that are synchronization, discarded or @@ -199,7 +199,7 @@ filenames(int my_nfiles, Eptr **my_files { int fi; const char *sep = " "; - int someerrors; + bool someerrors; /* * first, simply dump out errors that @@ -207,8 +207,8 @@ filenames(int my_nfiles, Eptr **my_files */ someerrors = nopertain(my_files); - if (my_nfiles) { - someerrors++; + if (my_nfiles > 0) { + someerrors = true; if (terse) fprintf(stdout, "%d file%s", my_nfiles, plural(my_nfiles)); else @@ -233,21 +233,21 @@ filenames(int my_nfiles, Eptr **my_files /* * Dump out errors that don't pertain to any file */ -static int +static bool nopertain(Eptr **my_files) { int type; - int someerrors = 0; + bool someerrors = false; Eptr *erpp; Eptr errorp; if (my_files[1] - my_files[0] <= 0) - return 0; + return false; for (type = C_UNKNOWN; NOTSORTABLE(type); type++) { if (class_count[type] <= 0) continue; if (type > C_SYNC) - someerrors++; + someerrors = true; if (terse) { fprintf(stdout, "\t%d %s errors NOT PRINTED\n", class_count[type], class_table[type]); @@ -274,7 +274,7 @@ touchfiles(int my_nfiles, Eptr **my_file int fi; Eptr *erpp; int ntrueerrors; - boolean scribbled; + bool scribbled; int n_pissed_on; /* # of file touched*/ int spread; @@ -326,7 +326,7 @@ touchfiles(int my_nfiles, Eptr **my_file static void hackfile(const char *name, Eptr **my_files, int ix, int my_nerrors) { - boolean previewed; + bool previewed; int errordest; /* where errors go */ if (!oktotouch(name)) { @@ -349,14 +349,14 @@ hackfile(const char *name, Eptr **my_fil /* * overwrite the original file */ - writetouched(1); + writetouched(true); } } -static boolean +static bool preview(int my_nerrors, Eptr **my_files, int ix) { - int back; + bool back; Eptr *erpp; if (my_nerrors <= 0) @@ -433,7 +433,7 @@ settotouch(const char *name) static void diverterrors(const char *name, int dest, Eptr **my_files, int ix, - boolean previewed, int nterrors) + bool previewed, int nterrors) { int my_nerrors; Eptr *erpp; @@ -471,7 +471,7 @@ diverterrors(const char *name, int dest, } } -static int +static bool oktotouch(const char *filename) { const char *src; @@ -480,9 +480,9 @@ oktotouch(const char *filename) pat = suffixlist; if (pat == 0) - return 0; + return false; if (*pat == '*') - return 1; + return true; while (*pat++ != '.') continue; --pat; /* point to the period */ @@ -491,26 +491,27 @@ oktotouch(const char *filename) src > filename && *src != '.'; --src) continue; if (*src != '.') - return 0; + return false; - for (src++, pat++, osrc = src; *src && *pat; src = osrc, pat++) { - for (; *src /* not at end of the source */ - && *pat /* not off end of pattern */ + for (src++, pat++, osrc = src; + *src != '\0' && *pat != '\0'; src = osrc, pat++) { + for (; *src != '\0' /* not at end of the source */ + && *pat != '\0' /* not off end of pattern */ && *pat != '.' /* not off end of sub pattern */ && *pat != '*' /* not wild card */ && *src == *pat; /* and equal... */ src++, pat++) continue; if (*src == 0 && (*pat == 0 || *pat == '.' || *pat == '*')) - return 1; + return true; if (*src != 0 && *pat == '*') - return 1; - while (*pat && *pat != '.') + return true; + while (*pat != '\0' && *pat != '.') pat++; - if (!*pat) - return 0; + if (*pat == '\0') + return false; } - return 0; + return false; } /* @@ -561,13 +562,13 @@ static const char *o_name; static char n_name[MAXPATHLEN]; static int o_lineno; static int n_lineno; -static boolean tempfileopen = false; +static bool tempfileopen = false; /* * open the file; guaranteed to be both readable and writable * Well, if it isn't, then return TRUE if something failed */ -static boolean +static bool edit(const char *name) { int fd; @@ -612,7 +613,7 @@ insert(int place) } static void -text(Eptr p, boolean use_all) +text(Eptr p, bool use_all) { int offset = use_all ? 0 : 2; @@ -629,23 +630,23 @@ text(Eptr p, boolean use_all) * write the touched file to its temporary copy, * then bring the temporary in over the local file */ -static boolean -writetouched(int overwrite) +static bool +writetouched(bool overwrite) { size_t nread; FILE *localfile; FILE *temp; - int botch; - int oktorm; + bool botch; + bool oktorm; - botch = 0; - oktorm = 1; + botch = false; + oktorm = true; while ((nread = fread(edbuf, 1, sizeof(edbuf), o_touchedfile)) != 0) { if (nread != fwrite(edbuf, 1, nread, n_touchedfile)) { /* * Catastrophe in temporary area: file system full? */ - botch = 1; + botch = true; warn("write failure: No errors inserted in `%s'", o_name); } @@ -657,17 +658,16 @@ writetouched(int overwrite) * Now, copy the temp file back over the original * file, thus preserving links, etc */ - if (botch == 0 && overwrite) { - botch = 0; + if (!botch && overwrite) { localfile = NULL; temp = NULL; if ((localfile = fopen(o_name, "w")) == NULL) { warn("Can't open file `%s' to overwrite", o_name); - botch++; + botch = true; } if ((temp = fopen(n_name, "r")) == NULL) { warn("Can't open file `%s' to read", n_name); - botch++; + botch = true; } if (!botch) oktorm = mustoverwrite(localfile, temp); @@ -676,7 +676,7 @@ writetouched(int overwrite) if (temp != NULL) fclose(temp); } - if (oktorm == 0) + if (!oktorm) errx(1, "Catastrophe: A copy of `%s': was saved in `%s'", o_name, n_name); /* @@ -688,33 +688,33 @@ writetouched(int overwrite) } /* - * return 1 if the tmpfile can be removed after writing it out + * return whether the tmpfile can be removed after writing it out */ -static int +static bool mustoverwrite(FILE *preciousfile, FILE *temp) { size_t nread; while ((nread = fread(edbuf, 1, sizeof(edbuf), temp)) != 0) { - if (mustwrite(edbuf, nread, preciousfile) == 0) - return 0; + if (!mustwrite(edbuf, nread, preciousfile)) + return false; } - return 1; + return true; } /* - * return 0 on catastrophe + * return false on catastrophe */ -static int +static bool mustwrite(const char *base, size_t n, FILE *preciousfile) { size_t nwrote; if (n == 0) - return 1; + return true; nwrote = fwrite(base, 1, n, preciousfile); if (nwrote == n) - return 1; + return true; warn("write failed"); switch (inquire(terse ? "Botch overwriting: retry? " @@ -722,25 +722,25 @@ mustwrite(const char *base, size_t n, FI case Q_YES: case Q_yes: mustwrite(base + nwrote, n - nwrote, preciousfile); - return 1; + return true; case Q_NO: case Q_no: switch (inquire("Are you sure? ")) { case Q_error: case Q_YES: case Q_yes: - return 0; + return false; case Q_NO: case Q_no: mustwrite(base + nwrote, n - nwrote, preciousfile); - return 1; + return true; default: abort(); } /* FALLTHROUGH */ case Q_error: default: - return 0; + return false; } } @@ -760,7 +760,7 @@ onintr(int sig) /* * Don't overwrite the original file! */ - writetouched(0); + writetouched(false); } (void)raise_default_signal(sig); _exit(127); @@ -769,7 +769,7 @@ onintr(int sig) } static void -errorprint(FILE *place, Eptr errorp, boolean print_all) +errorprint(FILE *place, Eptr errorp, bool print_all) { int offset = print_all ? 0 : 2;