Sfoglia il codice sorgente

LibC: Implement CODESET for langinfo

Tim Schumacher 4 anni fa
parent
commit
8f9af4a582

+ 1 - 0
Userland/Libraries/LibC/CMakeLists.txt

@@ -12,6 +12,7 @@ set(LIBC_SOURCES
     grp.cpp
     inttypes.cpp
     ioctl.cpp
+    langinfo.cpp
     libcinit.cpp
     libgen.cpp
     link.cpp

+ 27 - 0
Userland/Libraries/LibC/langinfo.cpp

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2021, the SerenityOS developers
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <langinfo.h>
+
+static const char* __nl_langinfo(nl_item item)
+{
+    switch (item) {
+    case CODESET:
+        return "UTF-8";
+    default:
+        return "";
+    }
+}
+
+extern "C" {
+
+char* nl_langinfo(nl_item item)
+{
+    // POSIX states that returned strings should not be modified,
+    // so this cast is probably fine.
+    return const_cast<char*>(__nl_langinfo(item));
+}
+}

+ 20 - 0
Userland/Libraries/LibC/langinfo.h

@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2021, the SerenityOS developers
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <nl_types.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+enum {
+    CODESET,
+};
+
+char* nl_langinfo(nl_item);
+
+__END_DECLS

+ 15 - 0
Userland/Libraries/LibC/nl_types.h

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2021, the SerenityOS developers
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+typedef int nl_item;
+
+__END_DECLS