From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6723C429E27 for ; Tue, 13 Sep 2011 14:32:25 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6ZNjiRMBJQ-i for ; Tue, 13 Sep 2011 14:32:24 -0700 (PDT) Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8BAAB431FB6 for ; Tue, 13 Sep 2011 14:32:24 -0700 (PDT) Received: from localhost6.localdomain6 (entry3.nixu.fi [193.209.237.21]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p8DLW8G2022252; Wed, 14 Sep 2011 00:32:14 +0300 From: tomi.ollila@iki.fi To: notmuch@notmuchmail.org Subject: [PATCH 1/3] added function notmuch_talloc_g_key_file_get_string_list() Date: Wed, 14 Sep 2011 00:32:02 +0300 Message-Id: <1315949524-4948-2-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi> References: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi> Cc: Tomi Ollila X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Sep 2011 21:32:25 -0000 From: Tomi Ollila The function notmuch_talloc_g_key_file_get_string_list() wraps call to g_key_file_get_string_list() in a way that the returned string array is copied to talloc'd memory area. The returned pointer is itself also a talloc context, child of the context given as first argument. --- notmuch-config.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 41 insertions(+), 3 deletions(-) diff --git a/notmuch-config.c b/notmuch-config.c index 485fa72..706f481 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -170,6 +170,44 @@ get_username_from_passwd_file (void *ctx) return name; } +/** XXX move to (not-yet-existent) notmuch-talloc.c, or somewhere */ +static char ** +notmuch_talloc_g_key_file_get_string_list (const void * ctx, + GKeyFile *key_file, + const gchar *group_name, + const gchar *key, + gsize *length, + GError **error) +{ + char ** newlist; + gchar ** strlist = g_key_file_get_string_list (key_file, group_name, key, + length, error); + if (strlist) { + int i; + int l = *length; + + newlist = talloc_array (ctx, char *, l + 1); + if (newlist == NULL) + goto fail1; + for (i = 0; i < l; i++) { + if ( (newlist[i] = talloc_strdup (newlist, strlist[i])) == NULL) + goto fail2; + } + newlist[i] = NULL; + g_strfreev (strlist); + + return newlist; + } + return NULL; + +fail2: + talloc_free (newlist); +fail1: + g_strfreev (strlist); + *length = 0; /* like in g_key_file_get_string_list () */ + return NULL; +} + /* Open the named notmuch configuration file. If the filename is NULL, * the value of the environment variable $NOTMUCH_CONFIG will be used. * If $NOTMUCH_CONFIG is unset, the default configuration file @@ -229,7 +267,7 @@ notmuch_config_open (void *ctx, fprintf (stderr, "Out of memory.\n"); return NULL; } - + talloc_set_destructor (config, notmuch_config_destructor); if (filename) { @@ -393,7 +431,7 @@ notmuch_config_open (void *ctx, } /* Close the given notmuch_config_t object, freeing all resources. - * + * * Note: Any changes made to the configuration are *not* saved by this * function. To save changes, call notmuch_config_save before * notmuch_config_close. @@ -653,7 +691,7 @@ notmuch_config_command_get (void *ctx, char *item) } else if (strcmp(item, "user.other_email") == 0) { const char **other_email; size_t i, length; - + other_email = notmuch_config_get_user_other_email (config, &length); for (i = 0; i < length; i++) printf ("%s\n", other_email[i]); -- 1.7.3.4