summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rwxr-xr-xconfigure.ac2
-rw-r--r--poptint.c73
-rw-r--r--poptint.h49
4 files changed, 75 insertions, 51 deletions
diff --git a/CHANGES b/CHANGES
index c826bba..9cb0e61 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,6 @@
1.13 -> 1.14:
+ - jbj: permit "#define POPT_fprintf fprintf" to lose the malloc'ing fprintf.
+ - jbj: use vasprintf(3) when available (Wayne Davison<wayned@samba.org>).
- jbj: study the mess with splint, remove annotations where possible.
- jbj: add -D_GNU_SOURCE for gcc to use __builtin_stpcpy when available.
- jbj: add static inline stpcpy for the deprived.
diff --git a/configure.ac b/configure.ac
index 71bcea5..f0f2e43 100755
--- a/configure.ac
+++ b/configure.ac
@@ -69,7 +69,7 @@ AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
AC_CHECK_FUNC(setreuid, [], [
AC_CHECK_LIB(ucb, setreuid, [if echo $LIBS | grep -- -lucb >/dev/null ;then :; else LIBS="$LIBS -lc -lucb" USEUCB=y;fi])
])
-AC_CHECK_FUNCS(getuid geteuid iconv mtrace __secure_getenv setregid stpcpy strerror)
+AC_CHECK_FUNCS(getuid geteuid iconv mtrace __secure_getenv setregid stpcpy strerror vasprintf)
AM_GNU_GETTEXT([external])
diff --git a/poptint.c b/poptint.c
index de2ebbc..3cea184 100644
--- a/poptint.c
+++ b/poptint.c
@@ -16,6 +16,33 @@ static const unsigned char utf8_skip_data[256] = {
};
/*@=varuse =charint =ignoresigns @*/
+const char *
+POPT_prev_char (const char *str)
+{
+ const char *p = str;
+
+ while (1) {
+ p--;
+ if (((unsigned)*p & 0xc0) != (unsigned)0x80)
+ return p;
+ }
+}
+
+const char *
+POPT_next_char (const char *str)
+{
+ const char *p = str;
+
+ while (*p != '\0') {
+ p++;
+ if (((unsigned)*p & 0xc0) != (unsigned)0x80)
+ break;
+ }
+ return p;
+}
+
+#if !defined(POPT_fprintf) /* XXX lose all the goop ... */
+
#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
/*
* Rebind a "UTF-8" codeset for popt's internal use.
@@ -123,42 +150,30 @@ strdup_locale_from_utf8 (/*@null@*/ char *buffer)
}
#endif
-const char *
-POPT_prev_char (const char *str)
-{
- const char *p = str;
-
- while (1) {
- p--;
- if (((unsigned)*p & 0xc0) != (unsigned)0x80)
- return p;
- }
-}
-
-const char *
-POPT_next_char (const char *str)
-{
- const char *p = str;
-
- while (*p != '\0') {
- p++;
- if (((unsigned)*p & 0xc0) != (unsigned)0x80)
- break;
- }
- return p;
-}
-
int
POPT_fprintf (FILE * stream, const char * format, ...)
{
char * b = NULL, * ob = NULL;
- size_t nb = (size_t)1;
int rc;
va_list ap;
+#if defined(HAVE_VASPRINTF)
va_start(ap, format);
- while ((b = realloc(b, nb)) != NULL) {
+ if ((rc = vasprintf(b, format, ap)) < 0)
+ b = NULL;
+ va_end(ap);
+#else
+ size_t nb = (size_t)1;
+
+ /* HACK: add +1 to the realloc no. of bytes "just in case". */
+ /* XXX Likely unneeded, the issues wrto vsnprintf(3) return b0rkage have
+ * to do with whether the final '\0' is counted (or not). The code
+ * below already adds +1 for the (possibly already counted) trailing NUL.
+ */
+ while ((b = realloc(b, nb+1)) != NULL) {
+ va_start(ap, format);
rc = vsnprintf(b, nb, format, ap);
+ va_end(ap);
if (rc > -1) { /* glibc 2.1 */
if ((size_t)rc < nb)
break;
@@ -167,7 +182,7 @@ POPT_fprintf (FILE * stream, const char * format, ...)
nb += (nb < (size_t)100 ? (size_t)100 : nb);
ob = b;
}
- va_end(ap);
+#endif
rc = 0;
if (b != NULL) {
@@ -185,3 +200,5 @@ POPT_fprintf (FILE * stream, const char * format, ...)
return rc;
}
+
+#endif /* !defined(POPT_fprintf) */
diff --git a/poptint.h b/poptint.h
index 9c2b73b..f0be0b5 100644
--- a/poptint.h
+++ b/poptint.h
@@ -133,26 +133,9 @@ struct poptContext_s {
pbm_set * arg_strip;
};
-#ifdef HAVE_LIBINTL_H
-#include <libintl.h>
-#endif
-
-#if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
-#define _(foo) gettext(foo)
+#if defined(POPT_fprintf)
+#define POPT_dgettext dgettext
#else
-#define _(foo) foo
-#endif
-
-#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
-#define D_(dom, str) POPT_dgettext(dom, str)
-#define POPT_(foo) D_("popt", foo)
-#else
-#define D_(dom, str) str
-#define POPT_(foo) foo
-#endif
-
-#define N_(foo) foo
-
#ifdef HAVE_ICONV
#include <iconv.h>
#if defined(__LCLINT__)
@@ -188,14 +171,36 @@ char *POPT_dgettext(const char * dom, const char * str)
/*@*/;
#endif
+int POPT_fprintf (FILE* stream, const char *format, ...)
+ /*@globals fileSystem @*/
+ /*@modifies stream, fileSystem @*/;
+#endif /* !defined(POPT_fprintf) */
+
const char *POPT_prev_char (/*@returned@*/ const char *str)
/*@*/;
const char *POPT_next_char (/*@returned@*/ const char *str)
/*@*/;
-int POPT_fprintf (FILE* stream, const char *format, ...)
- /*@globals fileSystem @*/
- /*@modifies stream, fileSystem @*/;
+#endif
+
+#ifdef HAVE_LIBINTL_H
+#include <libintl.h>
+#endif
+#if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
+#define _(foo) gettext(foo)
+#else
+#define _(foo) foo
#endif
+
+#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
+#define D_(dom, str) POPT_dgettext(dom, str)
+#define POPT_(foo) D_("popt", foo)
+#else
+#define D_(dom, str) str
+#define POPT_(foo) foo
+#endif
+
+#define N_(foo) foo
+