flushpl

LD_PRELOAD hook to force fflush
git clone https://git.sinitax.com/sinitax/flushpl
Log | Files | Refs | LICENSE | sfeed.txt

commit c6f5d448602986029227a230e30cc3d9060bdb9a
parent cb7abaeb03fcc46fa6b3e7f88be8518fd14de4e9
Author: Louis Burda <quent.burda@gmail.com>
Date:   Fri, 23 Jun 2023 00:14:55 +0200

Add MIT license

Diffstat:
ALICENSE | 21+++++++++++++++++++++
MMakefile | 5+++--
Dflush.c | 23-----------------------
Amain.c | 22++++++++++++++++++++++
4 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Louis Burda + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile @@ -1,4 +1,5 @@ -CFLAGS = -nostartfiles -fPIC -shared --std=gnu99 +CFLAGS = -Wunused-variable -Wunused-function -Wconversion +CFLAGS += -nostartfiles -fPIC -shared --std=c99 -O2 LDLIBS = -ldl all: flush.so @@ -6,7 +7,7 @@ all: flush.so clean: rm -f flush.so -flush.so: flush.c +fflush.so: main.c $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) .PHONY: all clean diff --git a/flush.c b/flush.c @@ -1,23 +0,0 @@ -#include <dlfcn.h> - -#include <stdlib.h> -#include <stdio.h> - -size_t -fwrite(const void *src, size_t size, size_t count, FILE *file) -{ - static size_t (*func)(const void *, size_t, size_t, FILE *) = NULL; - static void *libc = NULL; - size_t ret; - - if (!libc) libc = dlopen("libc.so.6", RTLD_GLOBAL | RTLD_LAZY); - if (!func) func = dlsym(libc, "fwrite"); - - if (!libc || !func) exit(1); - - ret = (*func)(src, size, count, file); - fflush(file); - - return ret; -} - diff --git a/main.c b/main.c @@ -0,0 +1,22 @@ +#include <dlfcn.h> + +#include <stdlib.h> +#include <stdio.h> + +size_t +fwrite(const void *src, size_t size, size_t count, FILE *file) +{ + static size_t (*func)(const void *, size_t, size_t, FILE *) = NULL; + static void *libc = NULL; + size_t ret; + + if (!libc) libc = dlopen("libc.so.6", RTLD_GLOBAL | RTLD_LAZY); + if (libc && !func) func = dlsym(libc, "fwrite"); + if (!libc || !func) exit(1); + + ret = (*func)(src, size, count, file); + fflush(file); + + return ret; +} +