tweaks: change another function with two possible results to boolean

master
Benno Schulenberg 2020-02-09 14:30:57 +01:00
parent d5ce44820a
commit 1d52548575
1 changed files with 10 additions and 9 deletions

View File

@ -145,7 +145,7 @@ bool delete_lockfile(const char *lockfilename)
/* Write a lockfile, under the given lockfilename. This ALWAYS annihilates /* Write a lockfile, under the given lockfilename. This ALWAYS annihilates
* an existing version of that file. Return 1 on success, and 0 on failure. */ * an existing version of that file. Return 1 on success, and 0 on failure. */
int write_lockfile(const char *lockfilename, const char *filename, bool modified) bool write_lockfile(const char *lockfilename, const char *filename, bool modified)
{ {
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
int cflags, fd; int cflags, fd;
@ -165,7 +165,7 @@ int write_lockfile(const char *lockfilename, const char *filename, bool modified
if ((mypwuid = getpwuid(myuid)) == NULL) { if ((mypwuid = getpwuid(myuid)) == NULL) {
/* TRANSLATORS: Keep the next eight messages at most 76 characters. */ /* TRANSLATORS: Keep the next eight messages at most 76 characters. */
statusline(MILD, _("Couldn't determine my identity for lock file")); statusline(MILD, _("Couldn't determine my identity for lock file"));
return 0; return FALSE;
} }
if (gethostname(myhostname, 31) < 0) { if (gethostname(myhostname, 31) < 0) {
@ -173,14 +173,14 @@ int write_lockfile(const char *lockfilename, const char *filename, bool modified
myhostname[31] = '\0'; myhostname[31] = '\0';
else { else {
statusline(MILD, _("Couldn't determine hostname: %s"), strerror(errno)); statusline(MILD, _("Couldn't determine hostname: %s"), strerror(errno));
return 0; return FALSE;
} }
} }
/* If the lockfile exists, try to delete it. */ /* If the lockfile exists, try to delete it. */
if (stat(lockfilename, &fileinfo) != -1) if (stat(lockfilename, &fileinfo) != -1)
if (!delete_lockfile(lockfilename)) if (!delete_lockfile(lockfilename))
return 0; return FALSE;
if (ISSET(INSECURE_BACKUP)) if (ISSET(INSECURE_BACKUP))
cflags = O_WRONLY | O_CREAT | O_APPEND; cflags = O_WRONLY | O_CREAT | O_APPEND;
@ -193,7 +193,7 @@ int write_lockfile(const char *lockfilename, const char *filename, bool modified
if (fd < 0) { if (fd < 0) {
statusline(MILD, _("Error writing lock file %s: %s"), statusline(MILD, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
return 0; return FALSE;
} }
/* Try to associate a stream with the now open lockfile. */ /* Try to associate a stream with the now open lockfile. */
@ -203,7 +203,7 @@ int write_lockfile(const char *lockfilename, const char *filename, bool modified
statusline(MILD, _("Error writing lock file %s: %s"), statusline(MILD, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
close(fd); close(fd);
return 0; return FALSE;
} }
lockdata = charalloc(LOCKSIZE); lockdata = charalloc(LOCKSIZE);
@ -243,12 +243,12 @@ int write_lockfile(const char *lockfilename, const char *filename, bool modified
if (fclose(filestream) == EOF || wroteamt < LOCKSIZE) { if (fclose(filestream) == EOF || wroteamt < LOCKSIZE) {
statusline(MILD, _("Error writing lock file %s: %s"), statusline(MILD, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
return 0; return FALSE;
} }
openfile->lock_filename = (char *)lockfilename; openfile->lock_filename = (char *)lockfilename;
#endif #endif
return 1; return TRUE;
} }
/* Deal with lockfiles. Return -1 on refusing to override the lockfile, /* Deal with lockfiles. Return -1 on refusing to override the lockfile,
@ -348,7 +348,8 @@ int do_lockfile(const char *filename, bool ask_the_user)
} }
} }
retval = write_lockfile(lockfilename, filename, FALSE); if (write_lockfile(lockfilename, filename, FALSE))
retval = 1;
free_the_name: free_the_name:
if (retval < 1) if (retval < 1)