From patchwork Wed Jan 12 10:57:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1/3] make path_has_protocol() to return pointer instead of bool Date: Wed, 12 Jan 2011 00:57:00 -0000 From: Michael Tokarev X-Patchwork-Id: 78539 Message-Id: <1294829822-27938-2-git-send-email-mjt@msgid.tls.msk.ru> To: qemu-devel@nongnu.org Cc: Michael Tokarev 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)