Skip to content

Commit

Permalink
- Got rid of GNU extension asprintf to please clang.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13993 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 20, 2012
1 parent c5769da commit fa441d1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Compiler/runtime/systemimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,15 @@ int SystemImpl__intRand(int n)
return r % n;
}

char* alloc_locale_str(const char *locale, int llen, const char *suffix, int slen)
{
char *loc = malloc(sizeof(char) * (llen + slen + 1));
assert(loc != NULL);
strncpy(loc, locale, llen);
strncpy(loc + llen, suffix, slen + 1);
return loc;
}

void SystemImpl__gettextInit(const char *locale)
{
#if defined(_MSC_VER)
Expand All @@ -1935,12 +1944,12 @@ void SystemImpl__gettextInit(const char *locale)
}
#else
/* We might get sent sv_SE when only sv_SE.utf8 exists, etc */
char *locale2 = NULL;
char *locale3 = NULL;
int locale_len = strlen(locale);
char *locale2 = alloc_locale_str(locale, locale_len, ".utf8", 5);
char *locale3 = alloc_locale_str(locale, locale_len, ".UTF-8", 6);
char *old_ctype = strdup(setlocale(LC_CTYPE, ""));
int old_ctype_is_utf8 = strcmp(nl_langinfo(CODESET), "UTF-8") == 0;
assert(asprintf(&locale2, "%s.utf8", locale) > 0);
assert(asprintf(&locale3, "%s.UTF-8", locale) > 0);

int res = *locale == 0 ? setlocale(LC_MESSAGES, "") && setlocale(LC_CTYPE, ""):
(setlocale(LC_MESSAGES, locale3) && setlocale(LC_CTYPE, locale3)) ||
(setlocale(LC_MESSAGES, locale2) && setlocale(LC_CTYPE, locale2)) ||
Expand Down

0 comments on commit fa441d1

Please sign in to comment.