]> granicus.if.org Git - neomutt/commitdiff
boolify
authorRichard Russon <rich@flatcap.org>
Mon, 10 Sep 2018 20:39:31 +0000 (21:39 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 10 Sep 2018 22:26:19 +0000 (23:26 +0100)
- be_edit_header
- boolify mutt_file_lock
  The parameters were only being used as bools.
- boolify maildir_delayed_parsing

compress.c
edit.c
hcache/bdb.c
maildir/mh.c
mutt/file.c
mutt/file.h
nntp/newsrc.c

index 6061149e9d78c0c1250e18b6af5012d6a08e673f..fe6537aa1eb0966ef8b688e16756fd3eae546da1 100644 (file)
@@ -105,7 +105,7 @@ static bool lock_realpath(struct Mailbox *mailbox, bool excl)
     return false;
   }
 
-  int r = mutt_file_lock(fileno(ci->lockfp), excl, 1);
+  int r = mutt_file_lock(fileno(ci->lockfp), excl, true);
   if (r == 0)
     ci->locked = true;
   else if (excl)
diff --git a/edit.c b/edit.c
index 648ec85a54e0838b3d0a634c7b6756d0ae706fcf..83be5120efd72566b7a824ead5092276819dd5dd 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -298,7 +298,7 @@ static void be_print_header(struct Envelope *env)
  * @param e     Message headers
  * @param force override the $ask* vars (used for the ~h command)
  */
