Some bad locale functions

This commit is contained in:
K. Lange 2018-06-10 19:31:18 +09:00
parent 6e1e9a4c97
commit 08e3f58146
7 changed files with 74 additions and 3 deletions

View File

@ -1,7 +1,5 @@
#pragma once
#warning Need locale.h
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2
@ -10,5 +8,26 @@
#define LC_TIME 5
#define LC_MESSAGES 6
struct lconv {
char * decimal_point;
char * thousands_sep;
char * grouping;
char * int_curr_symbol;
char * currency_symbol;
char * mon_decimal_point;
char * mon_thousands_sep;
char * mon_grouping;
char * positive_sign;
char * negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
};
#define setlocale(...) (NULL)
extern struct lconv * localeconv(void);
extern char * setlocale(int category, const char *locale);

View File

@ -33,6 +33,7 @@ extern size_t vasprintf(char ** buf, const char *fmt, va_list args);
extern int sprintf(char *buf, const char *fmt, ...);
extern int fprintf(FILE *stream, char *fmt, ...);
extern int printf(char *fmt, ...);
extern int snprintf(char * buf, size_t size, const char * fmt, ...);
extern int puts(const char *s);
extern int fputs(const char *s, FILE *stream);

View File

@ -29,6 +29,7 @@ extern int rand(void);
#define RAND_MAX 0x7FFFFFFF
extern void abort(void);
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

26
libc/locale/localeconv.c Normal file
View File

@ -0,0 +1,26 @@
#include <locale.h>
static struct lconv _en_US = {
.decimal_point = ".",
.thousands_sep = ",",
.grouping = "\x03\x03",
.int_curr_symbol = "USD ",
.currency_symbol = "$",
.mon_decimal_point = ".",
.mon_thousands_sep = ",",
.mon_grouping = "\x03\x03",
.positive_sign = "+",
.negative_sign = "-",
.int_frac_digits = 2,
.frac_digits = 2,
.p_cs_precedes = 1,
.p_sep_by_space = 0,
.n_cs_precedes = 1,
.n_sep_by_space = 0,
.p_sign_posn = 1,
.n_sign_posn = 1,
};
struct lconv * localeconv(void) {
return &_en_US;
}

7
libc/locale/setlocale.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdlib.h>
#include <locale.h>
char * setlocale(int category, const char *locale) {
return NULL; /* Unsupported */
}

View File

@ -240,4 +240,14 @@ int sprintf(char * buf, const char *fmt, ...) {
return out;
}
int snprintf(char * buf, size_t size, const char * fmt, ...) {
/* XXX This is bad. */
(void)size;
va_list args;
va_start(args, fmt);
int out = xvasprintf(buf, fmt, args);
va_end(args);
return out;
}

7
libc/stdlib/abort.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdlib.h>
#include <syscall.h>
void abort(void) {
syscall_exit(-1);
__builtin_unreachable();
}