Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strtok.c File Reference
#include <stddef.h>
#include <string.h>
Include dependency graph for strtok.c:

Go to the source code of this file.

Functions

char * __strtok_r (char *, const char *, char **)
 
char * strtok (char *s, const char *delim)
 Finds the next token in a null-terminated byte string pointed to by s. More...
 

Function Documentation

◆ __strtok_r()

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

Definition at line 43 of file strtok.c.

44 {
45  char *spanp, *tok;
46  int c, sc;
47 
48  if(s == NULL && (s = *last) == NULL)
49  {
50  {
51  return (NULL);
52  }
53  }
54 
55 /*
56  * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
57  */
58 cont:
59  c = *s++;
60  for(spanp = (char*)(uintptr_t)delim; (sc = *spanp++) != 0;)
61  {
62  if(c == sc)
63  {
64  {
65  goto cont;
66  }
67  }
68  }
69 
70  if(c == 0)
71  { /* no non-delimiter characters */
72  *last = NULL;
73  return (NULL);
74  }
75  tok = s - 1;
76 
77  /*
78  * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
79  * Note that delim must have one NUL; we stop if we see that, too.
80  */
81  for(;;)
82  {
83  c = *s++;
84  spanp = (char*)(uintptr_t)delim;
85  do
86  {
87  if((sc = *spanp++) == c)
88  {
89  if(c == 0)
90  {
91  {
92  s = NULL;
93  }
94  }
95  else
96  {
97  {
98  s[-1] = '\0';
99  }
100  }
101  *last = s;
102  return (tok);
103  }
104  } while(sc != 0);
105  }
106  /* NOTREACHED */
107 }
#define NULL
Definition: stddef.h:15

References NULL.

Referenced by strtok().

◆ strtok()

char* strtok ( char *  s,
const char *  delim 
)

Finds the next token in a null-terminated byte string pointed to by s.

Finds the next token in a null-terminated byte string pointed to by s. The separator characters are identified by null-terminated byte string pointed to by delim. This function is designed to be called multiples times to obtain successive tokens from the same string.

  • If s != NULL, the call is treated as the first call to strtok for this particular string. The function searches for the first character which is not contained in delim.

The behavior is undefined if either s or delim is not a pointer to a null-terminated byte string.

Parameters
spointer to the null-terminated byte string to tokenize
delimpointer to the null-terminated byte string identifying delimiters
Returns
Returns pointer to the beginning of the next token or NULL if there are no more tokens.

Definition at line 109 of file strtok.c.

110 {
111  static char* last;
112 
113  return (__strtok_r(s, delim, &last));
114 }
char * __strtok_r(char *, const char *, char **)
Definition: strtok.c:43

References __strtok_r().