-static void be_edit_header(struct Envelope *e, int force)
+static void be_edit_header(struct Envelope *e, bool force)
 {
   char tmp[HUGE_STRING];
 
@@ -399,7 +399,7 @@ int mutt_builtin_editor(const char *path, struct Header *msg, struct Header *cur
 
   scrollok(stdscr, true);
 
-  be_edit_header(msg->env, 0);
+  be_edit_header(msg->env, false);
 
   addstr(_("(End message with a . on a line by itself)\n"));
 
@@ -440,7 +440,7 @@ int mutt_builtin_editor(const char *path, struct Header *msg, struct Header *cur
           msg->env->cc = mutt_expand_aliases(msg->env->cc);
           break;
         case 'h':
-          be_edit_header(msg->env, 1);
+          be_edit_header(msg->env, true);
           break;
         case 'F':
         case 'f':
index f061ccd10cae55c2528bebf2f532785728fab97f..702bf26bef91829100f278369e93fc44b14d0d69 100644 (file)
@@ -107,7 +107,7 @@ static void *hcache_bdb_open(const char *path)
     return NULL;
   }
 
-  if (mutt_file_lock(ctx->fd, 1, 5))
+  if (mutt_file_lock(ctx->fd, true, true))
     goto fail_close;
 
   ret = db_env_create(&ctx->env, 0);
index b1f27d78217e5529c4f9049b7e1250027849b723..dd09838e53937e356729efab7622dc46d1ea4c32 100644 (file)
@@ -1305,7 +1305,7 @@ static void maildir_delayed_parsing(struct Mailbox *mailbox, struct Maildir **md
   struct Maildir *p, *last = NULL;
   char fn[PATH_MAX];
   int count;
-  int sort = 0;
+  bool sort = false;
 #ifdef USE_HCACHE
   const char *key = NULL;
   size_t keylen;
@@ -1336,7 +1336,7 @@ static void maildir_delayed_parsing(struct Mailbox *mailbox, struct Maildir **md
         *md = p;
       else
         last->next = p;
-      sort = 1;
+      sort = true;
       p = skip_duplicates(p, &last);
       snprintf(fn, sizeof(fn), "%s/%s", mailbox->path, p->h->path);
     }
index b6a7900da51fa815d9bb43905340e730e7591d4d..d8cae66e4cb96855cae5e3e2a4d034b50c89ca18 100644 (file)
@@ -1010,8 +1010,8 @@ int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st)
 /**
  * mutt_file_lock - (try to) lock a file using fcntl()
  * @param fd      File descriptor to file
- * @param excl    If set, try to lock exclusively
- * @param timeout Retry after this time
+ * @param excl    If true, try to lock exclusively
+ * @param timeout If true, Retry #MAX_LOCK_ATTEMPTS times
  * @retval  0 Success
  * @retval -1 Failure
  *
@@ -1019,20 +1019,17 @@ int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st)
  *
  * Use mutt_file_unlock() to unlock the file.
  */
-int mutt_file_lock(int fd, int excl, int timeout)
+int mutt_file_lock(int fd, bool excl, bool timeout)
 {
-  int count;
-  int attempt;
   struct stat sb = { 0 }, prev_sb = { 0 };
+  int count = 0;
+  int attempt = 0;
 
   struct flock lck;
-
   memset(&lck, 0, sizeof(struct flock));
   lck.l_type = excl ? F_WRLCK : F_RDLCK;
   lck.l_whence = SEEK_SET;
 
-  count = 0;
-  attempt = 0;
   while (fcntl(fd, F_SETLK, &lck) == -1)
   {
     mutt_debug(1, "fcntl errno %d.\n", errno);
@@ -1085,8 +1082,8 @@ int mutt_file_unlock(int fd)
 /**
  * mutt_file_lock - (try to) lock a file using flock()
  * @param fd      File descriptor to file
- * @param excl    If set, try to lock exclusively
- * @param timeout Retry after this time
+ * @param excl    If true, try to lock exclusively
+ * @param timeout If true, Retry #MAX_LOCK_ATTEMPTS times
  * @retval  0 Success
  * @retval -1 Failure
  *
@@ -1094,21 +1091,19 @@ int mutt_file_unlock(int fd)
  *
  * Use mutt_file_unlock() to unlock the file.
  */
-int mutt_file_lock(int fd, int excl, int timeout)
+int mutt_file_lock(int fd, bool excl, bool timeout)
 {
-  int count;
-  int attempt;
   struct stat sb = { 0 }, prev_sb = { 0 };
-  int r = 0;
+  int rc = 0;
+  int count = 0;
+  int attempt = 0;
 
-  count = 0;
-  attempt = 0;
   while (flock(fd, (excl ? LOCK_EX : LOCK_SH) | LOCK_NB) == -1)
   {
     if (errno != EWOULDBLOCK)
     {
       mutt_perror("flock");
-      r = -1;
+      rc = -1;
       break;
     }
 
@@ -1123,7 +1118,7 @@ int mutt_file_lock(int fd, int excl, int timeout)
     {
       if (timeout)
         mutt_error(_("Timeout exceeded while attempting flock lock"));
-      r = -1;
+      rc = -1;
       break;
     }
 
@@ -1134,12 +1129,12 @@ int mutt_file_lock(int fd, int excl, int timeout)
   }
 
   /* release any other locks obtained in this routine */
-  if (r != 0)
+  if (rc != 0)
   {
     flock(fd, LOCK_UN);
   }
 
-  return r;
+  return rc;
 }
 
 /**
@@ -1169,7 +1164,7 @@ void mutt_file_unlink_empty(const char *path)
   if (fd == -1)
     return;
 
-  if (mutt_file_lock(fd, 1, 1) == -1)
+  if (mutt_file_lock(fd, true, true) == -1)
   {
     close(fd);
     return;
index 693d790cfd23cf5df6f92a48fd50a52d5161a767..7776fef03b16dcf7a4c390a05928169bb9e6eb7a 100644 (file)
@@ -49,7 +49,7 @@ void        mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *f
 int         mutt_file_fclose(FILE **f);
 FILE *      mutt_file_fopen(const char *path, const char *mode);
 int         mutt_file_fsync_close(FILE **f);
-int         mutt_file_lock(int fd, int excl, int timeout);
+int         mutt_file_lock(int fd, bool excl, bool timeout);
 int         mutt_file_mkdir(const char *path, mode_t mode);
 FILE *      mutt_file_mkstemp_full(const char *file, int line, const char *func);
 #define     mutt_file_mkstemp() mutt_file_mkstemp_full(__FILE__, __LINE__, __func__)
index 5d180735b3a4fbab7220c922f7bd37d6a6a4958a..fc7b82046fe15c5c10a5fef429d794d304b4f369 100644 (file)
@@ -213,7 +213,7 @@ int nntp_newsrc_parse(struct NntpServer *nserv)
 
   /* lock it */
   mutt_debug(1, "Locking %s\n", nserv->newsrc_file);
-  if (mutt_file_lock(fileno(nserv->newsrc_fp), 0, 1))
+  if (mutt_file_lock(fileno(nserv->newsrc_fp), false, true))
   {
     mutt_file_fclose(&nserv->newsrc_fp);
     return -1;