From: Rich Felker <email@example.com>
To: "wangjianjian (C)" <firstname.lastname@example.org>
Subject: Re: [musl] basename with no parameter?
Date: Mon, 7 Mar 2022 08:18:47 -0500 [thread overview]
Message-ID: <20220307131847.GJ7074@brightrain.aerifal.cx> (raw)
On Mon, Mar 07, 2022 at 10:31:41AM +0800, wangjianjian (C) wrote:
> Hi all,
> I find that the basename in string.h with _GNU_SOURCE in Musl
> libc(Line 119):
> char *basename();
This is not a declaration with no parameter. It's a declaration
without any prototype.
> The man page says that have two different version of basename
> however both need one parameter, is this correct?
No, that's documenting glibc. There is only one version of basename in
musl and it's the standard one.
The reason for the non-prototype declaration is explained in commit
omit declaration of basename wrongly interpreted as prototype in C++
the non-prototype declaration of basename in string.h is an ugly
compromise to avoid breaking 2 types of broken software:
1. programs which assume basename is declared in string.h and thus
would suffer from dangerous pointer-truncation if an implicit
declaration were used.
2. programs which include string.h with _GNU_SOURCE defined but then
declare their own prototype for basename using the incorrect GNU
signature for the function (which would clash with a correct
however, since C++ does not have non-prototype declarations and
interprets them as prototypes for a function with no arguments, we
must omit it when compiling C++ code. thankfully, all known broken
apps that suffer from the above issues are written in C, not C++.
This was from 2012, so it might make sense to do something different
now, like putting the correct prototype there and getting any programs
it still clashes with fixed.
next prev parent reply other threads:[~2022-03-07 13:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-07 2:31 wangjianjian (C)
2022-03-07 13:18 ` Rich Felker [this message]
2022-03-07 16:42 ` James Y Knight
2022-03-07 18:38 ` Rich Felker
2022-03-26 3:34 ` wangjianjian (C)
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).