summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2016-07-12 14:37:54 +0800
committerLv Zheng <lv.zheng@intel.com>2016-12-14 16:33:22 +0800
commitd837f450572fa1a84b36fccb3d7404442ca03ca6 (patch)
tree31b6eb756f067c60e81057e998bc0421e5ade900
parent30495a682e335ce08da696e45e4f00a1d7ecc026 (diff)
downloadacpica-d837f450572fa1a84b36fccb3d7404442ca03ca6.tar.gz
Clib: Add generic strpbrk() and strtok() to improve portability
This patch implements the native string APIs of strpbrk()/strtok(). Unit tests have been done to these two functions in unix environment and no bugs have been found. Lv Zheng. Signed-off-by: Lv Zheng <lv.zheng@intel.com>
-rw-r--r--source/components/utilities/utclib.c87
-rw-r--r--source/include/acclib.h10
2 files changed, 97 insertions, 0 deletions
diff --git a/source/components/utilities/utclib.c b/source/components/utilities/utclib.c
index d2f73642f..31241a992 100644
--- a/source/components/utilities/utclib.c
+++ b/source/components/utilities/utclib.c
@@ -358,6 +358,93 @@ strlen (
/*******************************************************************************
*
+ * FUNCTION: strpbrk
+ *
+ * PARAMETERS: String - Null terminated string
+ * Delimiters - Delimiters to match
+ *
+ * RETURN: The first occurance in the string of any of the bytes in the
+ * delimiters
+ *
+ * DESCRIPTION: Search a string for any of a set of the delimiters
+ *
+ ******************************************************************************/
+
+char *
+strpbrk (
+ const char *String,
+ const char *Delimiters)
+{
+ const char *Delimiter;
+
+
+ for ( ; *String != '\0'; ++String)
+ {
+ for (Delimiter = Delimiters; *Delimiter != '\0'; Delimiter++)
+ {
+ if (*String == *Delimiter)
+ {
+ return (ACPI_CAST_PTR (char, String));
+ }
+ }
+ }
+
+ return (NULL);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: strtok
+ *
+ * PARAMETERS: String - Null terminated string
+ * Delimiters - Delimiters to match
+ *
+ * RETURN: Pointer to the next token
+ *
+ * DESCRIPTION: Split string into tokens
+ *
+ ******************************************************************************/
+
+char*
+strtok (
+ char *String,
+ const char *Delimiters)
+{
+ char *Begin = String;
+ static char *SavedPtr;
+
+
+ if (Begin == NULL)
+ {
+ if (SavedPtr == NULL)
+ {
+ return (NULL);
+ }
+ Begin = SavedPtr;
+ }
+
+ SavedPtr = strpbrk (Begin, Delimiters);
+ while (SavedPtr == Begin)
+ {
+ *Begin++ = '\0';
+ SavedPtr = strpbrk (Begin, Delimiters);
+ }
+
+ if (SavedPtr)
+ {
+ *SavedPtr++ = '\0';
+ return (Begin);
+ }
+ else
+ {
+ return (NULL);
+ }
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: strcpy
*
* PARAMETERS: DstString - Target of the copy
diff --git a/source/include/acclib.h b/source/include/acclib.h
index 10667216a..bd7b564e0 100644
--- a/source/include/acclib.h
+++ b/source/include/acclib.h
@@ -176,6 +176,16 @@ strchr (
int ch);
char *
+strpbrk (
+ const char *String,
+ const char *Delimiters);
+
+char *
+strtok (
+ char *String,
+ const char *Delimiters);
+
+char *
strcpy (
char *DstString,
const char *SrcString);