Date: Sat, 12 May 2001 05:24:25 -0700 From: Terry Lambert <tlambert2@mindspring.com> To: hackers@freebsd.org Subject: Re: adding a new function to libc Message-ID: <3AFD2B79.AB7627B8@mindspring.com>
next in thread | raw e-mail | index | archive | help
To follow myself up: > > > > Any comments, suggestions, swears concerning adding a new function, > > strndup(), to libc? > > > > So that instead of permitting it to attempt to allocate a large > > chunk of memory, it is possible to give it a max length. > > How about just knowing what you are passing to the function > before you call it, so that it isn't a problem? There might actually be tiny value in such a function, but not the way you've written it. The value would be in avoiding the strlen() call prior to the malloc(), which would permit a single traversal of the string, relative to the standard strdup() function, which always ens up doing two traversals (one to get the length, and a second to do the copy). See the strncpy() sources. The downside risk would be that you could end up allocating too much memory, e.g.: char string[BIGFREAKINGARRAY]; char *s; ... s = strndup( string, BIGFREAKINGARRAY); So it seems to me that the people who would want to use it would probably end up shooting themselves anyway. Something that seems more useful would be an asnprintf(), and you could (ab)use it to get the same functionality, but in this case "more useful" still doesn't mean "generally useful". -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3AFD2B79.AB7627B8>