libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / system / libroot / posix / stdlib / getsubopt.cpp
blob9346bcef32fe874163ab6bc2df4d26a68478944d
1 /*
2 * Copyright 2010, Oliver Tappe <zooey@hirschkaefer.de>.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <stdlib.h>
8 #include <string.h>
11 int
12 getsubopt(char** optionPtr, char* const* keys, char** valuePtr)
14 if (optionPtr == NULL || valuePtr == NULL)
15 return -1;
17 char* option = *optionPtr;
18 if (*option == '\0')
19 return -1;
21 char* startOfNextOption = strchr(option, ',');
22 if (startOfNextOption != NULL)
23 *startOfNextOption++ = '\0';
24 else
25 startOfNextOption = option + strlen(option);
26 *optionPtr = startOfNextOption;
28 char* startOfValue = strchr(option, '=');
29 if (startOfValue != NULL)
30 *startOfValue++ = '\0';
31 *valuePtr = startOfValue;
33 for (int keyIndex = 0; keys[keyIndex] != NULL; ++keyIndex) {
34 if (strcmp(option, keys[keyIndex]) == 0)
35 return keyIndex;
38 return -1;