Any chance we could get strndup supported?
I guess we could, but I'm not so sure that we should; strndup() is a POSIX function; it isn't provided by MSVCRT, and AFAICT it isn't required by ISO-C99. Given our mission of supporting native MSVCRT, with added C99 support, the extra burden of POSIX functions isn't a priority for us. That said, there are already a few precedents in libmingwex.a; (indeed, we have already attracted criticism from some quarters, for going too far in this respect).
Personally, I don't have any strong objection to carrying some added POSIX capability in libmingwex.a, provided the implementation is simple, clean and well tested. Until someone, (you?), contributes such an implementation for strndup(), and the MinGW developer community has had an opportunity to review it, with majority support for inclusion, you might like to consider adding a strndup() replacement to your project; (if you use autoconf, you can do so via AC_REPLACE_FUNCS). Something like (untested):
char *repl_strndup( char *src, size_t maxlen )
if( strlen( src ) > maxlen )
if( (retbuf = malloc( 1 + maxlen )) != NULL )
memcpy( retbuf, src, maxlen );
retbuf[maxlen] = '\0';
return strdup( src );
Ticket moved from /p/mingw/feature-requests/89/
Log in to post a comment.