From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLlXj-00035N-OM for qemu-devel@nongnu.org; Mon, 25 Aug 2014 00:06:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLlXd-0006up-VX for qemu-devel@nongnu.org; Mon, 25 Aug 2014 00:06:07 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:43041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLlXd-0006sk-BW for qemu-devel@nongnu.org; Mon, 25 Aug 2014 00:06:01 -0400 From: "john.liuli" Date: Mon, 25 Aug 2014 12:00:32 +0800 Message-ID: <1408939237-8444-2-git-send-email-john.liuli@huawei.com> In-Reply-To: <1408939237-8444-1-git-send-email-john.liuli@huawei.com> References: <1408939237-8444-1-git-send-email-john.liuli@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 1/6] device_tree.c: Introduce a function to check multiple strings for dts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.crosthwaite@xilinx.com, agraf@suse.de Cc: Li Liu , qemu-devel@nongnu.org From: Li Liu dts property's value can be multiple strings. So introduce a function to check a data with a given length to see if it is all printable and has a valid terminator. It can contain either a single string, or multiple strings each of non-zero length. Signed-off-by: Li Liu --- device_tree.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/device_tree.c b/device_tree.c index ca83504..29d9acc 100644 --- a/device_tree.c +++ b/device_tree.c @@ -345,3 +345,35 @@ int qemu_fdt_setprop_sized_cells_from_array(void *fdt, return qemu_fdt_setprop(fdt, node_path, property, propcells, cellnum * sizeof(uint32_t)); } + +/* + * Check a data of a given length to see if it is all printable and + * has a valid terminator. The data can contain either a single string, + * or multiple strings each of non-zero length. + */ +static int dts_is_printable_strings(const void *data, int len) +{ + const char *str = (char *)data; + int substrs = 0; + int substr_len = 0; + int i; + + for (i = 0; i < len; i++) { + if (str[i] == '\0') { + if (substr_len) { + substr_len = 0; + substrs++; + continue; + } else { + /* substr is empty */ + return 0; + } + } else if (isprint(str[i])) { + substr_len++; + } else { + return 0; + } + } + + return substrs && !substr_len; +} -- 1.7.9.5