aboutsummaryrefslogtreecommitdiff
path: root/libsylph/recv.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-07 08:37:31 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-07 08:37:31 +0000
commitd19d2c5d8874b947abc80b7aa29c7b19909006f7 (patch)
tree7f9b3f1b7095b12da753df3fb0fd28b6fef7476c /libsylph/recv.c
parent5f667d42f46f4735b0e23c00467055fc7d93df8e (diff)
support literals in IMAP response.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@627 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/recv.c')
-rw-r--r--libsylph/recv.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/libsylph/recv.c b/libsylph/recv.c
index d01d49b8..0b71545c 100644
--- a/libsylph/recv.c
+++ b/libsylph/recv.c
@@ -36,6 +36,31 @@
static RecvUIFunc recv_ui_func;
static gpointer recv_ui_func_data;
+
+gchar *recv_bytes(SockInfo *sock, glong size)
+{
+ gchar *buf;
+ glong count = 0;
+
+ if (size == 0)
+ return NULL;
+
+ buf = g_malloc(size);
+
+ do {
+ gint read_count;
+
+ read_count = sock_read(sock, buf + count, size - count);
+ if (read_count < 0) {
+ g_free(buf);
+ return NULL;
+ }
+ count += read_count;
+ } while (count < size);
+
+ return buf;
+}
+
gint recv_write_to_file(SockInfo *sock, const gchar *filename)
{
FILE *fp;
@@ -164,24 +189,14 @@ gint recv_write(SockInfo *sock, FILE *fp)
gint recv_bytes_write(SockInfo *sock, glong size, FILE *fp)
{
gchar *buf;
- glong count = 0;
gchar *prev, *cur;
if (size == 0)
return 0;
- buf = g_malloc(size);
-
- do {
- gint read_count;
-
- read_count = sock_read(sock, buf + count, size - count);
- if (read_count < 0) {
- g_free(buf);
- return -2;
- }
- count += read_count;
- } while (count < size);
+ buf = recv_bytes(sock, size);
+ if (!buf)
+ return -2;
/* +------------------+----------------+--------------------------+ *
* ^buf ^prev ^cur buf+size-1^ */