2020-12-09 23:04:54 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_FMT_CONV_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_FMT_CONV_H_
|
2020-08-25 11:23:25 +00:00
|
|
|
#include "libc/calls/struct/timespec.h"
|
|
|
|
#include "libc/calls/struct/timeval.h"
|
|
|
|
#include "libc/nt/struct/filetime.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § conversion ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
2020-10-06 06:11:49 +00:00
|
|
|
#define MODERNITYSECONDS 11644473600ull
|
|
|
|
#define HECTONANOSECONDS 10000000ull
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
int abs(int) libcesque pureconst;
|
|
|
|
long labs(long) libcesque pureconst;
|
|
|
|
long long llabs(long long) libcesque pureconst;
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
intmax_t imaxabs(intmax_t) libcesque pureconst;
|
2020-10-11 04:18:53 +00:00
|
|
|
int atoi(const char *) paramsnonnull() libcesque;
|
|
|
|
long atol(const char *) paramsnonnull() libcesque;
|
|
|
|
long long atoll(const char *) paramsnonnull() libcesque;
|
2020-06-15 14:18:57 +00:00
|
|
|
unsigned long strtoul(const char *, char **, int) paramsnonnull((1));
|
|
|
|
long long strtoll(const char *, char **, int) paramsnonnull((1));
|
|
|
|
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
|
|
|
|
long long strtonum(const char *, long long, long long, const char **);
|
|
|
|
intmax_t strtoimax(const char *, char **, int) paramsnonnull((1));
|
|
|
|
uintmax_t strtoumax(const char *, char **, int) paramsnonnull((1));
|
|
|
|
intmax_t wcstoimax(const wchar_t *, wchar_t **, int);
|
2021-08-13 18:18:25 +00:00
|
|
|
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
long wcstol(const wchar_t *, wchar_t **, int);
|
2021-08-13 18:18:25 +00:00
|
|
|
unsigned long wcstoul(const wchar_t *, wchar_t **, int);
|
2020-10-11 04:18:53 +00:00
|
|
|
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
|
2021-08-13 18:18:25 +00:00
|
|
|
long sizetol(const char *, long) paramsnonnull() libcesque;
|
2022-08-17 20:41:21 +00:00
|
|
|
char *sizefmt(char *, uint64_t, uint64_t);
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
long long wcstoll(const wchar_t *, wchar_t **, int);
|
|
|
|
unsigned long long wcstoull(const wchar_t *, wchar_t **, int);
|
|
|
|
int wcscoll(const wchar_t *, const wchar_t *);
|
|
|
|
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § conversion » time ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
2022-07-08 13:29:24 +00:00
|
|
|
struct timeval _timespec2timeval(struct timespec);
|
2022-04-06 07:13:44 +00:00
|
|
|
int64_t DosDateTimeToUnix(unsigned, unsigned) libcesque nosideeffect;
|
|
|
|
struct timeval WindowsTimeToTimeVal(int64_t) libcesque nosideeffect;
|
|
|
|
struct timespec WindowsTimeToTimeSpec(int64_t) libcesque nosideeffect;
|
|
|
|
int64_t TimeSpecToWindowsTime(struct timespec) libcesque nosideeffect;
|
|
|
|
int64_t TimeValToWindowsTime(struct timeval) libcesque nosideeffect;
|
|
|
|
struct timeval WindowsDurationToTimeVal(int64_t) libcesque nosideeffect;
|
|
|
|
struct timespec WindowsDurationToTimeSpec(int64_t) libcesque nosideeffect;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2022-06-20 11:32:25 +00:00
|
|
|
#define MakeFileTime(x) \
|
|
|
|
({ \
|
|
|
|
int64_t __x = x; \
|
|
|
|
(struct NtFileTime){(uint32_t)__x, (uint32_t)(__x >> 32)}; \
|
|
|
|
})
|
2021-08-16 22:26:31 +00:00
|
|
|
|
2022-06-20 11:32:25 +00:00
|
|
|
#define ReadFileTime(t) \
|
|
|
|
({ \
|
|
|
|
struct NtFileTime __t = t; \
|
|
|
|
uint64_t x = __t.dwHighDateTime; \
|
|
|
|
(int64_t)(x << 32 | __t.dwLowDateTime); \
|
|
|
|
})
|
2021-08-16 22:26:31 +00:00
|
|
|
|
|
|
|
#define FileTimeToTimeSpec(x) WindowsTimeToTimeSpec(ReadFileTime(x))
|
|
|
|
#define FileTimeToTimeVal(x) WindowsTimeToTimeVal(ReadFileTime(x))
|
|
|
|
#define TimeSpecToFileTime(x) MakeFileTime(TimeSpecToWindowsTime(x))
|
|
|
|
#define TimeValToFileTime(x) MakeFileTime(TimeValToWindowsTime(x))
|
2021-08-14 13:17:56 +00:00
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § conversion » manipulation ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
2020-12-01 11:43:40 +00:00
|
|
|
char *dirname(char *);
|
2022-04-06 07:13:44 +00:00
|
|
|
char *basename(char *);
|
2021-09-28 05:58:51 +00:00
|
|
|
char *stripext(char *);
|
2021-07-19 21:55:20 +00:00
|
|
|
char *stripexts(char *);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § conversion » computation ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int quot;
|
|
|
|
int rem;
|
|
|
|
} div_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-05-12 13:11:22 +00:00
|
|
|
long int quot;
|
|
|
|
long int rem;
|
2020-06-15 14:18:57 +00:00
|
|
|
} ldiv_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-05-12 13:11:22 +00:00
|
|
|
long long int quot;
|
|
|
|
long long int rem;
|
2020-06-15 14:18:57 +00:00
|
|
|
} lldiv_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
intmax_t quot;
|
|
|
|
intmax_t rem;
|
|
|
|
} imaxdiv_t;
|
|
|
|
|
|
|
|
div_t div(int, int) pureconst;
|
|
|
|
ldiv_t ldiv(long, long) pureconst;
|
|
|
|
lldiv_t lldiv(long long, long long) pureconst;
|
|
|
|
imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;
|
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § conversion » optimizations ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
|
|
|
#if __STDC_VERSION__ + 0 >= 199901L
|
|
|
|
#define div(num, den) ((div_t){(num) / (den), (num) % (den)})
|
|
|
|
#define ldiv(num, den) ((ldiv_t){(num) / (den), (num) % (den)})
|
|
|
|
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
|
|
|
|
#endif
|
|
|
|
|
2022-09-10 23:11:26 +00:00
|
|
|
#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)) && \
|
|
|
|
!defined(__STRICT_ANSI__)
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
int128_t i128abs(int128_t) libcesque pureconst;
|
|
|
|
int128_t strtoi128(const char *, char **, int) paramsnonnull((1));
|
|
|
|
uint128_t strtou128(const char *, char **, int) paramsnonnull((1));
|
|
|
|
int128_t wcstoi128(const wchar_t *, wchar_t **, int);
|
|
|
|
uint128_t wcstou128(const wchar_t *, wchar_t **, int);
|
|
|
|
#endif /* gcc 4.6+ */
|
2020-08-25 11:23:25 +00:00
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
2020-12-09 23:04:54 +00:00
|
|
|
#endif /* COSMOPOLITAN_LIBC_FMT_CONV_H_ */
|