fix: using file descriptors instead of FILE*

we can directly write to a socket using dprintf, no need for a buffer
This commit is contained in:
2024-01-20 17:53:36 +01:00
parent b4560bd748
commit 8880fae4aa
11 changed files with 75 additions and 97 deletions

View File

@@ -11,18 +11,18 @@ void api_put() {
int mode = state->STACK[state->STACK_IDX--]; // 1 for char, 2 for num
if (mode != 1 && mode != 2) return;
FILE *f = fstream;
if (f == stderr)
f = stdout;
int f = fstream;
if (f == fileno(stderr))
f = fileno(stdout);
if (mode == 1) {
char c = state->STACK[state->STACK_IDX--];
if (c == '\0') c = ' ';
fprintf(f, "%c", c); //using printf and not write because of the buffer
dprintf(f, "%c", c); //using printf and not write because of the buffer
}
else {
fprintf(f, "%d", state->STACK[state->STACK_IDX--]);
dprintf(f, "%d", state->STACK[state->STACK_IDX--]);
}
}