we have buffers, add an API to readln directly in a buffer instead of implementing...
[apps/madmutt.git] / lib-sys / mutt_socket.c
index 3528db4..194ad5a 100644 (file)
@@ -150,6 +150,23 @@ int mutt_socket_readln(char *buf, ssize_t buflen, CONNECTION * conn)
   return i + 1;
 }
 
+int mutt_socket_readln2(buffer_t *buf, CONNECTION *conn)
+{
+    char ch;
+
+    while (mutt_socket_readchar(conn, &ch) == 1) {
+        if (ch == '\n') {
+            if (buf->data[buf->len - 1] == '\r') {
+                buf->data[--buf->len] = '\0';
+            }
+            return 0;
+        }
+        buffer_addch(buf, ch);
+    }
+
+    return -1;
+}
+
 CONNECTION *mutt_socket_head (void)
 {
   return Connections;