@@ -23,11 +23,11 @@ #ifdef HAVE_WCHAR_H # include #endif -#ifdef HAVE_ASPRINTF_L +#if defined(HAVE_ASPRINTF_L) || defined(HAVE_USELOCALE) # include #endif #ifdef HAVE_XLOCALE_H # include #endif @@ -81,11 +81,11 @@ lengthModifierCapitalL } lengthModifier; bool useLocale; }; -#ifdef HAVE_ASPRINTF_L +#if defined(HAVE_ASPRINTF_L) || defined(HAVE_USELOCALE) static locale_t cLocale; OF_CONSTRUCTOR() { if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL) @@ -375,11 +375,11 @@ static bool formatConversionSpecifierState(struct Context *ctx) { char *tmp = NULL; int tmpLen = 0; -#ifndef HAVE_ASPRINTF_L +#if !defined(HAVE_ASPRINTF_L) && !defined(HAVE_USELOCALE) OFString *point; #endif if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; @@ -546,43 +546,57 @@ case 'a': case 'A': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierL: -#ifdef HAVE_ASPRINTF_L +#if defined(HAVE_ASPRINTF_L) if (!ctx->useLocale) tmpLen = asprintf_l(&tmp, cLocale, ctx->subformat, va_arg(ctx->arguments, double)); else +#elif defined(HAVE_USELOCALE) + if (!ctx->useLocale) { + locale_t previousLocale = uselocale(cLocale); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, double)); + uselocale(previousLocale); + } else #endif tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, double)); break; case lengthModifierCapitalL: -#ifdef HAVE_ASPRINTF_L +#if defined(HAVE_ASPRINTF_L) if (!ctx->useLocale) tmpLen = asprintf_l(&tmp, cLocale, ctx->subformat, va_arg(ctx->arguments, long double)); else +#elif defined(HAVE_USELOCALE) + if (!ctx->useLocale) { + locale_t previousLocale = uselocale(cLocale); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, long double)); + uselocale(previousLocale); + } else #endif tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long double)); break; default: return false; } -#ifndef HAVE_ASPRINTF_L +#if !defined(HAVE_ASPRINTF_L) && !defined(HAVE_USELOCALE) if (tmpLen == -1) return false; /* - * If there's no asprintf_l, we have no other choice than to - * use this ugly hack to replace the locale's decimal point - * back to ".". + * If there's no asprintf_l and no uselocale, we have no other + * choice than to use this ugly hack to replace the locale's + * decimal point back to ".". */ point = [OFLocale decimalSeparator]; if (!ctx->useLocale && point != nil && ![point isEqual: @"."]) { void *pool = objc_autoreleasePoolPush();