Back to index

nagios-plugins  1.4.16
Functions
strsep.c File Reference
#include <string.h>

Go to the source code of this file.

Functions

char * strsep (char **stringp, const char *delim)

Function Documentation

char* strsep ( char **  stringp,
const char *  delim 
)

Definition at line 27 of file strsep.c.

{
  char *start = *stringp;
  char *ptr;

  if (start == NULL)
    return NULL;

  /* Optimize the case of no delimiters.  */
  if (delim[0] == '\0')
    {
      *stringp = NULL;
      return start;
    }

  /* Optimize the case of one delimiter.  */
  if (delim[1] == '\0')
    ptr = strchr (start, delim[0]);
  else
    /* The general case.  */
    ptr = strpbrk (start, delim);
  if (ptr == NULL)
    {
      *stringp = NULL;
      return start;
    }

  *ptr = '\0';
  *stringp = ptr + 1;

  return start;
}

Here is the caller graph for this function: