From 2330d1a1edd2b4901c3f84a2f589cd5baa34bae5 Mon Sep 17 00:00:00 2001 From: Luiz Augusto Von Dentz Date: Mon, 14 Dec 2009 17:02:25 +0200 Subject: [PATCH] obexd: Fix .read of capability driver Capability driver .read was not returning 0 once the capability was already read which cause obex_write_stream to interpret as there is still more data to be read. This should also enable reading capability in chunks if the buffer is not big enough to accomodate the whole string. --- obexd/plugins/filesystem.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c index 080b7717f..46fbd8e59 100644 --- a/obexd/plugins/filesystem.c +++ b/obexd/plugins/filesystem.c @@ -180,6 +180,7 @@ static gpointer capability_open(const char *name, int oflag, mode_t mode, gchar *buf; gint exit; gboolean ret; + GString *object; if (oflag != O_RDONLY) goto fail; @@ -207,10 +208,12 @@ static gpointer capability_open(const char *name, int oflag, mode_t mode, } done: + object = g_string_new(buf); + if (size) - *size = strlen(buf); + *size = object->len; - return buf; + return object; fail: if (gerr) @@ -222,14 +225,25 @@ fail: static int capability_close(gpointer object) { - g_free(object); + GString *capability = object; + + g_string_free(capability, TRUE); return 0; } static ssize_t capability_read(gpointer object, void *buf, size_t count) { - strncpy(buf, object, count); - return strlen(buf); + GString *capability = object; + ssize_t len; + + if (capability->len == 0) + return 0; + + strncpy(buf, capability->str, count); + len = strlen(buf); + capability = g_string_erase(capability, 0, len); + + return len; } static gpointer folder_open(const char *name, int oflag, mode_t mode, -- 2.47.3