libroot: Replace getsubopt implementation with musl's.
It looks to be a bit more optimized, and one less thing for us to have to maintain from POSIX.
This commit is contained in:
@@ -12,6 +12,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
MergeObject <$(architecture)>posix_musl_misc.o :
|
MergeObject <$(architecture)>posix_musl_misc.o :
|
||||||
a64l.c
|
a64l.c
|
||||||
ffs.c
|
ffs.c
|
||||||
|
getsubopt.c
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int getsubopt(char **opt, char *const *keys, char **val)
|
||||||
|
{
|
||||||
|
char *s = *opt;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
*val = NULL;
|
||||||
|
*opt = strchr(s, ',');
|
||||||
|
if (*opt) *(*opt)++ = 0;
|
||||||
|
else *opt = s + strlen(s);
|
||||||
|
|
||||||
|
for (i=0; keys[i]; i++) {
|
||||||
|
size_t l = strlen(keys[i]);
|
||||||
|
if (strncmp(keys[i], s, l)) continue;
|
||||||
|
if (s[l] == '=')
|
||||||
|
*val = s + l + 1;
|
||||||
|
else if (s[l]) continue;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
@@ -21,7 +21,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
div.c
|
div.c
|
||||||
env.cpp
|
env.cpp
|
||||||
exit.cpp
|
exit.cpp
|
||||||
getsubopt.cpp
|
|
||||||
heapsort.c
|
heapsort.c
|
||||||
merge.c
|
merge.c
|
||||||
mktemp.c
|
mktemp.c
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010, Oliver Tappe <[email protected]>.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
getsubopt(char** optionPtr, char* const* keys, char** valuePtr)
|
|
||||||
{
|
|
||||||
if (optionPtr == NULL || valuePtr == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
char* option = *optionPtr;
|
|
||||||
if (*option == '\0')
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
char* startOfNextOption = strchr(option, ',');
|
|
||||||
if (startOfNextOption != NULL)
|
|
||||||
*startOfNextOption++ = '\0';
|
|
||||||
else
|
|
||||||
startOfNextOption = option + strlen(option);
|
|
||||||
*optionPtr = startOfNextOption;
|
|
||||||
|
|
||||||
char* startOfValue = strchr(option, '=');
|
|
||||||
if (startOfValue != NULL)
|
|
||||||
*startOfValue++ = '\0';
|
|
||||||
*valuePtr = startOfValue;
|
|
||||||
|
|
||||||
for (int keyIndex = 0; keys[keyIndex] != NULL; ++keyIndex) {
|
|
||||||
if (strcmp(option, keys[keyIndex]) == 0)
|
|
||||||
return keyIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user