From patchwork Wed Jan 12 10:57:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 78539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0D1DFB70A3 for ; Wed, 12 Jan 2011 22:14:20 +1100 (EST) Received: from localhost ([127.0.0.1]:55827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pcyee-0002tw-Um for incoming@patchwork.ozlabs.org; Wed, 12 Jan 2011 06:14:17 -0500 Received: from [140.186.70.92] (port=51821 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PcyWD-0005yU-T1 for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:05:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PcyWB-0006mo-Tl for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:05:33 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:37035) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PcyWB-0006m8-M6 for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:05:31 -0500 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 0A69AA0A98 for ; Wed, 12 Jan 2011 13:57:19 +0300 (MSK) (envelope-from mjt@tls.msk.ru) Received: from gandalf.tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with ESMTP id E90BC1D; Wed, 12 Jan 2011 13:57:18 +0300 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 26AF912B60; Wed, 12 Jan 2011 13:57:18 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Date: Wed, 12 Jan 2011 13:57:00 +0300 Message-Id: <1294829822-27938-2-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1294829822-27938-1-git-send-email-mjt@tls.msk.ru> References: <1294829822-27938-1-git-send-email-mjt@tls.msk.ru> To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Michael Tokarev Subject: [Qemu-devel] [PATCH 1/3] make path_has_protocol() to return pointer instead of bool X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently protocol: parsing in filenames is ad-hoc and scattered all around block.c. This is a first step to prepare for common parsing. Signed-off-by: Michael Tokarev --- block.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index ff2795b..e5a6f60 100644 --- a/block.c +++ b/block.c @@ -90,9 +90,11 @@ int is_windows_drive(const char *filename) } #endif -/* check if the path starts with ":" */ -static int path_has_protocol(const char *path) +/* check if the path starts with ":" + * Return pointer to the leading colon or NULL */ +static char *path_has_protocol(const char *path) { + const char *p; #ifdef _WIN32 if (is_windows_drive(path) || is_windows_drive_prefix(path)) { @@ -100,7 +102,17 @@ static int path_has_protocol(const char *path) } #endif - return strchr(path, ':') != NULL; + p = path; + /* we allow [a-z_] for now */ + while((*p >= 'a' && *p <= 'z') || *p == '_') { + ++p; + } + +#define MAX_PROTO_LEN 31 + /* recognize non-empty string of max MAX_PROTO chars as protocol */ + return + *p == ':' && p > path && (p - path) <= MAX_PROTO_LEN ? + (char*)p : NULL; } int path_is_absolute(const char *path)