threads / patch / 35770

patchCleanly redefine (v)snprintf when needed.

Subject: [PATCH] Cleanly redefine (v)snprintf when needed.

## tl;dr

3 messages between Jan 31, 2014 and Jan 31, 2014. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Benoit Sigoure· Jan 31, 2014, 06:25 UTC · lore
When we detect that vsnprintf / snprintf are broken, we #define them to
an alternative implementation.  On OS X, stdio.h already #define's them,
which causes a warning to be issued at the point we re-define them in
`git-compat-util.h'.
---
 git-compat-util.h | 6 ++++++
 1 file changed, 6 insertions(+)
Show changes to git-compat-util.h +6 −0
diff --git a/git-compat-util.h b/git-compat-util.h
index cbd86c3..614a5e9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -480,9 +480,15 @@ extern FILE *git_fopen(const char*, const char*);
 #endif
 
 #ifdef SNPRINTF_RETURNS_BOGUS
+#ifdef snprintf
+#undef snprintf
+#endif
 #define snprintf git_snprintf
 extern int git_snprintf(char *str, size_t maxsize,
 			const char *format, ...);
+#ifdef vsnprintf
+#undef vsnprintf
+#endif
 #define vsnprintf git_vsnprintf
 extern int git_vsnprintf(char *str, size_t maxsize,
 			 const char *format, va_list ap);
-- 
1.9.rc1.1.g186f0be.dirty
Junio C Hamano· Jan 31, 2014, 17:28 UTC · re: Benoit Sigoure · lore

Re: [PATCH] Cleanly redefine (v)snprintf when needed.

Benoit Sigoure <tsunanet@gmail.com> writes:
Show 5 quoted lines
> When we detect that vsnprintf / snprintf are broken, we #define them to
> an alternative implementation.  On OS X, stdio.h already #define's them,
> which causes a warning to be issued at the point we re-define them in
> `git-compat-util.h'.
> ---

Makes perfect sense. Please sign-off your patch (see Documentation/SubmittingPatches).

Thanks.
Show 23 quoted lines
>  git-compat-util.h | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index cbd86c3..614a5e9 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -480,9 +480,15 @@ extern FILE *git_fopen(const char*, const char*);
>  #endif
>  
>  #ifdef SNPRINTF_RETURNS_BOGUS
> +#ifdef snprintf
> +#undef snprintf
> +#endif
>  #define snprintf git_snprintf
>  extern int git_snprintf(char *str, size_t maxsize,
>  			const char *format, ...);
> +#ifdef vsnprintf
> +#undef vsnprintf
> +#endif
>  #define vsnprintf git_vsnprintf
>  extern int git_vsnprintf(char *str, size_t maxsize,
>  			 const char *format, va_list ap);
Benoit Sigoure· Jan 31, 2014, 17:36 UTC · re: Junio C Hamano · lore

When we detect that vsnprintf / snprintf are broken, we #define them to an alternative implementation. On OS X, stdio.h already #define's them, which causes a warning to be issued at the point we re-define them in `git-compat-util.h'.

Signed-off-by: Benoit Sigoure <tsunanet@gmail.com>
---
 git-compat-util.h | 6 ++++++
 1 file changed, 6 insertions(+)
Show changes to git-compat-util.h +6 −0
diff --git a/git-compat-util.h b/git-compat-util.h
index cbd86c3..614a5e9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -480,9 +480,15 @@ extern FILE *git_fopen(const char*, const char*);
 #endif
 
 #ifdef SNPRINTF_RETURNS_BOGUS
+#ifdef snprintf
+#undef snprintf
+#endif
 #define snprintf git_snprintf
 extern int git_snprintf(char *str, size_t maxsize,
 			const char *format, ...);
+#ifdef vsnprintf
+#undef vsnprintf
+#endif
 #define vsnprintf git_vsnprintf
 extern int git_vsnprintf(char *str, size_t maxsize,
 			 const char *format, va_list ap);
-- 
1.9.rc1.1.g186f0be.dirty

← back to recent threads