c - Can't find documentation for strtok_s() -
what each argument passed it, return?
how better regular strtok
?
please give me simplified , basic explanation possible.
this detailed in appendix k (bounds checking interfaces)
of iso c11
standard. optional part of standard provides "safer" (a) versions of existing functionality provided in core part of standard.
the prototype is:
char *strtok_s ( char * restrict s1, rsize_t * restrict s1max, const char * restrict s2, char ** restrict ptr);
the runtime constraints checked part of safety features are:
- the pointers
s1max
,s2
, ,ptr
must non-null. - if
s1
null pointer,*ptr
must not be. - the value of
*s1max
must less or equalrsize_max
. - the end of token found must occur within first
*s1max
characters ofs1
first call - the end of token found must occur within first
*s1max
characters of searching resumes on subsequent calls.
the safety aspect that, if of constraints violated, no indirection occurs on s1
or s2
, no value stored via ptr
.
other checks, pretty works identically standard strtok
function, returning tokens s1
separated groups of delimiters found in s2
. think use of ptr
makes thread-safe since using non-static state provided user (b).
(a) quoted because parts of standard already safe if know how use them :-)
(b) 1 thing that's still missing ability have empty tokens such as:
field1||||field5
because strtok_s
(and original) treat ||||
single separator, have find other ways </rant>
:-)
Comments
Post a Comment