的strdup() [英] strdup()
问题描述
据我所知,strdup()既不在C89也不在C99中。
这是正确的吗?
< ; OT>它可能在POSIX中吗?< / OT>
Grumble< de ***** @ kma.eu.org> ;写道:据我所知,strdup()既不在C89也不在C99中。
这是正确的吗?
是的。
< OT>或许它在POSIX中?< / OT>
我相信。
-
Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
2005年3月22日星期二10:37:25 +0100,Grumble
< de ** ***@kma.eu.org>写道:
据我所知,strdup()既不在C89也不在C99。
这是正确的吗?
正确。但实施起来却微不足道:
#include< stdlib.h>
char * strdup(const char * str)
{
char * cpy = NULL;
if(str)
{
cpy = malloc(strlen(str)+1);
if(cpy)
strcpy(cpy,str);
}
返回cpy;
}
(实际上,POSIX并没有指定如果空指针是什么,会发生什么? b $ b传入,但我更喜欢琐碎的测试,以便strdup(NULL)== NULL。)
< OT>它可能在POSIX中吗?< / OT>
确实如此。 POSIX的一些有用的URL:
http: //www.opengroup.org/onlinepubs/...9/nfindex.html
http://www.opengroup.org/onlinepubs/007908799/toc.htm
http://www.everything2.com/?node=Posix
Chris C
"叽" <德***** @ kma.eu.org>在消息中写道据我所知,strdup()既不在C89也不在C99中。
这是正确的吗?
肯定
< OT>它可能在POSIX吗?< / OT>
strdup()在UNIX 95中是强制性的。
http:// www.unix.org/
-
Tor< torust AT online DOT no>
As far as I can tell, strdup() is neither in C89 nor in C99.
Is that correct?
<OT>Is it in POSIX perhaps?</OT>
Grumble <de*****@kma.eu.org> writes:As far as I can tell, strdup() is neither in C89 nor in C99.
Is that correct?
Yes.
<OT>Is it in POSIX perhaps?</OT>
I believe so.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On Tue, 22 Mar 2005 10:37:25 +0100, Grumble
<de*****@kma.eu.org> wrote:
As far as I can tell, strdup() is neither in C89 nor in C99.
Is that correct?
Correct. It''s trivial to implement, though:
#include <stdlib.h>
char *strdup(const char *str)
{
char *cpy = NULL;
if (str)
{
cpy = malloc(strlen(str)+1);
if (cpy)
strcpy(cpy, str);
}
return cpy;
}
(Actually, POSIX doesn''t specify what happens if a null pointer is
passed in, but I prefer the trivial test so that strdup(NULL) == NULL.)
<OT>Is it in POSIX perhaps?</OT>
It is. Some useful URLs for POSIX:
http://www.opengroup.org/onlinepubs/...9/nfindex.html
http://www.opengroup.org/onlinepubs/007908799/toc.htm
http://www.everything2.com/?node=Posix
Chris C
"Grumble" <de*****@kma.eu.org> wrote in messageAs far as I can tell, strdup() is neither in C89 nor in C99.
Is that correct?
sure
<OT>Is it in POSIX perhaps?</OT>
strdup() was manditory in UNIX 95.
http://www.unix.org/
--
Tor <torust AT online DOT no>
这篇关于的strdup()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!