diff --git a/base/usr/include/locale.h b/base/usr/include/locale.h index 85ebc71a..805aab91 100644 --- a/base/usr/include/locale.h +++ b/base/usr/include/locale.h @@ -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); diff --git a/base/usr/include/stdio.h b/base/usr/include/stdio.h index fe85d286..ce18ae75 100644 --- a/base/usr/include/stdio.h +++ b/base/usr/include/stdio.h @@ -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); diff --git a/base/usr/include/stdlib.h b/base/usr/include/stdlib.h index 913a3925..8d04bf98 100644 --- a/base/usr/include/stdlib.h +++ b/base/usr/include/stdlib.h @@ -29,6 +29,7 @@ extern int rand(void); #define RAND_MAX 0x7FFFFFFF +extern void abort(void); #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 diff --git a/libc/locale/localeconv.c b/libc/locale/localeconv.c new file mode 100644 index 00000000..8ebe01d8 --- /dev/null +++ b/libc/locale/localeconv.c @@ -0,0 +1,26 @@ +#include + +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; +} diff --git a/libc/locale/setlocale.c b/libc/locale/setlocale.c new file mode 100644 index 00000000..9a4112dc --- /dev/null +++ b/libc/locale/setlocale.c @@ -0,0 +1,7 @@ +#include +#include + +char * setlocale(int category, const char *locale) { + return NULL; /* Unsupported */ +} + diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c index fec3c300..5edf367d 100644 --- a/libc/stdio/printf.c +++ b/libc/stdio/printf.c @@ -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; +} + diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c new file mode 100644 index 00000000..0da7cb08 --- /dev/null +++ b/libc/stdlib/abort.c @@ -0,0 +1,7 @@ +#include +#include + +void abort(void) { + syscall_exit(-1); + __builtin_unreachable(); +}