Back to index

glibc  2.9
Defines | Functions
getsubopt.c File Reference
#include <stdlib.h>
#include <string.h>
#include "strchrnul.h"

Go to the source code of this file.

Defines

#define __strchrnul   strchrnul

Functions

int getsubopt (char **optionp, char *const *tokens, char **valuep)

Define Documentation

#define __strchrnul   strchrnul

Definition at line 30 of file getsubopt.c.


Function Documentation

int getsubopt ( char **  optionp,
char *const tokens,
char **  valuep 
)

Definition at line 40 of file getsubopt.c.

{
  char *endp, *vstart;
  int cnt;

  if (**optionp == '\0')
    return -1;

  /* Find end of next token.  */
  endp = __strchrnul (*optionp, ',');

  /* Find start of value.  */
  vstart = memchr (*optionp, '=', endp - *optionp);
  if (vstart == NULL)
    vstart = endp;

  /* Try to match the characters between *OPTIONP and VSTART against
     one of the TOKENS.  */
  for (cnt = 0; tokens[cnt] != NULL; ++cnt)
    if (strncmp (*optionp, tokens[cnt], vstart - *optionp) == 0
       && tokens[cnt][vstart - *optionp] == '\0')
      {
       /* We found the current option in TOKENS.  */
       *valuep = vstart != endp ? vstart + 1 : NULL;

       if (*endp != '\0')
         *endp++ = '\0';
       *optionp = endp;

       return cnt;
      }

  /* The current suboption does not match any option.  */
  *valuep = *optionp;

  if (*endp != '\0')
    *endp++ = '\0';
  *optionp = endp;

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function: