9 /* Any pair of 32 bit hashes can be used. lookup3.c generates pairs, will do. */
10 #define _JLU3_jlu32lpair 1
11 #define jlu32lpair poptJlu32lpair
15 POPT_prev_char (const char *str
)
21 if (((unsigned)*p
& 0xc0) != (unsigned)0x80)
27 POPT_next_char (const char *str
)
33 if (((unsigned)*p
& 0xc0) != (unsigned)0x80)
39 #if !defined(POPT_fprintf) /* XXX lose all the goop ... */
41 #if defined(ENABLE_NLS) && defined(HAVE_LIBINTL_H) && defined(HAVE_DCGETTEXT)
43 * Rebind a "UTF-8" codeset for popt's internal use.
46 POPT_dgettext(const char * dom
, const char * str
)
48 char * codeset
= NULL
;
52 dom
= textdomain(NULL
);
53 codeset
= bind_textdomain_codeset(dom
, NULL
);
54 bind_textdomain_codeset(dom
, "UTF-8");
55 retval
= dgettext(dom
, str
);
56 bind_textdomain_codeset(dom
, codeset
);
64 * Return malloc'd string converted from UTF-8 to current locale.
65 * @param istr input string (UTF-8 encoding assumed)
66 * @return localized string
69 strdup_locale_from_utf8 (char * istr
)
71 char * codeset
= NULL
;
78 #ifdef HAVE_LANGINFO_H
79 codeset
= nl_langinfo ((nl_item
)CODESET
);
82 if (codeset
!= NULL
&& strcmp(codeset
, "UTF-8") != 0
83 && (cd
= iconv_open(codeset
, "UTF-8")) != (iconv_t
)-1)
85 char * shift_pin
= NULL
;
86 size_t db
= strlen(istr
);
87 char * dstr
= malloc((db
+ 1) * sizeof(*dstr
));
96 (void) iconv_close(cd
);
99 err
= iconv(cd
, NULL
, NULL
, NULL
, NULL
);
102 err
= iconv(cd
, &pin
, &ib
, &pout
, &ob
);
103 if (err
!= (size_t)-1) {
104 if (shift_pin
== NULL
) {
113 { size_t used
= (size_t)(pout
- dstr
);
115 dstr_tmp
= realloc(dstr
, (db
+ 1) * sizeof(*dstr
));
116 if (dstr_tmp
== NULL
) {
118 (void) iconv_close(cd
);
133 (void) iconv_close(cd
);
135 ostr
= xstrdup(dstr
);
138 ostr
= xstrdup(istr
);
145 POPT_fprintf (FILE * stream
, const char * format
, ...)
147 char * b
= NULL
, * ob
= NULL
;
151 #if defined(HAVE_VASPRINTF)
152 va_start(ap
, format
);
153 if ((rc
= vasprintf(&b
, format
, ap
)) < 0)
157 size_t nb
= (size_t)1;
159 /* HACK: add +1 to the realloc no. of bytes "just in case". */
160 /* XXX Likely unneeded, the issues wrto vsnprintf(3) return b0rkage have
161 * to do with whether the final '\0' is counted (or not). The code
162 * below already adds +1 for the (possibly already counted) trailing NUL.
164 while ((b
= realloc(b
, nb
+1)) != NULL
) {
165 va_start(ap
, format
);
166 rc
= vsnprintf(b
, nb
, format
, ap
);
168 if (rc
> -1) { /* glibc 2.1 */
171 nb
= (size_t)(rc
+ 1); /* precise buffer length known */
172 } else /* glibc 2.0 */
173 nb
+= (nb
< (size_t)100 ? (size_t)100 : nb
);
181 ob
= strdup_locale_from_utf8(b
);
183 rc
= fprintf(stream
, "%s", ob
);
187 rc
= fprintf(stream
, "%s", b
);
194 #endif /* !defined(POPT_fprintf) */