Although git itself would not be using "#include <libintl.h>" anywhere
in a NO_GETTEXT build, git's gettext.h is meant to tolerate prior
declarations from libintl, to prepare for a scenario in which some
system or compat/ header decides to start including libintl. GNU
libintl.h defines ngettext as a macro when __OPTIMIZE__ is defined, so
take care to "#undef ngettext" if it was defined for us.
To avoid having to worry about a conflicting ngettext symbol when
libintl is part of libc, also rename the no-op ngettext stub to
git_ngettext and make ngettext a macro referring to it. This is
probably never necessary (because git's ngettext is declared "static
inline") but it buys peace of mind.
This change does not protect against conflicts due to a header
included _after_ git's i18n support (e.g., pthread.h) being the first
to pull in libintl. We can deal with that separately if it happens.
Signed-off-by: Jonathan Nieder <redacted>
---
gettext.h | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/gettext.h b/gettext.h
index 03fb340..a473af4 100644
--- a/gettext.h
+++ b/gettext.h
@@ -13,6 +13,10 @@
#error "namespace conflict: '_' is pre-defined?"
#endif
+#ifdef ngettext
+#undef ngettext
+#endif
+
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
#ifdef GETTEXT_POISON
@@ -26,8 +30,9 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
return use_gettext_poison() ? " GETTEXT POISON " : msgid;
}
+#define ngettext git_ngettext
static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
-const char *ngettext(const char *msgid, const char *plu, unsigned long n)
+const char *git_ngettext(const char *msgid, const char *plu, unsigned long n)
{
if (use_gettext_poison())
return " GETTEXT POISON ";--
1.7.4.1