many things, cosmo build!

This commit is contained in:
veclavtlica
2026-10-12 21:12:47 +03:00
parent ba4131abbf
commit 8d2bb5575e
29 changed files with 699 additions and 312 deletions
+13 -8
View File
@@ -1,7 +1,9 @@
#include "../std.h"
#include "../str.h"
#include "any.c"
#include <assert.h>
#include <poll.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
@@ -11,13 +13,7 @@
void *com_std_alloc(void *ptr, size_t size) {
return size != 0 ? realloc(ptr, size) : (free(ptr), NULL);
}
void com_std_assert(bool holds) { assert(holds); }
void com_std_printf(char const *fmt, ...) {
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}
double com_std_sqrt(double v) { return sqrt(v); }
double com_std_fabs(double v) { return fabs(v); }
double com_std_sin(double v) { return sin(v); }
@@ -43,6 +39,15 @@ int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto) {
return fread(data, 1, upto, fd);
}
bool com_std_has_data(com_std_fd fd) {
struct pollfd pfd = {.fd = (intptr_t)fd, .events = POLLIN};
int ret = poll(&pfd, 1, 0);
if (ret > 0) {
return pfd.revents & POLLIN;
} else
return false;
}
bool com_std_sfwd(com_std_fd fd, uint32_t bytes) {
com_std_assert(fd != NULL && bytes != 0);
return fseek(fd, bytes, SEEK_CUR) == 0;