aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-03-24 00:22:29 +0800
committerDan Winship <danw@src.gnome.org>2000-03-24 00:22:29 +0800
commit6d99be7149ce15e10460f80a218b0f4333b8c4be (patch)
treeb681cbf085ee9e6733a6476ebc859d4d771b2991
parent58aa78c64b937828eb30550239eda4a429e66b19 (diff)
downloadgsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.tar
gsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.tar.gz
gsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.tar.bz2
gsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.tar.lz
gsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.tar.xz
gsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.tar.zst
gsoc2013-evolution-6d99be7149ce15e10460f80a218b0f4333b8c4be.zip
Function to read one line of any size from a stream and return it in
* camel-stream-buffer.c (camel_stream_buffer_read_line): Function to read one line of any size from a stream and return it in allocated memory. Also add camel-stream-buffer.h to camel.h and CamelStreamBuffer to camel-types.h. svn path=/trunk/; revision=2152
-rw-r--r--camel/ChangeLog6
-rw-r--r--camel/camel-stream-buffer.c43
-rw-r--r--camel/camel-stream-buffer.h6
-rw-r--r--camel/camel-types.h1
-rw-r--r--camel/camel.h1
5 files changed, 55 insertions, 2 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 0c11050043..3bb7c1529b 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,9 @@
+2000-03-23 Dan Winship <danw@helixcode.com>
+
+ * camel-stream-buffer.c (camel_stream_buffer_read_line): Function
+ to read one line of any size from a stream and return it in
+ allocated memory.
+
2000-03-22 Dan Winship <danw@helixcode.com>
* camel-service.c (camel_service_query_auth_types): New function
diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c
index cb4f0d4831..8dbe50a133 100644
--- a/camel/camel-stream-buffer.c
+++ b/camel/camel-stream-buffer.c
@@ -452,3 +452,46 @@ int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf, int max)
return outptr-buf;
}
+
+/**
+ * camel_stream_buffer_read_line: read a complete line from the stream
+ * @sbf: A CamelStreamBuffer
+ *
+ * This function reads a complete newline-terminated line from the stream
+ * and returns it in allocated memory. The trailing newline (and carriage
+ * return if any) are not included in the returned string.
+ *
+ * Return value: the line read, which the caller must free when done with,
+ * or NULL on eof or error.
+ **/
+char *
+camel_stream_buffer_read_line (CamelStreamBuffer *sbf)
+{
+ char *buf, *p;
+ int bufsiz, nread;
+
+ bufsiz = 80;
+ p = buf = g_malloc (bufsiz);
+
+ while (1) {
+ nread = camel_stream_buffer_gets (sbf, p, bufsiz - (p - buf));
+ if (nread == 0) {
+ g_free (buf);
+ return NULL;
+ }
+
+ p += nread;
+ if (*(p - 1) == '\n')
+ break;
+
+ nread = p - buf;
+ bufsiz *= 2;
+ buf = g_realloc (buf, bufsiz);
+ p = buf + nread;
+ }
+
+ *--p = '\0';
+ if (*(p - 1) == '\r')
+ *--p = '\0';
+ return buf;
+}
diff --git a/camel/camel-stream-buffer.h b/camel/camel-stream-buffer.h
index c4b7e4b2e7..967c33e553 100644
--- a/camel/camel-stream-buffer.h
+++ b/camel/camel-stream-buffer.h
@@ -53,7 +53,7 @@ typedef enum
CAMEL_STREAM_BUFFER_MODE = 0x80
} CamelStreamBufferMode;
-typedef struct
+struct _CamelStreamBuffer
{
CamelStream parent_object;
@@ -67,7 +67,7 @@ typedef struct
CamelStreamBufferMode mode;
unsigned int flags; /* internal flags */
-} CamelStreamBuffer;
+};
@@ -95,6 +95,8 @@ CamelStream *camel_stream_buffer_set_vbuf (CamelStreamBuffer *b, CamelStreamBuff
/* read a line of characters */
int camel_stream_buffer_gets(CamelStreamBuffer *b, char *buf, int max);
+char *camel_stream_buffer_read_line (CamelStreamBuffer *sbf);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/camel/camel-types.h b/camel/camel-types.h
index c070404e95..924c51db6d 100644
--- a/camel/camel-types.h
+++ b/camel/camel-types.h
@@ -45,6 +45,7 @@ typedef struct _CamelSimpleDataWrapper CamelSimpleDataWrapper;
typedef struct _CamelSimpleDataWrapperStream CamelSimpleDataWrapperStream;
typedef struct _CamelStore CamelStore;
typedef struct _CamelStream CamelStream;
+typedef struct _CamelStreamBuffer CamelStreamBuffer;
typedef struct _CamelStreamBufferedFs CamelStreamBufferedFs;
typedef struct _CamelStreamDataWrapper CamelStreamDataWrapper;
typedef struct _CamelStreamFs CamelStreamFs;
diff --git a/camel/camel.h b/camel/camel.h
index 382326f2e3..5145b58348 100644
--- a/camel/camel.h
+++ b/camel/camel.h
@@ -53,6 +53,7 @@ extern "C" {
#include <camel/camel-session.h>
#include <camel/camel-store.h>
#include <camel/camel-stream.h>
+#include <camel/camel-stream-buffer.h>
#include <camel/camel-stream-fs.h>
#include <camel/camel-stream-mem.h>
#include <camel/camel-thread-proxy.h>