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;
|
|
|
|
int llog10(unsigned long) 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 **);
|
2020-07-01 02:55:47 +00:00
|
|
|
intmax_t div10(intmax_t, unsigned *) hidden;
|
2020-06-15 14:18:57 +00:00
|
|
|
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;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § conversion » time ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
2021-08-16 22:26:31 +00:00
|
|
|
int64_t DosDateTimeToUnix(unsigned, unsigned) nothrow;
|
|
|
|
struct timeval WindowsTimeToTimeVal(int64_t) nothrow;
|
|
|
|
struct timespec WindowsTimeToTimeSpec(int64_t) nothrow;
|
|
|
|
int64_t TimeSpecToWindowsTime(struct timespec) nothrow;
|
|
|
|
int64_t TimeValToWindowsTime(struct timeval) nothrow;
|
|
|
|
struct timeval WindowsDurationToTimeVal(int64_t) nothrow;
|
|
|
|
struct timespec WindowsDurationToTimeSpec(int64_t) nothrow;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-08-16 22:26:31 +00:00
|
|
|
static inline struct NtFileTime MakeFileTime(int64_t x) {
|
|
|
|
return (struct NtFileTime){x, x >> 32};
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int64_t ReadFileTime(struct NtFileTime t) {
|
|
|
|
uint64_t x = t.dwHighDateTime;
|
|
|
|
return x << 32 | t.dwLowDateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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 *);
|
2020-06-15 14:18:57 +00:00
|
|
|
char *basename(const char *) nosideeffect;
|
|
|
|
char *basename_n(const char *, size_t) nosideeffect;
|
|
|
|
bool isabspath(const char *) paramsnonnull() nosideeffect;
|
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 {
|
|
|
|
long int quot;
|
|
|
|
long int rem;
|
|
|
|
} ldiv_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
long long int quot;
|
|
|
|
long long int rem;
|
|
|
|
} 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
|
|
|
|
|
2020-08-25 11:23:25 +00:00
|
|
|
#ifndef __STRICT_ANSI__
|
2020-12-05 20:20:41 +00:00
|
|
|
intmax_t __imaxabs(intmax_t) libcesque pureconst;
|
2020-08-25 11:23:25 +00:00
|
|
|
#define imaxabs(x) __imaxabs(x)
|
|
|
|
#endif /* !ANSI */
|
|
|
|
|
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_ */
|