#1900 strndup currently not supported

WSL
pending
Feature
later
Feature_in_WSL_4.1
False
2013-02-21
2011-04-27
timwilson
No

Any chance we could get strndup supported?

Discussion

  • Keith Marshall

    Keith Marshall - 2011-05-04

    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 )
    {
    char *retbuf;
    if( (retbuf = malloc( 1 + maxlen )) != NULL )
    {
    memcpy( retbuf, src, maxlen );
    retbuf[maxlen] = '\0';
    }
    return retbuf;
    }
    return strdup( src );
    }

     
  • Earnie Boyd

    Earnie Boyd - 2013-02-15

    Ticket moved from /p/mingw/feature-requests/89/

     
  • Earnie Boyd

    Earnie Boyd - 2013-02-15
    • labels: GNU/BSD Compatibility Feature --> GNU/BSD Compatibility Feature, posix
    • status: open --> pending
    • assigned_to: Earnie Boyd
    • milestone: Submitted --> WSL
    • type: --> Feature
    • resolution: --> later
    • category: --> Unknown
    • patch_attached: --> False
     
  • Earnie Boyd

    Earnie Boyd - 2013-02-21
    • labels: GNU/BSD Compatibility Feature, posix --> GNU/BSD Compatibility Feature, posix, needs review, needs test
    • category: Unknown --> Feature_in_WSL_4.1
     

Log in to post a comment.