* Imap profiling: memreadline function that returns the copied stringlength so we...
authorWilfried Göesgens <willi@citadel.org>
Sat, 13 Oct 2007 15:55:23 +0000 (15:55 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 13 Oct 2007 15:55:23 +0000 (15:55 +0000)
citadel/tools.c
citadel/tools.h

index 75fa3fbe6076f9a7641aeae84fc9b4d349065bab..cd8f1510d5ae9a897b8782d79b788e12b879993b 100644 (file)
@@ -594,6 +594,36 @@ char *memreadline(char *start, char *buf, int maxlen)
 }
 
 
+/** 
+ * \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
+ * \param retlen the length of the returned string
+ * \return Pointer to the source memory right after we stopped reading.
+ */
+char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen)
+{
+       char ch;
+       char *ptr;
+       int len = 0;            /**< tally our own length to avoid strlen() delays */
+
+       ptr = start;
+
+       while (1) {
+               ch = *ptr++;
+               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
+                       buf[len++] = ch;
+               }
+               if ((ch == 10) || (ch == 0)) {
+                       buf[len] = 0;
+                       *retlen = len;
+                       return ptr;
+               }
+       }
+}
+
+
 
 
 /*
index 30ae142617533f742bdbbc4547c22e1da264d097..4f205d6fa56b45419183672f3ffb6d321e8508d4 100644 (file)
@@ -15,6 +15,7 @@ void remove_token(char *source, int parmnum, char separator);
 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
 int is_msg_in_sequence_set(char *mset, long msgnum);
 char *memreadline(char *start, char *buf, int maxlen);
+char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
 
 #ifndef HAVE_STRNCASECMP
 int strncasecmp(char *, char *, int);