[patch] basename vs. __gnu_basename fix
Wed Apr 22 11:01:00 GMT 2015
On Apr 21 17:07, Craig Howland wrote:
> On 04/21/2015 11:50 AM, Corinna Vinschen wrote:
> >+/* There are two common basename variants. If you #include <libgen.h> you get
> >+ the POSIX version; otherwise, if you define _GNU_SOURCE, you get the GNU
> >+ version via <string.h>. POSIX requires that #undef basename will still let
> >+ you invoke the underlying function. However, this also implies that the
> >+ POSIX version is used in this case. That's made sure here. */
> >+#if __GNU_VISIBLE && !defined(basename)
> > char *_EXFUN(__gnu_basename,(const char *));
> > # define basename __gnu_basename
> >-# endif
> > #endif
> The prototype should not be skipped if basename is defined (which I'm
> guessing is an unintended change).
Hang on, the prototype *must* be skipped if basename is defined. If you
don't do that you end up with the exact problem my patch is trying to
fix: You'll get two contradicting prototypes for basename, one from
libgen.h, one from string.h. If basename is defined, it's from
libgen.h, so basename is already prototyped. Have a look into the glibc
> In addition, to help make use more clear
> (particularly for users--maintainers too, but not so much) the comment and
> #if condition should perhaps be changed a little. I suggest it should end
> up being more like the following. (Comment same in both files, as you have
> it, but only shown once in the context of string.h.)
> I also added the nonnull attribute to the prototype, to avoid a possible
> change in compiler warnings due to the GNUC part being dropped.
> /* There are two common basename variants. If you do NOT #include <libgen.h>
> * and you do
> * #define _GNU_SOURCE
> * #include <string.h>
> * you get the GNU version. Otherwise, you get the POSIX version, for which
> * you should #include <libgen.h> for the function prototype. POSIX requires
> * that #undef basename will still let you invoke the underlying function.
> * However, this also implies that the POSIX version is used in this case.
> * That's made sure here. */
> #if defined(_GNU_SOURCE)
> char *_EXFUN(__nonnull(1) __gnu_basename,(const char *));
> # if !defined(basename)
> # define basename __gnu_basename
> # endif
Thanks, I changed that.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 819 bytes
Desc: not available
More information about the Newlib