Hi Collin,

On 2026-03-10T17:57:36-0700, Collin Funk wrote:
> >> >   - n3750, alx-0007r6 - add a malloc(3)-based sprintf(3) variant
> >> >     (similar to gnulib's xasprintf() and xvasprintf() functions),
> >> 
> >> I expect we'll vote this one in March, or maybe July.  I think it might
> >> be accepted, but I'm not sure.
> >
> > I have news about this.  The committee wants the API, but there's no
> > agreement on the name.
> >
> > People have complained that aprintf() is too used in the wild, so it
> > would break a lot of existing code.
> >
> > Then, people started proposing many nonsensical names...
> >
> > I think we have some alternatives.  To be fair, I didn't fully like the
> > name aprintf(), and am now more inclined to call it saprintf().  That
> > is still used in the wild, but significantly less than aprintf().  Also,
> > the 's' in the name marks it as being from the s*printf() sub-family.
> > I think the breakage from saprintf() would be acceptable (just one hit
> > in a Debian code search).
> >
> > I'll write a proposal, and we'll probably vote it by the end of this
> > year.
> >
> > If gnulib likes this name, you're invited to provide it, which would
> > hopefully add some points to the committee to follow existing
> > implementations.
> 
> I'm confused, isn't this the same functionality as asprintf which
> POSIX.1-2024 added?

Yes.

> If so, why add it under a new name?

asprintf(3) is a bad design.  Here's the relevant text of the proposal:

        [...].  GNU and the
        BSDs have it as asprintf(3), but there seems to be consensus
        that this API isn't very well designed; evidence of this is that
        the behavior is slightly different in the various
        implementations, and has changed through history.

        Another design is closer to strdup(3).  Plan9 has smprint(2),
        which behaves basically like strdup(3), except for formatting
        the string.  This API matches the internal APIs implemented in
        projects like the Linux kernel (kvasprintf()) and shadow-utils
        (aprintf()).  This one has the advantage that the attributes
        such as [[gnu::malloc(free)]] can be applied to it.

        It is common to use such APIs together with code that calls
        strdup(3).  Here's an example from shadow utils:

                src/userdel.c-1062-     if (prefix[0]) {
                src/userdel.c:1063:             user_home = xaprintf("%s/%s", 
prefix, pwd->pw_dir);
                src/userdel.c-1064-     } else {
                src/userdel.c-1065-             user_home = 
xstrdup(pwd->pw_dir);
                src/userdel.c-1066-     }

        This kind of code tends to favour the Plan9 API variant in
        comparison with the GNU variant which doesn't fit well in
        surrounding code.


Have a lovely night!
Alex

> Collin

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to