* brought over the tuned memreadline from webcit
authorWilfried Göesgens <willi@citadel.org>
Thu, 9 Aug 2007 23:37:27 +0000 (23:37 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 9 Aug 2007 23:37:27 +0000 (23:37 +0000)
citadel/tools.c

index af91ce78fb1d005ddbb40271620b92dcef313426..5a9a9839733ab01287f7d993db5f2034979c4ab5 100644 (file)
@@ -479,33 +479,36 @@ int is_msg_in_sequence_set(char *mset, long msgnum) {
 }
 
 
-/*
- * Utility function to "readline" from memory
- * (returns new pointer)
+/** 
+ * \brief Utility function to "readline" from memory
+ * \param start Location in memory from which we are reading.
+ * \param buf the buffer to place the string in.
+ * \param maxlen Size of string buffer
+ * \return Pointer to the source memory right after we stopped reading.
  */
 char *memreadline(char *start, char *buf, int maxlen)
 {
-        char ch;
-        char *ptr;
-        int len = 0;    /* tally our own length to avoid strlen() delays */
-
-        ptr = start;
-        memset(buf, 0, maxlen);
-
-        while (1) {
-                ch = *ptr++;
-                if ( (len < (maxlen - 1)) && (ch != 13) && (ch != 10) ) {
-                        buf[strlen(buf) + 1] = 0;
-                        buf[strlen(buf)] = ch;
-                        ++len;
-                }
-                if ((ch == 10) || (ch == 0)) {
-                        return ptr;
-                }
-        }
+       char ch;
+       char *ptr;
+       int len = 0;            /**< tally our own length to avoid strlen() delays */
+
+       ptr = start;
+       memset(buf, 0, maxlen);
+
+       while (1) {
+               ch = *ptr++;
+               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
+                       buf[len++] = ch;
+                       buf[len] = 0;
+               }
+               if ((ch == 10) || (ch == 0)) {
+                       return ptr;
+               }
+       }
 }
 
 
+
 /*
  * Strip a boundarized substring out of a string (for example, remove
  * parentheses and anything inside them).