From 73c2b00a10c5786ddeeacc915e233fd4df1c9321 Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Sat, 11 Oct 2025 22:19:00 +0200 Subject: fix: evalexpr & tinyprintf contenaient toute la piscine --- .../tinylibstream/stdin_buffering_test.c | 70 ---------------------- 1 file changed, 70 deletions(-) delete mode 100644 rushs/tinyprintf/tinylibstream/stdin_buffering_test.c (limited to 'rushs/tinyprintf/tinylibstream/stdin_buffering_test.c') diff --git a/rushs/tinyprintf/tinylibstream/stdin_buffering_test.c b/rushs/tinyprintf/tinylibstream/stdin_buffering_test.c deleted file mode 100644 index 6d3361b..0000000 --- a/rushs/tinyprintf/tinylibstream/stdin_buffering_test.c +++ /dev/null @@ -1,70 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include - -struct slow_cookie -{ - int fd; -}; - -static ssize_t slow_read(void *vcookie, char *buf, size_t count) -{ - struct slow_cookie *cookie = vcookie; - usleep(500000); // sleep for half of a second - - ssize_t res; - - while ((res = read(cookie->fd, buf, count)) < 0) - if (errno != EINTR && errno != EAGAIN) - break; - - return res; -} - -static int slow_close(void *vcookie) -{ - struct slow_cookie *cookie = vcookie; - return close(cookie->fd); -} - -cookie_io_functions_t slow_stdio = { - .read = slow_read, - .close = slow_close, -}; - -int main(void) -{ - /* setup a custom stdin stream with a slow read function */ - struct slow_cookie cookie = { - .fd = STDIN_FILENO, - }; - - FILE *input_stream = fopencookie(&cookie, "r", slow_stdio); - - /* change the buffer size to the one given by stdbuf. - ** it doesn't work out of the box as stdbuf only does - ** this for the already existing stdin stream. - */ - char *buffer = NULL; - char *buffer_size = getenv("_STDBUF_I"); - if (buffer_size) - { - size_t size = atoi(buffer_size); - buffer = malloc(size); - setvbuf(input_stream, buffer, _IOFBF, size); - } - - /* forward all characters from stdin to stdout */ - int c; - while ((c = fgetc(input_stream)) != EOF) - { - fputc(c, stdout); - fflush(stdout); - } - - fclose(input_stream); - free(buffer); - return 0; -} -- cgit v1.2.3