Files
haiku-beta6/src/system/libroot/posix/stdlib/getsubopt.cpp
T
Oliver Tappe 338ddd836f Closing #6499:
* add missing getsubopt() POSIX-function
* added corresponding test


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38650 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-09-14 18:43:24 +00:00

40 lines
816 B
C++

/*
* 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;
}