refactor(build): add static_library

This commit is contained in:
2025-09-12 01:43:26 +02:00
parent 25e259ae07
commit 56fa31d087
13 changed files with 349 additions and 152 deletions

39
socket/mysocket.c Normal file
View File

@@ -0,0 +1,39 @@
#include "mysocket.h"
#include <winsock2.h>
int sock_platform_init() {
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
return -1;
}
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
WSACleanup();
return -1;
}
#endif
return 0;
}
int sock_close(int socket) {
int ret = 0;
#ifdef _WIN32
ret = closesocket(socket);
#else
ret = close(socket);
#endif
return ret;
}
int sock_platform_shutdown() {
#ifdef _WIN32
WSACleanup();
#endif
return 0;
}

27
socket/mysocket.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef MYCLIB_SOCKET_H
#define MYCLIB_SOCKET_H
#ifdef _WIN32
/* Windows */
#include <winsock2.h>
#include <ws2tcpip.h>
#else
/* Unix */
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#endif
/* Run this before everything */
int sock_platform_init();
/* Use this to close a socket */
int sock_close(int socket);
/* Use at exit */
int sock_platform_shutdown();
#endif