]> diplodocus.org Git - nmh/blobdiff - sbr/seq_list.c
new.c: Order two return statements to match comment.
[nmh] / sbr / seq_list.c
index afa8671c5bc479266d5dffdb868e8772c60553e7..b7ed570794f1447d1ada46944535b9016e7eb6e8 100644 (file)
@@ -1,12 +1,13 @@
-
-/*
- * seq_list.c -- Get all messages in a sequence and return them
+/* seq_list.c -- Get all messages in a sequence and return them
  *            -- as a space separated list of message ranges.
  *
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 
 /* allocate this much buffer space at a time */
 #define MAXBUFFER 1024
@@ -25,8 +26,7 @@ seq_list(struct msgs *mp, char *seqname)
     /* On first invocation, allocate initial buffer space */
     if (!buffer) {
        len = MAXBUFFER;
-       if (!(buffer = malloc ((size_t) len)))
-           adios (NULL, "unable to malloc storage in seq_list");
+       buffer = mh_xmalloc ((size_t) len);
     }
 
     /*
@@ -37,10 +37,10 @@ seq_list(struct msgs *mp, char *seqname)
      */
     if (!strcmp (current, seqname)) {
        if (mp->curmsg) {       
-           sprintf(buffer, "%s", m_name(mp->curmsg));
-           return (buffer);
-       } else
-           return (NULL);
+           snprintf(buffer, len, "%s", m_name(mp->curmsg));
+           return buffer;
+       }
+        return NULL;
     }
 
     /* If the folder is empty, just return NULL */
@@ -71,8 +71,7 @@ seq_list(struct msgs *mp, char *seqname)
            char *newbuf;
 
            len += MAXBUFFER;
-           if (!(newbuf = realloc (buffer, (size_t) len)))
-               adios (NULL, "unable to realloc storage in seq_list");
+           newbuf = mh_xrealloc (buffer, (size_t) len);
            bp = newbuf + (bp - buffer);
            buffer = newbuf;
        }
@@ -84,7 +83,7 @@ seq_list(struct msgs *mp, char *seqname)
        if (bp > buffer)
            *bp++ = ' ';
 
-       sprintf(bp, "%s", m_name(i));
+       strcpy(bp, m_name(i));
        bp += strlen(bp);
        j = i;                  /* Remember beginning of message range */
 
@@ -96,9 +95,10 @@ seq_list(struct msgs *mp, char *seqname)
            ;
 
        if (i - j > 1) {
-           sprintf(bp, "-%s", m_name(i - 1));
+            *bp++ = '-';
+           strcpy(bp, m_name(i - 1));
            bp += strlen(bp);
        }
     }
-    return (bp > buffer? buffer : NULL);
+    return bp > buffer ? buffer : NULL;
 }