From patchwork Sun Mar 10 12:17:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 2244381 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id C94803FCF6 for ; Sun, 10 Mar 2013 12:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752184Ab3CJMQb (ORCPT ); Sun, 10 Mar 2013 08:16:31 -0400 Received: from nm11.bullet.mail.ird.yahoo.com ([77.238.189.64]:42628 "HELO nm11.bullet.mail.ird.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751191Ab3CJMQ3 (ORCPT ); Sun, 10 Mar 2013 08:16:29 -0400 Received: from [77.238.189.48] by nm11.bullet.mail.ird.yahoo.com with NNFMP; 10 Mar 2013 12:16:27 -0000 Received: from [217.146.188.160] by tm1.bullet.mail.ird.yahoo.com with NNFMP; 10 Mar 2013 12:16:27 -0000 Received: from [127.0.0.1] by smtp128.mail.ird.yahoo.com with NNFMP; 10 Mar 2013 12:16:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1362917787; bh=IiQUdf3wFCjnMjf/SbS66hy0KLTrRW78dA1Ed2GzIwA=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=C6HV01AZNUVeUZHEc5oI8GHzd7O9Ha1gpgNcZNbszUwHchFQjJEDTP4DvP5kN+2/8nS9GEsub2Qv2tf08Yel2iw1ziEzvCgW2GsFY6uXIddAWEL1wW5cnY3f+dSp35MghMblZ+FQuIe/V27/9kIQBxwVAhTL4n2QB7wRtWEvyMY= X-Yahoo-Newman-Id: 864061.19778.bm@smtp128.mail.ird.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: vzqf6woVM1mwTH5R.cMM9TtLDDwxuCXdfR4PKUEHGeKBIa9 Rto3siwwnSmB9HtOqiTsaYioHou2uyBSt.FkPVD8fr00u6qW0aaiVXdoBrHY soHhZwd0Dld6Hwwpltvv6HqbdPa1wsQlnP2gKd_zfxFJEA4kDvBZ4r9qIyxZ 3n4yJxCOka34O8R1xUwVSALRFoZWvF6RoGTXtaTEVJNmlgcVQWHrYXG0CzcA QD700ks6GW6spv2AR4pI8uXRRajQjGN03g3DZPzOzbYvVFadGDnnRQpEhaaR EZ7lhWd0T8v3.jdInuVH0ujcnLaj2kP6We6MFlvITk.G5gVzV9fD8GiVIBQO JzbuT7ZZIQ_h71YM.tKxHDhWU8n12zwaB.2x4ZdeiK.bkgTRXbUlDW7XG4uS 37IZ_Qf0yQ8DXSbq0qgLHuLn3toboIkJ7eX5AYuq7DGMyGb86WFicrmVGGc. n0SsWoXfMq.ln0oSykfX.p4s- X-Yahoo-SMTP: ssXiUn.swBDBJsD4bjmtGfj6buOv3E4378JD.MOD2Xo- Received: from venice..bhome (goffredo.baroncelli@95.242.133.103 with login) by smtp128.mail.ird.yahoo.com with SMTP; 10 Mar 2013 05:16:27 -0700 PDT From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Hugo Mills , Michael =?utf-8?q?Kj=C3=B6rling?= , Martin Steigerwald , cwillu , Chris Murphy , David Sterba , Zach Brown , Goffredo Baroncelli Subject: [PATCH 1/8] Add some helpers to manage the strings allocation/deallocation. Date: Sun, 10 Mar 2013 13:17:32 +0100 Message-Id: <1362917859-18824-2-git-send-email-goffredo.baroncelli@yahoo.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362917859-18824-1-git-send-email-goffredo.baroncelli@yahoo.com> References: <1362917859-18824-1-git-send-email-goffredo.baroncelli@yahoo.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli This patch adds some helpers to manage the strings allocation and deallocation. The function string_list_add(char *) adds the passed string to a list; the function string_list_free() frees all the strings together. Signed-off-by: Goffredo Baroncelli --- Makefile | 3 ++- string_list.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ string_list.h | 23 ++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 string_list.c create mode 100644 string_list.h diff --git a/Makefile b/Makefile index 596bf93..0d6c43a 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o file-item.o inode-item.o \ inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ - send-stream.o send-utils.o qgroup.o raid6.o + send-stream.o send-utils.o qgroup.o raid6.o \ + string_list.o cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o diff --git a/string_list.c b/string_list.c new file mode 100644 index 0000000..f840048 --- /dev/null +++ b/string_list.c @@ -0,0 +1,65 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include +#include + +#include "string_list.h" + +/* To store the strings */ +static void **strings_to_free; +static int count_string_to_free; + +/* + * Add a string to the dynamic allocated string list + */ +char *string_list_add(char *s) +{ + int size; + + size = sizeof(void *) * ++count_string_to_free; + strings_to_free = realloc(strings_to_free, size); + + /* if we don't have enough memory, we have more serius + problem than that a wrong handling of not enough memory */ + if (!strings_to_free) { + fprintf(stderr, "add_string_to_free(): Not enough memory\n"); + count_string_to_free = 0; + return NULL; + } + + strings_to_free[count_string_to_free-1] = s; + return s; +} + +/* + * Free the dynamic allocated strings list + */ +void string_list_free() +{ + int i; + for (i = 0 ; i < count_string_to_free ; i++) + free(strings_to_free[i]); + + free(strings_to_free); + + strings_to_free = 0; + count_string_to_free = 0; +} + + diff --git a/string_list.h b/string_list.h new file mode 100644 index 0000000..fdc027d --- /dev/null +++ b/string_list.h @@ -0,0 +1,23 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef STRING_LIST_H +#define STRING_LIST_H + +char *string_list_add(char *s); +void string_list_free(); + +#endif