This commit is contained in:
2026-09-24 15:30:45 -03:00
commit a5af824c91
306 changed files with 58603 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
#ifndef DIR_H
#define DIR_H
#if defined(_WIN32)
#define WIN32_LEARN_AND_MEAN
#include <direct.h>
#define mkdir(dir, mode) _mkdir(dir)
#elif defined(__unix) || defined(__unix__)
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
#endif
#endif
+35
View File
@@ -0,0 +1,35 @@
#ifndef SOCKET_H
#define SOCKET_H
#if defined(__unix) || defined(__unix__)
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#define SockError(signature) strncpy(signature, strerror(errno), 256)
#define Poll poll
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <mstcpip.h>
#include <io.h>
#include <errno.h>
#define close closesocket
#define SockError(signature) FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK , 0, WSAGetLastError(), 0, signature, 256, 0);
#define Poll WSAPoll
#define MSG_NOSIGNAL 0
typedef int socklen_t;
#endif
#endif
+55
View File
@@ -0,0 +1,55 @@
#ifndef THREADS_H
#define THREADS_H
#if defined(__unix) || defined(__unix__)
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <sched.h>
typedef pthread_t Thread;
typedef pthread_key_t ThreadVar;
typedef void* (*pthread_cbfunc_t) (void*);
#define ThreadVarCreate(var) pthread_key_create(&var, NULL)
#define ThreadVarSet(var, value) pthread_setspecific(var, value)
#define ThreadVarGet(var) pthread_getspecific(var)
#define ThreadVarFree(var) pthread_key_delete(var)
#define ThreadSpawn(thr, cb, arg) \
RAssert(pthread_create(&thr, NULL, (pthread_cbfunc_t)(cb), (arg)) == 0)
#define ThreadJoin(thr) pthread_join(thr, NULL)
#define ThreadSleep(ms) { struct timespec ts;\
ts.tv_sec = ms / 1000;\
ts.tv_nsec = (ms % 1000) * 1000000;\
nanosleep(&ts, NULL); }
typedef pthread_mutex_t Mutex;
#define MutexCreate(mut) RAssert(pthread_mutex_init(&mut, NULL) == 0)
#define MutexLock(mut) RAssert(pthread_mutex_lock(&mut) == 0)
#define MutexUnlock(mut) RAssert(pthread_mutex_unlock(&mut) == 0)
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef HANDLE Thread;
typedef DWORD ThreadVar;
#define ThreadVarCreate(var) RAssert((var = TlsAlloc()) != TLS_OUT_OF_INDEXES)
#define ThreadVarGet(var) TlsGetValue(var)
#define ThreadVarSet(var, value) TlsSetValue(var, value)
#define ThreadVarFree(var) TlsFree(var)
#define ThreadSpawn(thr, cb, arg) (thr = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(cb), (arg), 0, NULL))
#define ThreadJoin(thr) WaitForSingleObject(thr, INFINITE)
#define ThreadSleep(ms) Sleep(ms)
typedef HANDLE Mutex;
#define MutexCreate(mut) (mut = CreateMutex(NULL, FALSE, NULL))
#define MutexLock(mut) RAssert(WaitForSingleObject(mut, INFINITE) == WAIT_OBJECT_0)
#define MutexUnlock(mut) RAssert(ReleaseMutex(mut))
#endif
extern ThreadVar g_threadName;
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef TIME_H
#define TIME_H
#include <stdint.h>
#include <time.h>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
typedef double TimeStamp;
void time_init(void);
void time_start (TimeStamp* timer);
double time_end (TimeStamp* timer);
#endif