Compare commits
20 Commits
82bd234d08
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 82a6293f21 | |||
| c4fd22542d | |||
| 4cfed24ec3 | |||
| de88e9ff16 | |||
| 26de01c3e7 | |||
| 7dc80c2fdf | |||
| bdbe959e23 | |||
| 94b051e852 | |||
| 08d45faa83 | |||
| af0931c727 | |||
| 0d422cd7e5 | |||
| 17d2d1c38d | |||
| a57f05cfeb | |||
| ea6c20f430 | |||
| 77e4f38416 | |||
| f3e4f8f061 | |||
| 83091ac707 | |||
|
|
6a7f0a8715 | ||
| 8a40caaf10 | |||
| 4c97787c27 |
23
README.md
23
README.md
@@ -3,21 +3,34 @@ C library with collections, strings, exceptions, io...
|
||||
|
||||
|
||||
## Build
|
||||
1. Clone the repository.
|
||||
1. Clone this repository.
|
||||
```
|
||||
git clone https://timerix.ddns.net/git/Timerix/tlibc.git
|
||||
```
|
||||
2. Install [cbuild](https://timerix.ddns.net/git/Timerix/cbuild).
|
||||
|
||||
2. Install [cbuild](https://timerix.ddns.net/git/Timerix/cbuild/releases).
|
||||
Select latest version compatible with the one in `project.config`.
|
||||
Example: For `2.3.0` download latest `2.3.x`.
|
||||
|
||||
|
||||
3. Build static library
|
||||
```
|
||||
cd tlibc
|
||||
cbuild build_static_lib_dbg
|
||||
```
|
||||
|
||||
6. If you use tlibc as static library, add `LINKER_LIBS` from tlibc `project.config` to your project.
|
||||
|
||||
|
||||
## Usage
|
||||
Include `tlibc/tlibc.h` and put this code at the beginning of `main()`.
|
||||
```
|
||||
Deferral(32);
|
||||
```c
|
||||
#include "tlibc/tlibc.h"
|
||||
|
||||
int main(){
|
||||
Deferral(32); // reserve memory for 32 defers
|
||||
try_fatal_void(tlibc_init());
|
||||
Defer(tlibc_deinit());
|
||||
|
||||
Return 0; // call defers
|
||||
}
|
||||
```
|
||||
|
||||
32
include/tlibc/algorithms.h
Normal file
32
include/tlibc/algorithms.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "std.h"
|
||||
|
||||
/// USAGE insertionSort(list.data, list.len, .id)
|
||||
#define insertionSort_inline(arr, n, field) \
|
||||
for(i32 i = 1, j; i < (i32)n; i++) { \
|
||||
j = i; \
|
||||
typeof(arr[i]) t = arr[i];\
|
||||
while(j > 0 && arr[j - 1]field > t##field){\
|
||||
arr[j] = arr[j - 1]; \
|
||||
j--; \
|
||||
} \
|
||||
arr[j] = t; \
|
||||
} \
|
||||
|
||||
#define binarySearch_inline(arr, n, key, field, out_index) {\
|
||||
i32 low = 0; \
|
||||
i32 high = n - 1; \
|
||||
while (low <= high) { \
|
||||
i32 mid = low + (high - low) / 2; \
|
||||
if (arr[mid]field == key) { \
|
||||
out_index = mid; \
|
||||
break; \
|
||||
} \
|
||||
/* choose left or right half */ \
|
||||
if (arr[mid]field < key) \
|
||||
low = mid + 1; \
|
||||
else high = mid - 1; \
|
||||
} \
|
||||
out_index = -1; \
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ typedef struct HashMapIter {
|
||||
|
||||
typedef struct HashMapKeyValue {
|
||||
str key;
|
||||
void* value;
|
||||
void* value_ptr;
|
||||
} HashMapKeyValue;
|
||||
|
||||
static inline HashMapIter HashMapIter_create(const HashMap_* table){
|
||||
|
||||
@@ -21,7 +21,7 @@ static inline LLNode(T)* LLNode_##T##_createZero(){ \
|
||||
LLNode(T)* n = (LLNode(T)*)malloc(sizeof(LLNode(T))); \
|
||||
n->prev = NULL; \
|
||||
n->next = NULL; \
|
||||
memset(&n->value, 0, sizeof(T)); \
|
||||
zeroStruct(&n->value); \
|
||||
return n; \
|
||||
} \
|
||||
\
|
||||
|
||||
@@ -27,23 +27,23 @@ static inline List(T) List_##T##_construct(T* data_ptr, u32 occupied_len, u32 ca
|
||||
\
|
||||
static inline List(T) List_##T##_alloc(u32 initial_capacity) { \
|
||||
List_ l = _List_alloc(initial_capacity, sizeof(T)); \
|
||||
return *(List(T)*)(void*)&l; \
|
||||
void* l_ptr = &l; \
|
||||
return *(List(T)*)l_ptr; \
|
||||
} \
|
||||
\
|
||||
static inline List(T) List_##T##_copy(const List(T)* src) { \
|
||||
List_ l = _List_copy((void*)src); \
|
||||
return *(List(T)*)(void*)&l; \
|
||||
void* l_ptr = &l; \
|
||||
return *(List(T)*)l_ptr; \
|
||||
} \
|
||||
\
|
||||
static inline void List_##T##_destroy(List(T)* self) { _List_destroy((void*)self); } \
|
||||
\
|
||||
static inline void List_##T##_push(List(T)* self, T value) { \
|
||||
T* empty_cell = (T*)(_List_expand((void*)self, 1)); \
|
||||
*empty_cell = value; \
|
||||
} \
|
||||
\
|
||||
static inline void List_##T##_pushMany(List(T)* self, T* values_ptr, u32 len) { \
|
||||
_List_push((void*)self, values_ptr, len); \
|
||||
static inline void List_##T##_destroyWithElements(List(T)* self, void (*elem_destructor)(T*)) { \
|
||||
for(u32 i = 0; i < self->len; i++){ \
|
||||
elem_destructor(self->data + i);\
|
||||
} \
|
||||
_List_destroy((void*)self); \
|
||||
} \
|
||||
\
|
||||
/* alloc bigger buffer if size + len_to_add won't fit in current */ \
|
||||
@@ -51,6 +51,20 @@ static inline void List_##T##_increaseCapacity(List(T)* self, u32 len_to_add){ \
|
||||
_List_increaseCapacity((void*)self, len_to_add); \
|
||||
} \
|
||||
\
|
||||
/* call increaseCapacity and return pointer to next empty cell */ \
|
||||
static inline T* List_##T##_expand(List(T)* self, u32 len_to_add){ \
|
||||
return (T*)_List_expand((void*)self, len_to_add); \
|
||||
} \
|
||||
\
|
||||
static inline void List_##T##_push(List(T)* self, T value) { \
|
||||
T* empty_cell = List_##T##_expand(self, 1); \
|
||||
*empty_cell = value; \
|
||||
} \
|
||||
\
|
||||
static inline void List_##T##_pushMany(List(T)* self, T* values_ptr, u32 len) { \
|
||||
_List_push((void*)self, values_ptr, len); \
|
||||
} \
|
||||
\
|
||||
static inline bool List_##T##_tryRemoveAt(List(T)* self, u32 i, u32 remove_len) ATTRIBUTE_WARN_UNUSED_RESULT; \
|
||||
static inline bool List_##T##_tryRemoveAt(List(T)* self, u32 i, u32 remove_len) { \
|
||||
return _List_tryRemoveAt((void*)self, i, remove_len); \
|
||||
|
||||
@@ -17,18 +17,21 @@ void foo(){
|
||||
#if defined(__GNUC__) || defined(__TINYC__)
|
||||
|
||||
#define Deferral(MAX_DEFER_STATEMENTS) \
|
||||
unsigned char _num_deferrals = 0; \
|
||||
void *_defer_return_loc = 0, *_deferrals[MAX_DEFER_STATEMENTS] = {0};
|
||||
int _num_deferrals = 0; \
|
||||
ATTRIBUTE_UNUSED void *_defer_return_loc = 0;\
|
||||
ATTRIBUTE_UNUSED void *_deferrals[MAX_DEFER_STATEMENTS] = {0};
|
||||
|
||||
# define Defer(block) _Defer(block, __LINE__)
|
||||
# define Return _Return(__LINE__)
|
||||
|
||||
#define _defer_token_cat(a, b) a ## b
|
||||
#ifndef CAT2
|
||||
#define CAT2(a, b) a ## b
|
||||
#endif
|
||||
|
||||
#define _Defer(block, n) do { \
|
||||
_deferrals[_num_deferrals++] = && _defer_token_cat(_defer_ini, n); \
|
||||
_deferrals[_num_deferrals++] = && CAT2(_defer_ini, n); \
|
||||
if (0) { \
|
||||
_defer_token_cat(_defer_ini, n): \
|
||||
CAT2(_defer_ini, n): \
|
||||
block; \
|
||||
if (_num_deferrals) { \
|
||||
goto *_deferrals[--_num_deferrals]; \
|
||||
@@ -39,13 +42,11 @@ void foo(){
|
||||
} while (0)
|
||||
|
||||
#define _Return(n) \
|
||||
if (_num_deferrals \
|
||||
/* this nonsense disables warning Wunused-but-set-variable */ \
|
||||
&& _defer_return_loc == _defer_return_loc ) \
|
||||
if (_num_deferrals) \
|
||||
{ \
|
||||
_defer_return_loc = && _defer_token_cat(_defer_fini_, n); \
|
||||
_defer_return_loc = && CAT2(_defer_fini_, n); \
|
||||
goto *_deferrals[--_num_deferrals]; \
|
||||
} else _defer_token_cat(_defer_fini_, n): \
|
||||
} else CAT2(_defer_fini_, n): \
|
||||
return
|
||||
|
||||
#else /* !__GNUC__ && !__TINYCC__ */
|
||||
@@ -59,7 +60,7 @@ void foo(){
|
||||
#endif
|
||||
|
||||
#define Deferral(MAX_DEFER_STATEMENTS) \
|
||||
volatile unsigned char _num_deferrals = 0; \
|
||||
volatile int _num_deferrals = 0; \
|
||||
jmp_buf _defer_return_loc = {0}, _deferrals[MAX_DEFER_STATEMENTS] = {0};
|
||||
|
||||
#define Defer(block) do { \
|
||||
|
||||
@@ -26,13 +26,23 @@ typedef struct Error {
|
||||
List(ErrorCallPos) call_stack;
|
||||
} Error;
|
||||
|
||||
Error* Error_create(const char* msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
Error* Error_create(str msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
u16 error_code_page, u32 error_code);
|
||||
void Error_free(Error* e);
|
||||
void Error_addCallPos(Error* e, ErrorCallPos p);
|
||||
str Error_toStr(Error* e);
|
||||
void Error_printAndExit(Error* e) ATTRIBUTE_NORETURN;
|
||||
|
||||
/*
|
||||
Define in header, declare somewhere in source.
|
||||
Create a function like
|
||||
```
|
||||
void init_your_lib() {
|
||||
ErrorCodePage_register(YOUR_PAGE);
|
||||
}
|
||||
```
|
||||
and call it in main().
|
||||
*/
|
||||
#define ErrorCodePage_name(name) ErrorCodePage_##name
|
||||
#define ErrorCodePage_declare(name) extern u16 ErrorCodePage_name(name);
|
||||
#define ErrorCodePage_define(name) u16 ErrorCodePage_name(name) = 0;
|
||||
@@ -46,6 +56,7 @@ typedef enum TlibcError {
|
||||
ErrorCodePage_declare(TLIBC);
|
||||
ErrorCodePage_declare(LIBC_ERRNO);
|
||||
|
||||
|
||||
typedef struct Result_ {
|
||||
Error* error;
|
||||
union {
|
||||
@@ -62,8 +73,11 @@ typedef struct Result_ {
|
||||
/// Warning can be suppressed by IGNORE_RESULT
|
||||
#define Result(T) Result_ ATTRIBUTE_WARN_UNUSED_RESULT
|
||||
#define ResultVar(T) Result_
|
||||
|
||||
// for some stupid reason gcc requires more than 3 levels of macros to concat token with line number
|
||||
#define _ignore_var_name(N) CAT2(__ignored_, N)
|
||||
///USAGE: IGNORE_RESULT trySomething();
|
||||
#define IGNORE_RESULT Result_ __ignored_##__LINE__ ATTRIBUTE_UNUSED =
|
||||
#define IGNORE_RESULT Result_ _ignore_var_name(__LINE__) ATTRIBUTE_UNUSED =
|
||||
|
||||
|
||||
#define RESULT_ERROR_CODE(CODE_PAGE, CODE, MSG, IS_MSG_ON_HEAP) (Result_){ \
|
||||
@@ -72,74 +86,82 @@ typedef struct Result_ {
|
||||
.u = 0 \
|
||||
}
|
||||
#define RESULT_ERROR_CODE_FMT(CODE_PAGE, CODE, FORMAT, ARGS...) \
|
||||
RESULT_ERROR_CODE(CODE_PAGE, CODE, sprintf_malloc(FORMAT ,##ARGS), true)
|
||||
RESULT_ERROR_CODE(CODE_PAGE, CODE, str_from_cstr(sprintf_malloc(FORMAT ,##ARGS)), true)
|
||||
#define RESULT_ERROR(MSG, IS_MSG_ON_HEAP) \
|
||||
RESULT_ERROR_CODE(NONE, 0, MSG, IS_MSG_ON_HEAP);
|
||||
#define RESULT_ERROR_LITERAL(MSG) \
|
||||
RESULT_ERROR(STR((MSG)), false)
|
||||
#define RESULT_ERROR_FMT(FORMAT, ARGS...) \
|
||||
RESULT_ERROR_CODE_FMT(NONE, 0, FORMAT ,##ARGS)
|
||||
|
||||
#define RESULT_ERROR_ERRNO() \
|
||||
RESULT_ERROR_CODE(LIBC_ERRNO, errno, strerror_malloc(errno), true)
|
||||
RESULT_ERROR_CODE(LIBC_ERRNO, errno, str_from_cstr(strerror_malloc(errno)), true)
|
||||
|
||||
#define RESULT_VOID (Result_){ .error = NULL, .u = 0 }
|
||||
#define RESULT_VALUE(FIELD, V) (Result_){ .error = NULL, .FIELD = V }
|
||||
|
||||
#define try(VAR, RESULT_FIELD, RSLT_CALL) \
|
||||
_try(VAR, RESULT_FIELD, RSLT_CALL, __LINE__)
|
||||
#define try_void(RSLT_CALL) \
|
||||
_try_void(RSLT_CALL, __LINE__)
|
||||
#define try_fatal(VAR, RESULT_FIELD, RSLT_CALL) \
|
||||
_try_fatal(VAR, RESULT_FIELD, RSLT_CALL, __LINE__)
|
||||
#define try_fatal_void(RSLT_CALL) \
|
||||
_try_fatal_void(RSLT_CALL, __LINE__)
|
||||
#define try_handle(VAR, RESULT_FIELD, RSLT_CALL, HANDLER) \
|
||||
_try_handle(VAR, RESULT_FIELD, RSLT_CALL, HANDLER, __LINE__)
|
||||
#define try_handle_void(RSLT_CALL, HANDLER) \
|
||||
_try_handle_void(RSLT_CALL, HANDLER, __LINE__)
|
||||
#define try_stderrcode(RSLT_CALL) \
|
||||
_try_stderrcode(RSLT_CALL, __LINE__)
|
||||
#define try_fatal_stderrcode(RSLT_CALL) \
|
||||
_try_fatal_stderrcode(RSLT_CALL, __LINE__)
|
||||
|
||||
|
||||
#define _rname(N) __r_##N
|
||||
|
||||
#define try(VAR, RESULT_FIELD, RSLT_CALL) _try(VAR, RESULT_FIELD, RSLT_CALL, __LINE__)
|
||||
#define try_fatal(VAR, RESULT_FIELD, RSLT_CALL) _try_fatal(VAR, RESULT_FIELD, RSLT_CALL, __LINE__)
|
||||
#define try_void(RSLT_CALL) _try_void(RSLT_CALL, __LINE__)
|
||||
#define try_fatal_void(RSLT_CALL) _try_fatal_void(RSLT_CALL, __LINE__)
|
||||
#define try_stderrcode(RSLT_CALL) _try_stderrcode(RSLT_CALL, __LINE__)
|
||||
#define try_fatal_stderrcode(RSLT_CALL) _try_fatal_stderrcode(RSLT_CALL, __LINE__)
|
||||
#define _try_handle(VAR, RESULT_FIELD, RSLT_CALL, HANDLER, N) \
|
||||
Result_ _rname(N) = RSLT_CALL;\
|
||||
if(_rname(N).error){\
|
||||
Error_addCallPos(_rname(N).error, ErrorCallPos_here());\
|
||||
HANDLER(_rname(N));\
|
||||
}\
|
||||
VAR = _rname(N).RESULT_FIELD;
|
||||
|
||||
#define _try_handle_void(RSLT_CALL, HANDLER, N) \
|
||||
Result_ _rname(N) = RSLT_CALL;\
|
||||
if(_rname(N).error){\
|
||||
Error_addCallPos(_rname(N).error, ErrorCallPos_here());\
|
||||
HANDLER(_rname(N));\
|
||||
}\
|
||||
|
||||
|
||||
#define _try__handler(R) Return R
|
||||
#define _try(VAR, RESULT_FIELD, RSLT_CALL, N) \
|
||||
Result_ _rname(N) = RSLT_CALL;\
|
||||
if(_rname(N).error){\
|
||||
Error_addCallPos(_rname(N).error, ErrorCallPos_here());\
|
||||
Return _rname(N);\
|
||||
};\
|
||||
VAR = _rname(N).RESULT_FIELD;
|
||||
|
||||
#define _try_void(RSLT_CALL, N) do {\
|
||||
Result_ _rname(N) = RSLT_CALL;\
|
||||
if(_rname(N).error){\
|
||||
Error_addCallPos(_rname(N).error, ErrorCallPos_here());\
|
||||
Return _rname(N);\
|
||||
};\
|
||||
} while(0)
|
||||
_try_handle(VAR, RESULT_FIELD, RSLT_CALL, _try__handler, N)
|
||||
#define _try_void(RSLT_CALL, N) \
|
||||
_try_handle_void(RSLT_CALL, _try__handler, N)
|
||||
|
||||
#define _try_fatal__handler(R) Error_printAndExit(R.error)
|
||||
#define _try_fatal(VAR, RESULT_FIELD, RSLT_CALL, N) \
|
||||
Result_ _rname(N) = RSLT_CALL;\
|
||||
if(_rname(N).error){\
|
||||
Error_addCallPos(_rname(N).error, ErrorCallPos_here());\
|
||||
Error_printAndExit(_rname(N).error);\
|
||||
};\
|
||||
VAR = _rname(N).RESULT_FIELD;
|
||||
_try_handle(VAR, RESULT_FIELD, RSLT_CALL, _try_fatal__handler, N)
|
||||
#define _try_fatal_void(RSLT_CALL, N) \
|
||||
_try_handle_void(RSLT_CALL, _try_fatal__handler, N)
|
||||
|
||||
#define _try_fatal_void(RSLT_CALL, N) do {\
|
||||
Result_ _rname(N) = RSLT_CALL;\
|
||||
if(_rname(N).error){\
|
||||
Error_addCallPos(_rname(N).error, ErrorCallPos_here());\
|
||||
Error_printAndExit(_rname(N).error);\
|
||||
};\
|
||||
} while(0)
|
||||
|
||||
#define _try_stderrcode(CALL, N) do {\
|
||||
#define _try_stderrcode(CALL, N) \
|
||||
int _rname(N) = CALL;\
|
||||
if(_rname(N) != 0){\
|
||||
Return RESULT_ERROR_CODE(LIBC_ERRNO, _rname(N), strerror_malloc(_rname(N)), true);\
|
||||
Return RESULT_ERROR_CODE(LIBC_ERRNO, _rname(N), str_from_cstr(strerror_malloc(_rname(N))), true);\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
#define _try_fatal_stderrcode(CALL, N) do {\
|
||||
#define _try_fatal_stderrcode(CALL, N) \
|
||||
int _rname(N) = CALL;\
|
||||
if(_rname(N) != 0){\
|
||||
Error_printAndExit(Error_create(\
|
||||
strerror_malloc(_rname(N)), true, ErrorCallPos_here(), \
|
||||
str_from_cstr(strerror_malloc(_rname(N))), true, \
|
||||
ErrorCallPos_here(), \
|
||||
ErrorCodePage_name(LIBC_ERRNO), _rname(N)\
|
||||
));\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
#define try_assert(EXPR) if(!(EXPR)) { Return RESULT_ERROR(("try_assert(" #EXPR ")"), false); }
|
||||
#define try_assert(EXPR) if(!(EXPR)) { Return RESULT_ERROR_LITERAL("assertion must be true: " #EXPR); }
|
||||
|
||||
@@ -39,6 +39,8 @@ str path_dirname(str path);
|
||||
/// @return pointer to a segment of path.data or path itself if no path_sep has been found
|
||||
str path_basename(str path, bool remove_ext);
|
||||
|
||||
/// @return heap-allocated string
|
||||
Result(char*) path_getUserDir();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// FILE //
|
||||
@@ -133,16 +135,27 @@ static inline Result(void) file_readBytesArrayExactly(FILE* f, Array(u8) dst){
|
||||
return file_readStructsExactly(f, dst.data, 1, dst.len);
|
||||
}
|
||||
|
||||
/// @brief allocates array of size equal `file_getSize()` and reads whole file
|
||||
/// @brief allocates buffer of size `file_getSize(f)` and reads whole file
|
||||
/// @param out_buf output array allocated on heap
|
||||
Result(void) file_readWhole(FILE* f, Array(u8)* out_buf);
|
||||
|
||||
/// @brief allocates buffer of size `file_getSize(f) + 1` and reads whole file
|
||||
/// @param out_str output str allocated on heap, null-terminated
|
||||
Result(void) file_readWholeText(FILE* f, str* out_str);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DIRECTORY //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// @return true if directory exists or `path` is null or empty or '.' or './'
|
||||
bool dir_exists(cstr path);
|
||||
|
||||
/// @brief creates directories specified in path recursively
|
||||
/// EXAMPLE: dir_createParent("a/b/c") -> creates "a", "a/b", "a/b/c"
|
||||
/// @return false if directory was present already, true if it has been created
|
||||
Result(bool) dir_create(cstr path);
|
||||
|
||||
/// @brief creates directories except the last part of path
|
||||
/// EXAMPLE: dir_createParent("a/b/c") -> creates "a", "a/b"
|
||||
/// @return false if directory was present already, true if it has been created
|
||||
Result(bool) dir_createParent(cstr path);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -59,6 +59,8 @@ typedef void (*Destructor_t)(void* self);
|
||||
#define dbg(N) printf("\e[95m%d\n",N)
|
||||
|
||||
#define nameof(V) #V
|
||||
#define CAT2(a, b) a ## b
|
||||
#define CAT3(a, b, c) a ## b ## c
|
||||
|
||||
#define ARRAY_LEN(A) (sizeof(A)/sizeof(A[0]))
|
||||
#define ALIGN_TO(_SIZE,_ALIGN) (((_SIZE) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1))
|
||||
@@ -76,7 +78,7 @@ typedef void (*Destructor_t)(void* self);
|
||||
a48,a49,a50,a51,a52,a53,a54,a55, a56,a57,a58,a59,a60,a61,a62,a63, \
|
||||
a64,...) a64
|
||||
// Macro for counting variadic arguments (max 64)
|
||||
// (see usage in kprint.h)
|
||||
// (see usage in cptr.h)
|
||||
#define count_args(ARGS...) __count_args(ARGS, \
|
||||
64,63,62,61,60,59,58,57, 56,55,54,53,52,51,50,49, \
|
||||
48,47,46,45,44,43,42,41, 40,39,38,37,36,35,34,33, \
|
||||
@@ -85,6 +87,8 @@ typedef void (*Destructor_t)(void* self);
|
||||
|
||||
#define printfe(FORMAT, ...) fprintf(stderr, FORMAT ,##__VA_ARGS__)
|
||||
|
||||
#define zeroStruct(STRUCT_PTR) memset((STRUCT_PTR), 0, sizeof(*STRUCT_PTR));
|
||||
|
||||
/// @warning pointer can be null
|
||||
#define NULLABLE(NAME) NAME
|
||||
|
||||
@@ -120,6 +124,24 @@ typedef void (*Destructor_t)(void* self);
|
||||
#define ATTRIBUTE_THREAD_LOCAL __thread
|
||||
#endif
|
||||
|
||||
#if __cplusplus
|
||||
#ifdef _MSC_VER
|
||||
#define PRAGMA_WARNING_PUSH __pragma(warning( push ))
|
||||
#define PRAGMA_WARNING_POP __pragma(warning( pop ))
|
||||
#define PRAGMA_WARNING_DISABLE(wNumber) __pragma(warning( disable : wNumber ))
|
||||
#define W_RETURN_TYPE
|
||||
#else
|
||||
#define _PRAGMA(P) _Pragma(#P)
|
||||
#define PRAGMA_WARNING_PUSH _PRAGMA(GCC diagnostic push)
|
||||
#define PRAGMA_WARNING_POP _PRAGMA(GCC diagnostic pop)
|
||||
#define PRAGMA_WARNING_DISABLE(wName) _PRAGMA(GCC diagnostic ignored wName)
|
||||
#define W_RETURN_TYPE "-Wreturn-type"
|
||||
#endif
|
||||
#define WARNING_DISABLE(WARNING, CODE...) \
|
||||
PRAGMA_WARNING_PUSH \
|
||||
PRAGMA_WARNING_DISABLE(WARNING) \
|
||||
CODE; \
|
||||
PRAGMA_WARNING_POP
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -13,7 +13,13 @@ typedef struct str {
|
||||
bool isZeroTerminated;
|
||||
} str;
|
||||
|
||||
/*
|
||||
USAGE:
|
||||
str s = STR("something");
|
||||
printf(FMT_str"\n", str_unwrap(s));
|
||||
*/
|
||||
#define FMT_str "%.*s"
|
||||
#define str_unwrap(S) (S).len, (S).data
|
||||
|
||||
/// creates str from a string literal
|
||||
#define STR(LITERAL) str_construct(LITERAL, ARRAY_LEN(LITERAL) - 1, true)
|
||||
@@ -24,8 +30,17 @@ static inline str str_from_cstr(cstr s_ptr){
|
||||
return str_construct((void*)s_ptr, strlen(s_ptr), true);
|
||||
}
|
||||
|
||||
static inline void str_free(str s){
|
||||
free(s.data);
|
||||
/// destroy str with .data allocated on heap
|
||||
static inline void str_destroy(str self){
|
||||
free(self.data);
|
||||
}
|
||||
|
||||
/// destroy str allocated on heap with .data allocated on heap
|
||||
static inline void str_free(str* self){
|
||||
if(!self)
|
||||
return;
|
||||
free(self->data);
|
||||
free(self);
|
||||
}
|
||||
|
||||
static inline Array(char) str_castTo_Array_char(str s) {
|
||||
@@ -44,7 +59,7 @@ static inline str Array_u8_castTo_str(Array(u8) a, bool isZeroTerminated) {
|
||||
|
||||
static const str str_null = str_construct(NULL, 0, 0);
|
||||
|
||||
/// copies src content to new string and adds \0 at the end
|
||||
/// copy str data to new str and add \0 at the end
|
||||
str str_copy(const str self);
|
||||
|
||||
/// compares two strings, NullPtr-friendly
|
||||
|
||||
47
include/tlibc/term.h
Normal file
47
include/tlibc/term.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
|
||||
typedef struct TerminalSize {
|
||||
i16 cols;
|
||||
i16 rows;
|
||||
} TerminalSize;
|
||||
|
||||
typedef enum Color16 {
|
||||
Color16_Black = 30,
|
||||
Color16_DarkRed = 31,
|
||||
Color16_DarkGreen = 32,
|
||||
Color16_DarkYellow = 33,
|
||||
Color16_DarkBlue = 34,
|
||||
Color16_DarkMagenta = 35,
|
||||
Color16_DarkCyan = 36,
|
||||
Color16_Gray = 37,
|
||||
Color16_DarkGray = 90,
|
||||
Color16_Red = 91,
|
||||
Color16_Green = 92,
|
||||
Color16_Yellow = 93,
|
||||
Color16_Blue = 94,
|
||||
Color16_Magenta = 95,
|
||||
Color16_Cyan = 96,
|
||||
Color16_White = 97
|
||||
} Color16;
|
||||
|
||||
Result(void) term_init();
|
||||
Result(void) term_getSize(TerminalSize* out);
|
||||
|
||||
Result(void) term_readLine(char* buf, u32 bufsize);
|
||||
Result(void) term_readLineHidden(char *buf, u32 bufsize);
|
||||
|
||||
void term_setFgColor16(Color16 c);
|
||||
void term_setBgColor16(Color16 c);
|
||||
void term_bold();
|
||||
void term_italic();
|
||||
void term_underline();
|
||||
void term_strikethrough();
|
||||
void term_resetColors();
|
||||
|
||||
void term_clear();
|
||||
void term_eraseRow();
|
||||
void term_resetCursor();
|
||||
void term_cursorMove(u16 row, u16 column);
|
||||
void term_cursorHide();
|
||||
void term_cursorShow();
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "std.h"
|
||||
#include "errors.h"
|
||||
|
||||
/// nanoseconds
|
||||
typedef u64 nsec_t;
|
||||
@@ -52,10 +52,15 @@ void DateTime_get(DateTime* dt, bool utc_time);
|
||||
static inline void DateTime_getLocal(DateTime* dt) { DateTime_get(dt, false); }
|
||||
static inline void DateTime_getUTC(DateTime* dt) { DateTime_get(dt, true); }
|
||||
|
||||
// yyyy.MM.dd_HH-mm-ss
|
||||
/// yyyy.MM.dd HH:mm:ss_float
|
||||
Result(void) DateTime_parse(cstr src, DateTime* dt);
|
||||
|
||||
/// yyyy.MM.dd_HH-mm-ss
|
||||
#define FMT_DateTime_fileName "%04i.%02i.%02i_%02i-%02i-%02i"
|
||||
// yyyy.MM.dd HH:mm:ss
|
||||
#define FMT_DateTime_text "%04i.%02i.%02i %02i:%02i:%02i"
|
||||
/// yyyy.MM.dd HH:mm:ss
|
||||
/// yyyy.MM.dd HH:mm:ss_float
|
||||
#define FMT_DateTime_text "%04i.%02i.%02i-%02i:%02i:%02i"
|
||||
#define FMT_DateTime_text_subsec FMT_DateTime_text".%09i"
|
||||
/*
|
||||
USAGE:
|
||||
DateTime dt;
|
||||
@@ -63,8 +68,8 @@ USAGE:
|
||||
printf(FMT_DateTime_text, DT_expand(dt));
|
||||
*/
|
||||
#define DT_expand(dt) dt.d.year, dt.d.month, dt.d.month_day, dt.t.hour, dt.t.min, dt.t.sec
|
||||
#define DT_expand_subsec(dt) dt.d.year, dt.d.month, dt.d.month_day, dt.t.hour, dt.t.min, dt.t.sec, dt.t.nsec
|
||||
|
||||
|
||||
#if __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -43,7 +43,7 @@ case "$OS" in
|
||||
EXEC_FILE="$PROJECT.exe"
|
||||
SHARED_LIB_FILE="$PROJECT.dll"
|
||||
INCLUDE="$INCLUDE "
|
||||
LINKER_LIBS=""
|
||||
LINKER_LIBS="-luuid"
|
||||
;;
|
||||
LINUX)
|
||||
EXEC_FILE="$PROJECT"
|
||||
|
||||
@@ -225,6 +225,6 @@ bool HashMapIter_getCurrent(HashMapIter* self, HashMapKeyValue* kv){
|
||||
return false;
|
||||
|
||||
kv->key = bu->key_hash_list.data[self->elem_n].key;
|
||||
kv->value = (u8*)bu->value_list.data + self->map->value_t_size * self->elem_n;
|
||||
kv->value_ptr = (u8*)bu->value_list.data + self->map->value_t_size * self->elem_n;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#define ERRMSG_LENGTH 1024
|
||||
|
||||
Error* Error_create(const char* msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
Error* Error_create(str msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
u16 error_code_page, u32 error_code)
|
||||
{
|
||||
Error* e = (Error*)malloc(sizeof(Error));
|
||||
e->msg = str_construct((char*)(void*)msg, strlen(msg), true);
|
||||
e->msg = msg;
|
||||
e->is_msg_on_heap = is_msg_on_heap;
|
||||
e->error_code_page = error_code_page;
|
||||
e->error_code = error_code;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "internal.h"
|
||||
|
||||
bool dir_exists(cstr path){
|
||||
if(path == NULL || path[0] == 0)
|
||||
return true;
|
||||
|
||||
if(path[0]=='.'){
|
||||
if(path[1]==0 || (path[1]==path_sep && path[1]==0))
|
||||
return true; // dir . or ./ always exists
|
||||
@@ -23,13 +26,12 @@ bool dir_exists(cstr path){
|
||||
|
||||
Result(bool) dir_create(cstr path){
|
||||
Deferral(4);
|
||||
if (dir_exists(path)){
|
||||
|
||||
if (path == NULL || path[0] == 0 || dir_exists(path)){
|
||||
Return RESULT_VALUE(i, false);
|
||||
}
|
||||
|
||||
char* parentDir= str_copy(path_dirname(str_from_cstr((void*)path))).data;
|
||||
Defer(free(parentDir));
|
||||
try_void(dir_create(parentDir));
|
||||
try_void(dir_createParent(path));
|
||||
|
||||
#if TLIBC_FS_USE_WINDOWS_H
|
||||
if(!CreateDirectory(path, NULL))
|
||||
@@ -47,3 +49,18 @@ Result(bool) dir_create(cstr path){
|
||||
|
||||
Return RESULT_VALUE(i, true);
|
||||
}
|
||||
|
||||
Result(bool) dir_createParent(cstr path){
|
||||
Deferral(4);
|
||||
|
||||
str parent_dir_str = path_dirname(str_from_cstr((void*)path));
|
||||
if(parent_dir_str.len == 0){
|
||||
Return RESULT_VALUE(i, false);
|
||||
}
|
||||
|
||||
char* parent_dir_cstr = str_copy(parent_dir_str).data;
|
||||
Defer(free(parent_dir_cstr));
|
||||
|
||||
try(bool result, i, dir_create(parent_dir_cstr));
|
||||
Return RESULT_VALUE(i, result);
|
||||
}
|
||||
|
||||
@@ -142,10 +142,28 @@ Result(void) file_readWhole(FILE* f, Array(u8)* out_buf){
|
||||
|
||||
try(i64 f_size, i, file_getSize(f));
|
||||
Array(u8) buf = Array_u8_alloc(f_size);
|
||||
Defer(if(!success) free(buf.data));
|
||||
try_void(file_readBytesArray(f, buf));
|
||||
Defer(if(!success) Array_u8_destroy(&buf));
|
||||
|
||||
try_void(file_readBytesArrayExactly(f, buf));
|
||||
|
||||
*out_buf = buf;
|
||||
success = true;
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
Result(void) file_readWholeText(FILE* f, str* out_str){
|
||||
Deferral(1);
|
||||
bool success = false;
|
||||
|
||||
try(i64 f_size, i, file_getSize(f));
|
||||
Array(u8) buf = Array_u8_alloc(f_size + 1);
|
||||
Defer(if(!success) Array_u8_destroy(&buf));
|
||||
buf.len--;
|
||||
|
||||
try_void(file_readBytesArrayExactly(f, buf));
|
||||
buf.data[buf.len] = '\0';
|
||||
|
||||
*out_str = Array_u8_castTo_str(buf, true);
|
||||
success = true;
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
#include "tlibc/filesystem.h"
|
||||
#include "internal.h"
|
||||
|
||||
#if TLIBC_FS_USE_WINDOWS_H
|
||||
#include <knownfolders.h>
|
||||
#include <shlobj.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
str path_dirname(str path){
|
||||
if(path.len == 0)
|
||||
@@ -43,3 +49,23 @@ str path_basename(str path, bool remove_ext){
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
Result(char*) path_getUserDir(){
|
||||
#if TLIBC_FS_USE_WINDOWS_H
|
||||
PWSTR wpath = NULL;
|
||||
HRESULT reslut = SHGetKnownFolderPath(&FOLDERID_Profile, 0, NULL, &wpath);
|
||||
if(!SUCCEEDED(reslut)){
|
||||
return RESULT_ERROR_LITERAL("can't get user directory by SHGetKnownFolderPath()");
|
||||
}
|
||||
size_t char_len = wcslen(wpath) * 4 + 1;
|
||||
char* path = (char*)malloc(char_len);
|
||||
wcstombs(path, wpath, char_len);
|
||||
return RESULT_VALUE(p, path);
|
||||
#else
|
||||
const char *home = getenv("HOME");
|
||||
if(home == NULL){
|
||||
return RESULT_ERROR_LITERAL("can't get user directory by getenv(\"HOME\")");
|
||||
}
|
||||
return RESULT_VALUE(p, cstr_copy(home));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
#include "tlibc/string/StringBuilder.h"
|
||||
|
||||
str str_copy(const str self){
|
||||
if(self.data == NULL || self.len == 0)
|
||||
return self;
|
||||
|
||||
str copy = str_construct((char*)malloc(self.len + 1), self.len, true);
|
||||
memcpy(copy.data, self.data, self.len);
|
||||
if(self.len != 0){
|
||||
memcpy(copy.data, self.data, self.len);
|
||||
}
|
||||
copy.data[copy.len] = '\0';
|
||||
return copy;
|
||||
}
|
||||
|
||||
189
src/term.c
Normal file
189
src/term.c
Normal file
@@ -0,0 +1,189 @@
|
||||
#include "tlibc/term.h"
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#define try_win_bool(EXPR) if(!(EXPR)) { Return RESULT_ERROR_FMT(#EXPR " failed with WindowsError %lu", GetLastError()); }
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#define try_zero_errno(EXPR) if((EXPR) != 0) { \
|
||||
char* errno_s = strerror_malloc(errno); \
|
||||
ResultVar(void) err = RESULT_ERROR_FMT(#EXPR " failed with errno: %s", strerror(errno)); \
|
||||
free(errno_s); \
|
||||
Return err; \
|
||||
}
|
||||
#endif
|
||||
|
||||
Result(void) term_init(){
|
||||
Deferral(8);
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
DWORD mode = 0;
|
||||
HANDLE console_handle;
|
||||
|
||||
// configure stdout
|
||||
console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
try_assert(console_handle != INVALID_HANDLE_VALUE);
|
||||
GetConsoleMode(console_handle, &mode);
|
||||
// https://learn.microsoft.com/en-us/windows/console/setconsolemode
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
mode |= ENABLE_PROCESSED_OUTPUT;
|
||||
mode |= DISABLE_NEWLINE_AUTO_RETURN;
|
||||
SetConsoleMode(console_handle, mode);
|
||||
|
||||
// configure stderr
|
||||
console_handle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
try_assert(console_handle != INVALID_HANDLE_VALUE);
|
||||
GetConsoleMode(console_handle, &mode);
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
mode |= ENABLE_PROCESSED_OUTPUT;
|
||||
mode |= DISABLE_NEWLINE_AUTO_RETURN;
|
||||
SetConsoleMode(console_handle, mode);
|
||||
|
||||
// configure stdin
|
||||
console_handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
try_assert(console_handle != INVALID_HANDLE_VALUE);
|
||||
GetConsoleMode(console_handle, &mode);
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
||||
SetConsoleMode(console_handle, mode);
|
||||
#endif
|
||||
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
i64 getenv_int(const char* var_name){
|
||||
char* s = getenv(var_name);
|
||||
if(s == NULL)
|
||||
return -1;
|
||||
return strtoll(s, NULL, 0);
|
||||
}
|
||||
|
||||
Result(void) term_getSize(TerminalSize* out) {
|
||||
Deferral(4);
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
// helps when STD_OUT is redirected to a file
|
||||
HANDLE console_handle_stderr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
try_assert(console_handle_stderr != INVALID_HANDLE_VALUE)
|
||||
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
|
||||
try_win_bool(GetConsoleScreenBufferInfo(console_handle_stderr, &consoleInfo));
|
||||
|
||||
out->cols = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1;
|
||||
out->rows = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
|
||||
#else
|
||||
struct winsize ws = {0};
|
||||
// try to get terminal size from stdin, stdout, stderr
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == 0 ||
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 ||
|
||||
ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == 0 ){
|
||||
out->cols = ws.ws_col;
|
||||
out->rows = ws.ws_row;
|
||||
}
|
||||
// try to get size from environtent variables
|
||||
else {
|
||||
out->cols = getenv_int("COLUMNS");
|
||||
out->rows = getenv_int("LINES");
|
||||
}
|
||||
#endif
|
||||
|
||||
try_assert(out->cols > 0);
|
||||
try_assert(out->rows > 0);
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
Result(void) term_readLine(char* buf, u32 bufsize) {
|
||||
Deferral(1);
|
||||
if(fgets(buf, bufsize, stdin) == NULL){
|
||||
try_stderrcode(ferror(stdin));
|
||||
}
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
Result(void) term_readLineHidden(char *buf, u32 bufsize) {
|
||||
Deferral(4);
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
HANDLE console_handle_stdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
try_assert(console_handle_stdin != INVALID_HANDLE_VALUE);
|
||||
DWORD old_mode;
|
||||
GetConsoleMode(console_handle_stdin, &old_mode);
|
||||
// turn off echo
|
||||
DWORD new_mode = old_mode & ~(ENABLE_ECHO_INPUT);
|
||||
SetConsoleMode(console_handle_stdin, new_mode);
|
||||
// restore echo
|
||||
Defer(SetConsoleMode(console_handle_stdin, old_mode));
|
||||
#else
|
||||
struct termios old_mode, new_mode;
|
||||
try_zero_errno(tcgetattr(STDIN_FILENO, &old_mode));
|
||||
new_mode = old_mode;
|
||||
// turn off echo
|
||||
new_mode.c_lflag &= ~(ECHO);
|
||||
try_zero_errno(tcsetattr(STDIN_FILENO, TCSAFLUSH, &new_mode));
|
||||
// restore echo
|
||||
Defer(tcsetattr(STDIN_FILENO, TCSAFLUSH, &old_mode));
|
||||
#endif
|
||||
// read line
|
||||
try_void(term_readLine(buf, bufsize));
|
||||
fputc('\n', stdout);
|
||||
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
/*
|
||||
Most of escape sequences can be found there
|
||||
https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
|
||||
*/
|
||||
#define ESC "\x1b"
|
||||
#define CSI ESC"["
|
||||
|
||||
void term_setFgColor16(Color16 c){
|
||||
printf(CSI"%um", c);
|
||||
}
|
||||
|
||||
void term_setBgColor16(Color16 c){
|
||||
printf(CSI"%um", c + 10);
|
||||
}
|
||||
|
||||
void term_bold(){
|
||||
printf(CSI"1m");
|
||||
}
|
||||
|
||||
void term_italic(){
|
||||
printf(CSI"3m");
|
||||
}
|
||||
|
||||
void term_underline(){
|
||||
printf(CSI"4m");
|
||||
}
|
||||
|
||||
void term_strikethrough(){
|
||||
printf(CSI"9m");
|
||||
}
|
||||
|
||||
void term_resetCursor() {
|
||||
printf(CSI"H");
|
||||
}
|
||||
|
||||
void term_resetColors() {
|
||||
printf(CSI"0m");
|
||||
}
|
||||
|
||||
void term_clear() {
|
||||
printf(CSI"0m" CSI"H" CSI"2J");
|
||||
}
|
||||
|
||||
void term_eraseRow(){
|
||||
printf(CSI"2K\r");
|
||||
}
|
||||
|
||||
void term_cursorMove(u16 row, u16 column) {
|
||||
printf(CSI"%u;%uH", row, column);
|
||||
}
|
||||
|
||||
void term_cursorHide() {
|
||||
printf(CSI"?25l");
|
||||
}
|
||||
|
||||
void term_cursorShow() {
|
||||
printf(CSI"?25h");
|
||||
}
|
||||
14
src/time.c
14
src/time.c
@@ -71,3 +71,17 @@ void DateTime_get(DateTime* dt, bool utc_time){
|
||||
dt->d.week_day = c_tm.tm_wday + 1;
|
||||
dt->d.year_day = c_tm.tm_yday + 1;
|
||||
}
|
||||
|
||||
Result(void) DateTime_parse(cstr src, DateTime* dt){
|
||||
zeroStruct(dt);
|
||||
f64 sec_f = 0;
|
||||
i32 r = sscanf(src, "%"SCNi16".%"SCNi8".%"SCNi8"-%"SCNi8":%"SCNi8":%lf",
|
||||
&dt->d.year, &dt->d.month, &dt->d.month_day,
|
||||
&dt->t.hour, &dt->t.min, &sec_f);
|
||||
if(r != 6){
|
||||
return RESULT_ERROR_FMT("attepmted to parse DateTime, got %i fields out of 6", r);
|
||||
}
|
||||
dt->t.sec = (i32)sec_f;
|
||||
dt->t.nsec = (sec_f - (i32)sec_f) * 1e9;
|
||||
return RESULT_VOID;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user