184184#if defined(_WIN32 ) || defined(_WIN64 ) || defined(__TINYC__ )
185185// On Windows the dispatch macros pass values directly (not pointer-to-value).
186186// va_arg(vl,void*) would read the value itself, so use PTR arithmetic instead.
187- #define __cstl_va_start (V ,C ,beg ) va_start(V,C);beg=V;
187+ #define __cstl_va_start (V ,C ,beg ) va_start(V,C);beg=(void*) V;
188188#define __cstl_va_arg (PTR ) (PTR)
189189// Windows: __cstl_va_arg_next is unused (Windows uses PTR-based path),
190190// but define it to avoid compile errors if referenced.
@@ -3135,6 +3135,31 @@ OPENCSTL_FUNC void __cstl_hashtable_free(void **container) {
31353135/* ////////////////////////////////////////////////////////////////////////////// */
31363136
31373137
3138+ /* ////////////////////////////////////////////////////////////////////////////// */
3139+ /* BEGIN algorithm.h (depth 1) */
3140+ /* ////////////////////////////////////////////////////////////////////////////// */
3141+
3142+ //
3143+ // Created by spring on 2026. 4. 9..
3144+ //
3145+
3146+ #if !defined(_OPENCSTL_C_ALGORITHM_H )
3147+ #define _OPENCSTL_C_ALGORITHM_H
3148+ #ifndef MAX
3149+ #define MAX (a ,b ) ((a)>(b)?(a):(b))
3150+ #endif
3151+ #ifndef MIN
3152+ #define MIN (a ,b ) ((a)<(b)?(a):(b))
3153+ #endif
3154+
3155+
3156+ #endif //_OPENCSTL_C_ALGORITHM_H
3157+
3158+ /* ////////////////////////////////////////////////////////////////////////////// */
3159+ /* END algorithm.h */
3160+ /* ////////////////////////////////////////////////////////////////////////////// */
3161+
3162+
31383163/* ////////////////////////////////////////////////////////////////////////////// */
31393164/* BEGIN cstl_compare.h (depth 1) */
31403165/* ////////////////////////////////////////////////////////////////////////////// */
@@ -3344,8 +3369,11 @@ CompareFunc CSTL_GREATER(const char *type_str) {
33443369#include <limits.h>
33453370#define CSTL_RAND64_MAX ULLONG_MAX
33463371#define CSTL_RAND32_MAX UINT_MAX
3347- static unsigned long long _seed64 = 1 ;
3348- static unsigned long _seed32 = 1 ;
3372+ static unsigned __int128 _seed64 = 1 ;
3373+ static unsigned long long _seed32 = 1 ;
3374+
3375+ //static unsigned long long _seed64 = 1;
3376+ //static unsigned int _seed32 = 1;
33493377
33503378static void cstl_rand_seed32 (unsigned int seed ) {
33513379 _seed32 = seed ;
@@ -3362,7 +3390,7 @@ static void cstl_rand_seed64(unsigned long long seed) {
33623390
33633391static unsigned long long cstl_rand64 () {
33643392 _seed64 = (_seed64 * 6364136223846793005ULL ) + 1442695040888963407ULL ;
3365- return _seed64 ;
3393+ return ( unsigned long long ) _seed64 ;
33663394}
33673395
33683396
@@ -3383,8 +3411,36 @@ static unsigned long long cstl_rand64() {
33833411#if !defined(_OPENCSTL_CSTL_TIME_H )
33843412#define _OPENCSTL_CSTL_TIME_H
33853413
3414+ #if defined(_WIN32 ) || defined(_WIN64 ) || defined(_MSC_VER )
3415+
3416+ #include <windows.h>
3417+ #include <stdio.h>
3418+
3419+ typedef LARGE_INTEGER watch ;
3420+
3421+ static watch tick () {
3422+ watch t ;
3423+ QueryPerformanceCounter (& t );
3424+ return t ;
3425+ }
3426+
3427+ static double lap (const watch t_beg , const watch t_end ) {
3428+ LARGE_INTEGER freq ;
3429+ QueryPerformanceFrequency (& freq );
3430+ return (double ) (t_end .QuadPart - t_beg .QuadPart ) * 1000.0 / (double ) freq .QuadPart ;
3431+ }
3432+
3433+ static void yyyy_mm_dd_hh_mm_ss_ms (char * timestr ) {
3434+ SYSTEMTIME st ;
3435+ GetLocalTime (& st );
3436+ snprintf (timestr , 32 , "%04d_%02d_%02d_%02d_%02d_%02d_%03d" ,
3437+ (int ) st .wYear , (int ) st .wMonth , (int ) st .wDay ,
3438+ (int ) st .wHour , (int ) st .wMinute , (int ) st .wSecond ,
3439+ (int ) st .wMilliseconds );
3440+ }
3441+
3442+ #elif defined(__MINGW32__ ) || defined(__MINGW64__ ) || defined(__GNUC__ ) || defined(__TINYC__ )
33863443
3387- #if defined(__MINGW32__ ) || defined(__MINGW64__ ) || defined(__GNUC__ )
33883444#include <stdio.h>
33893445#include <sys/time.h>
33903446#include <time.h>
@@ -3409,66 +3465,23 @@ static void yyyy_mm_dd_hh_mm_ss_ms(char *timestr) {
34093465 time_t now = tv .tv_sec ;
34103466 struct tm tm_now ;
34113467#if defined(__MINGW32__ ) || defined(__MINGW64__ )
3412- localtime_s (& tm_now , & now );
3413- #elif defined(__clang__ ) || (defined(__GNUC__ ) && defined(__APPLE__ )) || defined(__GNUC__ ) | defined(__TINYC__ )
3414- localtime_r (& now , & tm_now );
3468+ localtime_s (& tm_now , & now );
34153469#else
3416- localtime_s ( & tm_now , & now );
3470+ localtime_r ( & now , & tm_now );
34173471#endif
3418- int ms = (int ) (tv .tv_usec / 1000 );
3419-
3420- snprintf (timestr , 32 , "%04d_%02d_%02d_%02d_%02d_%02d_%03d" ,
3421- tm_now .tm_year + 1900 ,
3422- tm_now .tm_mon + 1 ,
3423- tm_now .tm_mday ,
3424- tm_now .tm_hour ,
3425- tm_now .tm_min ,
3426- tm_now .tm_sec ,
3427- ms );
3428- }
3429-
3430- #elif defined(_WIN32 ) || defined(_WIN64 ) || defined(_MSC_VER ) // MSVC, clang-cl
3431-
3432- #include <windows.h>
3433- #include <stdio.h>
3434-
3435- typedef LARGE_INTEGER watch ;
34363472
3437- static watch tick () {
3438- watch t ;
3439- QueryPerformanceCounter (& t );
3440- return t ;
3441- }
3442-
3443- static double lap (const watch t_beg , const watch t_end ) {
3444- LARGE_INTEGER freq ;
3445- QueryPerformanceFrequency (& freq );
3446-
3447- return (double ) (t_end .QuadPart - t_beg .QuadPart ) * 1000.0 / (double ) freq .QuadPart ;
3448- }
3449-
3450- static void yyyy_mm_dd_hh_mm_ss_ms (char * timestr ) {
3451- SYSTEMTIME st ;
3452- GetLocalTime (& st );
3453-
3454- snprintf (timestr , 32 , "%04d_%02d_%02d_%02d_%02d_%02d_%03d" ,
3455- (int ) st .wYear ,
3456- (int ) st .wMonth ,
3457- (int ) st .wDay ,
3458- (int ) st .wHour ,
3459- (int ) st .wMinute ,
3460- (int ) st .wSecond ,
3461- (int ) st .wMilliseconds );
3473+ int ms = (int ) (tv .tv_usec / 1000 );
3474+ snprintf (timestr , 32 , "%04d_%02d_%02d_%02d_%02d_%02d_%03d" ,
3475+ tm_now .tm_year + 1900 , tm_now .tm_mon + 1 , tm_now .tm_mday ,
3476+ tm_now .tm_hour , tm_now .tm_min , tm_now .tm_sec ,
3477+ ms );
34623478}
34633479
34643480#else
3465-
34663481#error Unsupported compiler/platform
3467-
34683482#endif
34693483
3470-
3471- #endif //_OPENCSTL_CSTL_TIME_H
3484+ #endif
34723485
34733486/* ////////////////////////////////////////////////////////////////////////////// */
34743487/* END cstl_time.h */
@@ -3491,14 +3504,10 @@ static void yyyy_mm_dd_hh_mm_ss_ms(char *timestr) {
34913504bool cstl_fopen (FILE * * fp , const char * filename , const char * mode ) {
34923505#if defined(_WIN32 ) || defined(_WIN64 )
34933506 fopen_s (fp , filename , mode );
3494- #elif defined(__linux__ ) && defined(__GNUC__ )
3495- * fp = fopen (filename , mode );
3496- #elif defined(__APPLE__ )
3497- * fp = fopen (filename , mode );
34983507#else
3499- fopen_s ( fp , filename , mode );
3508+ * fp = fopen ( filename , mode );
35003509#endif
3501- return fp != NULL ;
3510+ return * fp != NULL ;
35023511}
35033512
35043513bool cstl_getline (FILE * fp , char * line , size_t size ) {
@@ -3730,10 +3739,10 @@ static void msort(void *base, size_t nmemb, size_t size, int (*compar)(const voi
37303739#if !defined(_OPENCSTL_VERSION_H )
37313740#define _OPENCSTL_VERSION_H
37323741
3733- static char * VERSION = "1.0.0" ;
3742+ static char * OPENCSTL_VERSION = "1.0.0" ;
37343743
3735- static char * get_version () {
3736- return VERSION ;
3744+ static char * opencstl_version () {
3745+ return OPENCSTL_VERSION ;
37373746}
37383747#endif //_OPENCSTL_VERSION_H
37393748
0 commit comments