Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <assert.h>
8#include <locale.h>
9#include <stdio.h>
10#include <string.h>
11
12extern "C" {
13
14static char default_decimal_point[] = ".";
15static char default_thousands_sep[] = ",";
16static char default_grouping[] = "\x03\x03";
17
18static char default_empty_string[] = "";
19static char default_empty_value = 127;
20
21static struct lconv default_locale = {
22 default_decimal_point,
23 default_thousands_sep,
24 default_grouping,
25 default_empty_string,
26 default_empty_string,
27 default_empty_string,
28 default_empty_string,
29 default_empty_string,
30 default_empty_string,
31 default_empty_string,
32 default_empty_value,
33 default_empty_value,
34 default_empty_value,
35 default_empty_value,
36 default_empty_value,
37 default_empty_value,
38 default_empty_value,
39 default_empty_value,
40 default_empty_value,
41 default_empty_value,
42 default_empty_value,
43 default_empty_value,
44 default_empty_value,
45 default_empty_value
46};
47
48char* setlocale(int, char const* locale)
49{
50 static char c_locale_string[2];
51 memcpy(c_locale_string, "C", 2);
52
53 // If we get a null pointer, return the current locale as per POSIX spec.
54 if (locale == nullptr)
55 return c_locale_string;
56
57 if (strcmp(locale, "POSIX") == 0 || strcmp(locale, "C") == 0 || strcmp(locale, "") == 0)
58 return c_locale_string;
59
60 return nullptr;
61}
62
63struct lconv* localeconv()
64{
65 return &default_locale;
66}
67}