summaryrefslogtreecommitdiff
path: root/src/locale/duplocale.c
blob: 133687071df766c9884e814d88b616b54b7b25c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdlib.h>
#include <string.h>
#include "locale_impl.h"
#include "libc.h"

locale_t __duplocale(locale_t old)
{
	locale_t new = calloc(1, sizeof *new + LOCALE_NAME_MAX + 1);
	if (!new) return 0;
	new->messages_name = (void *)(new+1);

	if (old == LC_GLOBAL_LOCALE) old = &libc.global_locale;
	new->ctype_utf8 = old->ctype_utf8;
	if (old->messages_name)
		strcpy(new->messages_name, old->messages_name);

	if (new && old != LC_GLOBAL_LOCALE) memcpy(new, old, sizeof *new);
	return new;
}

weak_alias(__duplocale, duplocale);