strtok_r为MinGW的 [英] strtok_r for MinGW
本文介绍了strtok_r为MinGW的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
strtok_r 是的strtok的折返变体。这是POSIX的一致性。然而,从MinGW的失踪,我试图编译它正在使用的程序。
strtok_r is the reentrant variant of strtok. It is POSIX-conformant. However, it is missing from MinGW, and I'm trying to compile a program that is using it.
有什么办法,我可以添加一个标准实现这个功能,也许到项目本身的code,或MinGW的标准库函数?
Is there any way I could add a standard implementation of this function, perhaps to the project's own code, or to MinGW's standard library functions?
推荐答案
由于大约有来自另一个答案code牌照的一些问题,这里有一个明确的公共领域:
Since there are some license questions about the code from another answer, here's one that's explicitly public domain:
/*
* public domain strtok_r() by Charlie Gordon
*
* from comp.lang.c 9/14/2007
*
* http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684
*
* (Declaration that it's public domain):
* http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
*/
char* strtok_r(
char *str,
const char *delim,
char **nextp)
{
char *ret;
if (str == NULL)
{
str = *nextp;
}
str += strspn(str, delim);
if (*str == '\0')
{
return NULL;
}
ret = str;
str += strcspn(str, delim);
if (*str)
{
*str++ = '\0';
}
*nextp = str;
return ret;
}
这篇关于strtok_r为MinGW的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文