avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Multithreaded strtok


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] Multithreaded strtok
Date: Fri, 13 Sep 2002 12:03:27 +0200
User-agent: Mutt/1.2.5i

As Harald Kipp wrote:

> I received an email from Peter Scandrett with an
> attached C source of a multithreaded mt_strtok.
> It contains a BSD-style licence.

Hmm, i don't like the name.  There's already the (Posix) convention to
create a re-entrant function "foo_r" for any non-reentranct function
"foo".  I suggest we follow this convention wherever it makes sense
(and basically we already followed it by importing rand_r()).

Apart from that, i don't see why it can't be added.

Here's the BSD prototype:

    NAME
         strtok, strtok_r - string tokens

    LIBRARY
         Standard C Library (libc, -lc)

    SYNOPSIS
         #include <string.h>

         char *
         strtok(char *str, const char *sep);

         char *
         strtok_r(char *str, const char *sep, char **last);

However, the next comment is:

    DESCRIPTION
         This interface is obsoleted by strsep(3).

So for reference, here's strsep(3).  Maybe we should port this one
instead?

    SYNOPSIS
         #include <string.h>

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

    DESCRIPTION
         The strsep() function locates, in the string referenced by
         *stringp, the first occurrence of any character in the string
         delim (or the terminating `\0' character) and replaces it
         with a `\0'.  The location of the next character after the
         delimiter character (or NULL, if the end of the string was
         reached) is stored in *stringp.  The original value of
         *stringp is returned.

         An ``empty'' field, i.e. one caused by two adjacent delimiter
         characters, can be detected by comparing the location
         referenced by the pointer returned in *stringp to `\0'.

         If *stringp is initially NULL, strsep() returns NULL.
...

    HISTORY
         The strsep() function is intended as a replacement for the
         strtok() function.  While the strtok() function should be
         preferred for portability reasons (it conforms to ISO/IEC
         9899:1990 (``ISO C89'')) it is unable to handle empty fields,
         i.e. detect fields delimited by two adjacent delimiter
         characters, or to be used for more than a single string at a
         time.  The strsep() function first appeared in 4.4BSD.

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]