diff mbox

Fox a MinGW warning in libiberty/setenv.c

Message ID 83txofi24i.fsf@gnu.org
State New
Headers show

Commit Message

Eli Zaretskii March 13, 2013, 6:30 p.m. UTC
I get this compiling the latest pretest of GDB 7.6 with MinGW:

     gcc -c -DHAVE_CONFIG_H -O2 -gdwarf-2 -g3 -D__USE_MINGW_ACCESS  -I. -I./../include  -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -pedantic  ./setenv.c -o setenv.o
     ./setenv.c:66:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]

   This happens because MinGW's stdlib.h has this:

     #ifdef __MSVCRT__
       extern _CRTIMP char *** __cdecl __MINGW_NOTHROW __p__environ(void);
       extern _CRTIMP wchar_t *** __cdecl __MINGW_NOTHROW  __p__wenviron(void);
     # define _environ (*__p__environ())
     # define _wenviron (*__p__wenviron())
     #else /* ! __MSVCRT__ */
     #endif /* ! __MSVCRT__ */

     #define environ _environ

   and setenv.c does this:

     #ifndef HAVE_ENVIRON_DECL
     extern char **environ;
     #endif

   Solution: Add a guard:

Comments

Ian Lance Taylor March 13, 2013, 6:52 p.m. UTC | #1
On 3/13/13, Eli Zaretskii <eliz@gnu.org> wrote:
>
>      #ifdef __MSVCRT__
>        extern _CRTIMP char *** __cdecl __MINGW_NOTHROW __p__environ(void);
>        extern _CRTIMP wchar_t *** __cdecl __MINGW_NOTHROW
> __p__wenviron(void);
>      # define _environ (*__p__environ())
>      # define _wenviron (*__p__wenviron())
>      #else /* ! __MSVCRT__ */
>      #endif /* ! __MSVCRT__ */
>
>      #define environ _environ

Cool.

>    and setenv.c does this:
>
>      #ifndef HAVE_ENVIRON_DECL
>      extern char **environ;
>      #endif
>
>    Solution: Add a guard:

This is OK with a ChangeLog entry.

Thanks.

Ian
diff mbox

Patch

--- libiberty/setenv.c~	2011-02-03 09:23:59.000000000 +0200
+++ libiberty/setenv.c	2013-03-13 13:22:49.085187200 +0200
@@ -63,8 +63,10 @@ 
 
 #define __environ	environ
 #ifndef HAVE_ENVIRON_DECL
+#ifndef environ
 extern char **environ;
 #endif
+#endif

OK to commit (with a suitable ChangeLog entry)?