]> granicus.if.org Git - neomutt/commitdiff
move unsigned atoi functions
authorRichard Russon <rich@flatcap.org>
Wed, 17 Jan 2018 18:21:22 +0000 (18:21 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 18 Jan 2018 23:32:12 +0000 (23:32 +0000)
imap/command.c
imap/imap.c
imap/message.c
imap/util.c
mutt/string.c
mutt/string2.h
muttlib.c
protos.h

index ad36a483465a7dbef753835a40771348ecd1d414..5fd774eb718bb243de9f82eb06dbfcea80827b9b 100644 (file)
@@ -255,7 +255,7 @@ static void cmd_parse_expunge(struct ImapData *idata, const char *s)
 
   mutt_debug(2, "Handling EXPUNGE\n");
 
-  if (mutt_atoui(s, &exp_msn) < 0 || exp_msn < 1 || exp_msn > idata->max_msn)
+  if (mutt_str_atoui(s, &exp_msn) < 0 || exp_msn < 1 || exp_msn > idata->max_msn)
     return;
 
   h = idata->msn_index[exp_msn - 1];
@@ -300,7 +300,7 @@ static void cmd_parse_fetch(struct ImapData *idata, char *s)
 
   mutt_debug(3, "Handling FETCH\n");
 
-  if (mutt_atoui(s, &msn) < 0 || msn < 1 || msn > idata->max_msn)
+  if (mutt_str_atoui(s, &msn) < 0 || msn < 1 || msn > idata->max_msn)
   {
     mutt_debug(3, "#1 FETCH response ignored for this message\n");
     return;
@@ -346,7 +346,7 @@ static void cmd_parse_fetch(struct ImapData *idata, char *s)
     {
       s += 3;
       SKIPWS(s);
-      if (mutt_atoui(s, &uid) < 0)
+      if (mutt_str_atoui(s, &uid) < 0)
       {
         mutt_debug(2, "Illegal UID.  Skipping update.\n");
         return;
@@ -614,7 +614,7 @@ static void cmd_parse_search(struct ImapData *idata, const char *s)
 
   while ((s = imap_next_word((char *) s)) && *s != '\0')
   {
-    if (mutt_atoui(s, &uid) < 0)
+    if (mutt_str_atoui(s, &uid) < 0)
       continue;
     h = (struct Header *) mutt_hash_int_find(idata->uid_hash, uid);
     if (h)
@@ -841,7 +841,7 @@ static int cmd_handle_untagged(struct ImapData *idata)
       mutt_debug(2, "Handling EXISTS\n");
 
       /* new mail arrived */
-      if (mutt_atoui(pn, &count) < 0)
+      if (mutt_str_atoui(pn, &count) < 0)
       {
         mutt_debug(1, "Malformed EXISTS: '%s'\n", pn);
       }
index 85be54dcb179d9e7eacb9d2aa8918e24f439a519..95751760abf5a9cfe68798e003abeea21f058621 100644 (file)
@@ -2144,7 +2144,7 @@ static int imap_open_mailbox(struct Context *ctx)
       mutt_debug(3, "Getting mailbox UIDVALIDITY\n");
       pc += 3;
       pc = imap_next_word(pc);
-      if (mutt_atoui(pc, &idata->uid_validity) < 0)
+      if (mutt_str_atoui(pc, &idata->uid_validity) < 0)
         goto fail;
       status->uidvalidity = idata->uid_validity;
     }
@@ -2153,7 +2153,7 @@ static int imap_open_mailbox(struct Context *ctx)
       mutt_debug(3, "Getting mailbox UIDNEXT\n");
       pc += 3;
       pc = imap_next_word(pc);
-      if (mutt_atoui(pc, &idata->uidnext) < 0)
+      if (mutt_str_atoui(pc, &idata->uidnext) < 0)
         goto fail;
       status->uidnext = idata->uidnext;
     }
index 5581b54f0be8cb3c2156db3d33999fc01f922e56..aedb5baa4e60a2d8575f17f4bbef142cb9334567 100644 (file)
@@ -330,7 +330,7 @@ static int msg_parse_fetch(struct ImapHeader *h, char *s)
     {
       s += 3;
       SKIPWS(s);
-      if (mutt_atoui(s, &h->data->uid) < 0)
+      if (mutt_str_atoui(s, &h->data->uid) < 0)
         return -1;
 
       s = imap_next_word(s);
@@ -410,7 +410,7 @@ static int msg_fetch_header(struct Context *ctx, struct ImapHeader *h, char *buf
 
   /* skip to message number */
   buf = imap_next_word(buf);
-  if (mutt_atoui(buf, &h->data->msn) < 0)
+  if (mutt_str_atoui(buf, &h->data->msn) < 0)
     return rc;
 
   /* find FETCH tag */
@@ -1101,7 +1101,7 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno)
         if (mutt_str_strncasecmp("UID", pc, 3) == 0)
         {
           pc = imap_next_word(pc);
-          if (mutt_atoui(pc, &uid) < 0)
+          if (mutt_str_atoui(pc, &uid) < 0)
             goto bail;
           if (uid != HEADER_DATA(h)->uid)
             mutt_error(_(
index 5b00c5aef8c3c0717fb534645067294b8364a0a6..e18c16661cf8feb21799383ff585e3c1c868a869 100644 (file)
@@ -750,7 +750,7 @@ int imap_get_literal_count(const char *buf, unsigned int *bytes)
   while (isdigit((unsigned char) *pc))
     pc++;
   *pc = '\0';
-  if (mutt_atoui(pn, bytes) < 0)
+  if (mutt_str_atoui(pn, bytes) < 0)
     return -1;
 
   return 0;
index cd40b0289510e0deb8db97dc687b0ab6e1eeded3..ce4f90879e9030a07d212e426fb992e6b6ea3650 100644 (file)
@@ -32,6 +32,8 @@
  * | mutt_str_atoi()               | Convert ASCII string to an integer
  * | mutt_str_atol()               | Convert ASCII string to a long
  * | mutt_str_atos()               | Convert ASCII string to a short
+ * | mutt_str_atoui()              | Convert ASCII string to an unsigned integer
+ * | mutt_str_atoul()              | Convert ASCII string to an unsigned long
  * | mutt_str_dequote_comment()    | Un-escape characters in an email address comment
  * | mutt_str_find_word()          | Find the next word (non-space)
  * | mutt_str_getenv()             | Get an environment variable
@@ -246,6 +248,71 @@ int mutt_str_atoi(const char *str, int *dst)
   return 0;
 }
 
+/**
+ * mutt_str_atoui - Convert ASCII string to an unsigned integer
+ * @param[in]  str String to read
+ * @param[out] dst Store the result
+ * @retval  1 Successful conversion, with trailing characters 
+ * @retval  0 Successful conversion                           
+ * @retval -1 Invalid input                                   
+ * @retval -2 Input out of range                              
+ *
+ * @note
+ * This function's return value differs from the other functions.
+ * They return -1 if there is input beyond the number.
+ */
+int mutt_str_atoui(const char *str, unsigned int *dst)
+{
+  int rc;
+  unsigned long res = 0;
+  unsigned int tmp = 0;
+  unsigned int *t = dst ? dst : &tmp;
+
+  *t = 0;
+
+  rc = mutt_str_atoul(str, &res);
+  if (rc < 0)
+    return rc;
+  if ((unsigned int) res != res)
+    return -2;
+
+  *t = (unsigned int) res;
+  return rc;
+}
+
+/**
+ * mutt_str_atoul - Convert ASCII string to an unsigned long
+ * @param[in]  str String to read
+ * @param[out] dst Store the result
+ * @retval  1 Successful conversion, with trailing characters 
+ * @retval  0 Successful conversion                           
+ * @retval -1 Invalid input                                   
+ *
+ * @note
+ * This function's return value differs from the other functions.
+ * They return -1 if there is input beyond the number.
+ */
+int mutt_str_atoul(const char *str, unsigned long *dst)
+{
+  unsigned long r = 0;
+  unsigned long *res = dst ? dst : &r;
+  char *e = NULL;
+
+  /* no input: 0 */
+  if (!str || !*str)
+  {
+    *res = 0;
+    return 0;
+  }
+
+  errno = 0;
+  *res = strtoul(str, &e, 10);
+  if ((*res == ULONG_MAX) && (errno == ERANGE))
+    return -1;
+  if (e && (*e != '\0'))
+    return 1;
+  return 0;
+}
 /**
  * mutt_str_strdup - Copy a string, safely
  * @param s String to copy
index 9c73d3a1c5c0d6c654cce70ed3d2fbbf8dc73600..e0858837e51457c15220fbffd84f6c83d04827f2 100644 (file)
@@ -66,6 +66,8 @@ void        mutt_str_append_item(char **p, const char *item, int sep);
 int         mutt_str_atoi(const char *str, int *dst);
 int         mutt_str_atol(const char *str, long *dst);
 int         mutt_str_atos(const char *str, short *dst);
+int         mutt_str_atoui(const char *str, unsigned int *dst);
+int         mutt_str_atoul(const char *str, unsigned long *dst);
 void        mutt_str_dequote_comment(char *s);
 const char *mutt_str_find_word(const char *src);
 const char *mutt_str_getenv(const char *name);
index 8207aba76197eb6e65960981bc431bb86ba67cd2..dba155b99b79ae998a7c0886eac38a9a817eba39 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1572,58 +1572,3 @@ int mutt_inbox_cmp(const char *a, const char *b)
   return 0;
 }
 
-/* NOTE: this function's return value breaks with the above three functions.
- * The imap code lexes uint values out of a stream of characters without
- * tokenization.  The above functions return -1 if there is input beyond
- * the number.
- *
- * returns: 1 - successful conversion, with trailing characters
- *          0 - successful conversion
- *         -1 - invalid input
- *         -2 - input out of range
- */
-int mutt_atoui(const char *str, unsigned int *dst)
-{
-  int rc;
-  unsigned long res;
-  unsigned int tmp;
-  unsigned int *t = dst ? dst : &tmp;
-
-  *t = 0;
-
-  if ((rc = mutt_atoul(str, &res)) < 0)
-    return rc;
-  if ((unsigned int) res != res)
-    return -2;
-
-  *t = (unsigned int) res;
-  return rc;
-}
-
-/* NOTE: this function's return value is different from mutt_atol.
- *
- * returns: 1 - successful conversion, with trailing characters
- *          0 - successful conversion
- *         -1 - invalid input
- */
-int mutt_atoul(const char *str, unsigned long *dst)
-{
-  unsigned long r;
-  unsigned long *res = dst ? dst : &r;
-  char *e = NULL;
-
-  /* no input: 0 */
-  if (!str || !*str)
-  {
-    *res = 0;
-    return 0;
-  }
-
-  errno = 0;
-  *res = strtoul(str, &e, 10);
-  if (*res == ULONG_MAX && errno == ERANGE)
-    return -1;
-  if (e && *e != '\0')
-    return 1;
-  return 0;
-}
index fe3b9276abdd26c68ed024e7ce7fe56df0b9237c..e2595e95a40546419f4fc85faafaf18348fa0723 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -364,7 +364,4 @@ bool message_is_visible(struct Context *ctx, int index);
 int mutt_addrlist_to_intl(struct Address *a, char **err);
 int mutt_addrlist_to_local(struct Address *a);
 
-int mutt_atoui(const char *str, unsigned int *dst);
-int mutt_atoul(const char *str, unsigned long *dst);
-
 #endif /* _MUTT_PROTOS_H */