ReactOS 0.4.16-dev-927-g467dec4
strtok_s.cpp File Reference
#include <string.h>
#include <corecrt_internal_securecrt.h>
Include dependency graph for strtok_s.cpp:

Go to the source code of this file.

Functions

char *__cdecl __acrt_strtok_s_novalidation (_Inout_opt_z_ char *string, _In_z_ char const *control, _Inout_ _Deref_prepost_opt_z_ char **context)
 
char *__cdecl strtok_s (char *string, char const *control, char **context)
 

Function Documentation

◆ __acrt_strtok_s_novalidation()

char *__cdecl __acrt_strtok_s_novalidation ( _Inout_opt_z_ char string,
_In_z_ char const control,
_Inout_ _Deref_prepost_opt_z_ char **  context 
)

Definition at line 16 of file strtok_s.cpp.

21{
22 // Clear control map. The control characters are stored in a bitmap, one
23 // bit per character. The null character is always a control character.
24 unsigned char map[32];
25 for (int count = 0; count < 32; count++)
26 {
27 map[count] = 0;
28 }
29
30 // Set bits in delimiter table
31 unsigned char const* unsigned_control = reinterpret_cast<unsigned char const*>(control);
32 do
33 {
34 map[*unsigned_control >> 3] |= (1 << (*unsigned_control & 7));
35 }
36 while (*unsigned_control++);
37
38 // If string is null, set the iterator to the saved pointer (i.e., continue
39 // breaking tokens out of the string from the last strtok call):
40 char* it = string != nullptr
41 ? string
42 : *context;
43
44 unsigned char*& unsigned_it = reinterpret_cast<unsigned char*&>(it);
45
46 // Find beginning of token (skip over leading delimiters). Note that
47 // there is no token iff this loop sets it to point to the terminal
48 // null (*it == '\0')
49 while ((map[*unsigned_it >> 3] & (1 << (*unsigned_it & 7))) && *it)
50 {
51 ++it;
52 }
53
54 char* const token_first = it;
55
56 // Find the end of the token. If it is not the end of the string,
57 // put a null there.
58 for (; *it; ++it)
59 {
60 if (map[*unsigned_it >> 3] & (1 << (*unsigned_it & 7)))
61 {
62 *it++ = '\0';
63 break;
64 }
65 }
66
67 // Update the saved pointer:
68 *context = it;
69
70 // Determine if a token has been found.
71 return it != token_first ? token_first : nullptr;
72}
Definition: _map.h:48
GLuint GLuint GLsizei count
Definition: gl.h:1545
char string[160]
Definition: util.h:11
Definition: http.c:7252
Definition: dialog.c:52
#define const
Definition: zconf.h:233

Referenced by strtok(), and strtok_s().

◆ strtok_s()

char *__cdecl strtok_s ( char string,
char const control,
char **  context 
)

Definition at line 76 of file strtok_s.cpp.

77{
80 _VALIDATE_CONDITION_ERROR_RETURN(string != nullptr || *context != nullptr, EINVAL, nullptr);
81
83}
#define EINVAL
Definition: acclib.h:90
#define _VALIDATE_CONDITION_ERROR_RETURN(_Condition, _ErrorCode, _Ret)
#define _VALIDATE_POINTER_ERROR_RETURN(_Pointer, _ErrorCode, _Ret)
char *__cdecl __acrt_strtok_s_novalidation(_Inout_opt_z_ char *string, _In_z_ char const *control, _Inout_ _Deref_prepost_opt_z_ char **context)
Definition: strtok_s.cpp:16