Implement setlocale() stub (#43)

This commit is contained in:
Justine Tunney
2021-02-18 17:06:06 -08:00
parent 08d3700c15
commit 667ab245fe
19 changed files with 56 additions and 84 deletions

View File

@ -1890,21 +1890,6 @@ syscon misc ILL_ILLOPN 2 4 2 2 2 0
syscon misc ILL_ILLTRP 4 2 4 4 4 0
syscon misc ILL_PRVOPC 5 3 5 5 5 0
syscon misc LC_CTYPE 0 2 2 2 2 0 # bsd consensus
syscon misc LC_NUMERIC 1 4 4 4 4 0 # bsd consensus
syscon misc LC_CTYPE_MASK 1 0 2 4 4 0
syscon misc LC_TIME 2 5 5 5 5 0 # bsd consensus
syscon misc LC_NUMERIC_MASK 2 0 8 0x10 0x10 0
syscon misc LC_COLLATE 3 1 1 1 1 0 # bsd consensus
syscon misc LC_MONETARY 4 3 3 3 3 0 # bsd consensus
syscon misc LC_TIME_MASK 4 0 0x10 0x20 0x20 0
syscon misc LC_MESSAGES 5 6 6 6 6 0 # bsd consensus
syscon misc LC_ALL 6 0 0 0 0 0
syscon misc LC_COLLATE_MASK 8 0 1 2 2 0
syscon misc LC_MONETARY_MASK 0x10 0 4 8 8 0
syscon misc LC_MESSAGES_MASK 0x20 0 0x20 0x40 0x40 0
syscon misc LC_ALL_MASK 0x1fbf 0 63 126 126 0
syscon lock LOCK_UNLOCK_CACHE 54 0 0 0 0 0 # wut
syscon misc ARPHRD_ETHER 1 1 1 1 1 0 # unix consensus

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_ALL,6,0,0,0,0,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_ALL_MASK,0x1fbf,0,63,126,126,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_COLLATE,3,1,1,1,1,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_COLLATE_MASK,8,0,1,2,2,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_CTYPE,0,2,2,2,2,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_CTYPE_MASK,1,0,2,4,4,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_MESSAGES,5,6,6,6,6,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_MESSAGES_MASK,0x20,0,0x20,0x40,0x40,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_MONETARY,4,3,3,3,3,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_MONETARY_MASK,0x10,0,4,8,8,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_NUMERIC,1,4,4,4,4,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_NUMERIC_MASK,2,0,8,0x10,0x10,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_TIME,2,5,5,5,5,0

View File

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,LC_TIME_MASK,4,0,0x10,0x20,0x20,0

View File

@ -1,40 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_LC_H_
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LC_H_
#include "libc/runtime/symbolic.h"
#define LC_ALL SYMBOLIC(LC_ALL)
#define LC_ALL_MASK SYMBOLIC(LC_ALL_MASK)
#define LC_COLLATE SYMBOLIC(LC_COLLATE)
#define LC_COLLATE_MASK SYMBOLIC(LC_COLLATE_MASK)
#define LC_CTYPE SYMBOLIC(LC_CTYPE)
#define LC_CTYPE_MASK SYMBOLIC(LC_CTYPE_MASK)
#define LC_MESSAGES SYMBOLIC(LC_MESSAGES)
#define LC_MESSAGES_MASK SYMBOLIC(LC_MESSAGES_MASK)
#define LC_MONETARY SYMBOLIC(LC_MONETARY)
#define LC_MONETARY_MASK SYMBOLIC(LC_MONETARY_MASK)
#define LC_NUMERIC SYMBOLIC(LC_NUMERIC)
#define LC_NUMERIC_MASK SYMBOLIC(LC_NUMERIC_MASK)
#define LC_TIME SYMBOLIC(LC_TIME)
#define LC_TIME_MASK SYMBOLIC(LC_TIME_MASK)
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const long LC_ALL;
extern const long LC_ALL_MASK;
extern const long LC_COLLATE;
extern const long LC_COLLATE_MASK;
extern const long LC_CTYPE;
extern const long LC_CTYPE_MASK;
extern const long LC_MESSAGES;
extern const long LC_MESSAGES_MASK;
extern const long LC_MONETARY;
extern const long LC_MONETARY_MASK;
extern const long LC_NUMERIC;
extern const long LC_NUMERIC_MASK;
extern const long LC_TIME;
extern const long LC_TIME_MASK;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_LC_H_ */

View File

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
#include "libc/unicode/locale.h"
typedef void *iconv_t;

26
libc/unicode/locale.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef COSMOPOLITAN_LIBC_UNICODE_LOCALE_H_
#define COSMOPOLITAN_LIBC_UNICODE_LOCALE_H_
#define LC_CTYPE 0
#define LC_NUMERIC 1
#define LC_CTYPE_MASK 1
#define LC_TIME 2
#define LC_NUMERIC_MASK 2
#define LC_COLLATE 3
#define LC_MONETARY 4
#define LC_TIME_MASK 4
#define LC_MESSAGES 5
#define LC_ALL 6
#define LC_COLLATE_MASK 8
#define LC_MONETARY_MASK 16
#define LC_MESSAGES_MASK 32
#define LC_ALL_MASK 0x1fbf
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
char *setlocale(int, const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_UNICODE_LOCALE_H_ */

29
libc/unicode/setlocale.c Normal file
View File

@ -0,0 +1,29 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2021 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/bits/safemacros.h"
#include "libc/unicode/locale.h"
/**
* Sets program locale.
*
* Cosmopolitan only supports the C or POSIX locale.
*/
char *setlocale(int category, const char *locale) {
return firstnonnull(locale, "C");
}