memdebug.h: avoid -Wredundant-decls with an extra guard

Add an extra guard for the function and variable declarations to avoid
redundant redeclaration warnings when including this header multiple
times. This can happen in unity builds when including it again after
`curl_memory.h`.

Fixes:
```
bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c
In file included from lib/mprintf.c:32,
                 from bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c:7:
lib/memdebug.h:52:14: error: redundant redeclaration of ‘curl_dbg_logfile’ [-Werror=redundant-decls]
   52 | extern FILE *curl_dbg_logfile;
      |              ^~~~~~~~~~~~~~~~
In file included from tests/server/resolve.c:50,
                 from bld/tests/server/server_bundle.c:7,
                 from bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c:4:
lib/memdebug.h:52:14: note: previous declaration of ‘curl_dbg_logfile’ with type ‘FILE *’
   52 | extern FILE *curl_dbg_logfile;
      |              ^~~~~~~~~~~~~~~~
[...]
lib/memdebug.h:110:17: error: redundant redeclaration of ‘curl_dbg_fclose’ [-Werror=redundant-decls]
  110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
      |                 ^~~~~~~~~~~~~~~
lib/memdebug.h:110:17: note: previous declaration of ‘curl_dbg_fclose’ with type ‘int(FILE *, int,  const char *)’
  110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
      |                 ^~~~~~~~~~~~~~~
```
Ref: https://github.com/curl/curl/actions/runs/13822010778/job/38669360980#step:39:55

Cherry-picked from #15000
Closes #16696
This commit is contained in:
Viktor Szakats 2025-03-12 22:59:53 +01:00
parent 77401af485
commit 44d4957a6f
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201

View file

@ -49,6 +49,10 @@
#define CURL_MT_LOGFNAME_BUFSIZE 512
/* Avoid redundant redeclaration warnings with modern compilers, when including
this header multiple times. */
#ifndef HEADER_CURL_MEMDEBUG_H_EXTERNS
#define HEADER_CURL_MEMDEBUG_H_EXTERNS
extern FILE *curl_dbg_logfile;
/* memory functions */
@ -108,6 +112,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
int line, const char *source);
CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
#endif /* HEADER_CURL_MEMDEBUG_H_EXTERNS */
#ifndef MEMDEBUG_NODEFINES