Back to index

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

Go to the source code of this file.

Defines

#define __strtok_r   strtok_r
#define __rawmemchr   strchr

Functions

char * __strtok_r (char *s, const char *delim, char **save_ptr)

Define Documentation

#define __rawmemchr   strchr

Definition at line 33 of file strtok_r.c.

#define __strtok_r   strtok_r

Definition at line 32 of file strtok_r.c.


Function Documentation

char* __strtok_r ( char *  s,
const char *  delim,
char **  save_ptr 
)

Definition at line 47 of file strtok_r.c.

{
  char *token;

  if (s == NULL)
    s = *save_ptr;

  /* Scan leading delimiters.  */
  s += strspn (s, delim);
  if (*s == '\0')
    {
      *save_ptr = s;
      return NULL;
    }

  /* Find the end of the token.  */
  token = s;
  s = strpbrk (token, delim);
  if (s == NULL)
    /* This token finishes the string.  */
    *save_ptr = __rawmemchr (token, '\0');
  else
    {
      /* Terminate the token and make *SAVE_PTR point past it.  */
      *s = '\0';
      *save_ptr = s + 1;
    }
  return token;
}