Compare commits

...

3 Commits

Author SHA1 Message Date
dcb8ab569a
libc: Add basic sys/param.h for programs that want it
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-31 22:15:22 +02:00
d467f6257d
libc: Define EXIT_* macros and strto(u)ll in stdlib.h 2023-05-31 22:15:05 +02:00
5c68d50070
libc: Add a very bare-bones locale.h 2023-05-31 22:12:50 +02:00
6 changed files with 73 additions and 0 deletions

View File

@ -19,6 +19,7 @@ set(SOURCES
src/env.cpp src/env.cpp
src/pwd.cpp src/pwd.cpp
src/grp.cpp src/grp.cpp
src/locale.cpp
src/sys/stat.cpp src/sys/stat.cpp
src/sys/mman.cpp src/sys/mman.cpp
src/sys/wait.cpp src/sys/wait.cpp

View File

@ -0,0 +1,18 @@
/* bits/locale-cat.h: Locale categories. */
#ifndef _BITS_LOCALE_CAT_H
#define _BITS_LOCALE_CAT_H
enum __libc_locale_category
{
LC_ALL, // Controls all locales.
LC_CTYPE, // Character classification and case conversion.
LC_COLLATE, // Collation order.
LC_MONETARY, // Monetary formatting.
LC_NUMERIC, // Numeric, non-monetary formatting.
LC_TIME, // Date and time formats.
LC_MESSAGES, // Formats of informative and diagnostic messages and interactive responses.
__num_locale_categories,
};
#endif

20
libc/include/locale.h Normal file
View File

@ -0,0 +1,20 @@
/* locale.h: Locale category macros. */
#ifndef _LOCALE_H
#define _LOCALE_H
#include <bits/locale-cat.h>
#ifdef __cplusplus
extern "C"
{
#endif
// Query or set the current locale.
char* setlocale(int category, const char* locale);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -31,6 +31,9 @@ typedef struct
#define RAND_MAX 32767 #define RAND_MAX 32767
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
@ -93,6 +96,9 @@ extern "C"
* endptr if nonnull. */ * endptr if nonnull. */
unsigned long strtoul(const char* str, char** endptr, int base); unsigned long strtoul(const char* str, char** endptr, int base);
#define strtoll strtol
#define strtoull strtoul
/* Return the next pseudorandom number. */ /* Return the next pseudorandom number. */
int rand(); int rand();

16
libc/include/sys/param.h Normal file
View File

@ -0,0 +1,16 @@
/* sys/param.h: Old-style BSD macros. */
#ifndef _SYS_PARAM_H
#define _SYS_PARAM_H
#include <limits.h>
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#endif

12
libc/src/locale.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <locale.h>
static char s_default_locale[] = "C";
extern "C"
{
char* setlocale(int, const char*)
{
// FIXME: Set the current locale if <locale> is not NULL.
return s_default_locale;
}
}