mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Initial s390-tools-2.0.0 import
This commit is based on the s390-tools-1.39.0 version. Changes on top of s390-tools-1.39.0: - Add MIT license to all source files - Add LICENSE file - Transform REAMDE to README.md (markdown) - Add AUTHORS.md file - Add CONTRIBUTING.md file - Move changelog from README to CHANGELOG.md file Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Misc - Local helper functions
|
||||
*
|
||||
* Copyright IBM Corp. 2016, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <regex.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "lib/util_panic.h"
|
||||
#include "misc.h"
|
||||
|
||||
/**
|
||||
* Test string against regular expression
|
||||
*
|
||||
* @param[in] str String to investigate
|
||||
* @param[in] regex Regular expression
|
||||
*
|
||||
* @returns true String matches with regular expression
|
||||
* false No match
|
||||
*/
|
||||
bool misc_regex_match(const char *str, const char *regex)
|
||||
{
|
||||
regmatch_t pmatch[1];
|
||||
regex_t preg;
|
||||
int rc;
|
||||
|
||||
rc = regcomp(&preg, regex, REG_EXTENDED);
|
||||
util_assert(rc == 0, "The regcomp() function failed: rc = %d\n", rc);
|
||||
|
||||
rc = regexec(&preg, str, (size_t) 1, pmatch, 0);
|
||||
regfree(&preg);
|
||||
return rc == 0 ? true : false;
|
||||
}
|
||||
Reference in New Issue
Block a user