[lttng-dev] [Babeltrace RFC PATCH 16/28] Add MinGW implementation of strtok_r

Jérémie Galarneau jeremie.galarneau at efficios.com
Mon May 13 16:20:41 EDT 2013


On Thu, May 2, 2013 at 7:57 AM, Ikaheimonen, JP
<jp_ikaheimonen at mentor.com> wrote:
> ---
>  compat/compat_strlib.c             | 40 ++++++++++++++++++++++++++++++++++++++
>  converter/babeltrace.c             |  2 +-
>  include/babeltrace/compat/string.h |  4 ++++
>  3 files changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/compat/compat_strlib.c b/compat/compat_strlib.c
> index 7413e74..3cbd455 100644
> --- a/compat/compat_strlib.c
> +++ b/compat/compat_strlib.c
> @@ -1,6 +1,46 @@
>  #include <babeltrace/compat/string.h>
>
>  #ifdef __MINGW32__
> +
> +char* strtok_r(

Any reason you can't use strtok_s?

> +       char *str,
> +       const char *delim,
> +       char **nextp)
> +{
> +       char *ret;
> +
> +       /* if str is NULL, continue from nextp */
> +       if (str == NULL) {
> +               str = *nextp;
> +       }
> +       /* skip the leading delimiter characters */
> +       str += strspn(str, delim);
> +
> +       /* return NULL if all are delimiters */
> +       if (*str == '\0') {
> +               return NULL;
> +       }
> +       /* return the pointer to the first character that is not delimiter */
> +       ret = str;
> +
> +       /* scan to the next delimiter */
> +       str += strcspn(str, delim);
> +
> +       /* if we found a delimiter instead of a NUL */
> +       if (*str) {
> +               /* replace the delimiter with the NUL */
> +               *str = '\0';
> +               /* next time, scan from the character after NUL */
> +               *nextp = str + 1;
> +       }
> +       else {
> +               /* end of string: next time, scan at the end (NUL) again */
> +               *nextp = str;
> +       }
> +
> +       return ret;
> +}
> +
>  int strerror_r(int errnum, char *buf, size_t buflen)
>  {
>         /* non-recursive implementation of strerror_r */
> diff --git a/converter/babeltrace.c b/converter/babeltrace.c
> index 7b3db49..f4a9217 100644
> --- a/converter/babeltrace.c
> +++ b/converter/babeltrace.c
> @@ -49,7 +49,7 @@
>  #include <unistd.h>
>  #include <inttypes.h>
>  #include <babeltrace/compat/ftw.h>
> -#include <string.h>
> +#include <babeltrace/compat/string.h>
>
>  #include <babeltrace/ctf-ir/metadata.h>        /* for clocks */
>
> diff --git a/include/babeltrace/compat/string.h b/include/babeltrace/compat/string.h
> index 8591b7e..501d003 100644
> --- a/include/babeltrace/compat/string.h
> +++ b/include/babeltrace/compat/string.h
> @@ -3,6 +3,10 @@
>
>  #include <string.h>
>
> +#ifdef __MINGW32__
> +char *strtok_r(char *str, const char *delim, char **nextp);
> +#endif
> +
>  int compat_strerror_r(int errnum, char *buf, size_t buflen);
>
>  #endif
> --
> 1.8.1.msysgit.1
>
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list