revb

Byte-wise data-stream reverser
git clone https://git.sinitax.com/sinitax/revb
Log | Files | Refs | LICENSE | sfeed.txt

commit fc1ea8d4b498e21d5248b5f1a62337dfe3013e1a
parent 7c5179b792a8504564131d08692a838c5a019749
Author: Louis Burda <quent.burda@gmail.com>
Date:   Thu, 22 Jun 2023 22:39:22 +0200

Add MIT license and warning flags

Diffstat:
ALICENSE | 21+++++++++++++++++++++
MMakefile | 8+++++++-
Mrevb.c | 20++++++++------------
3 files changed, 36 insertions(+), 13 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,7 +1,13 @@ PREFIX ?= /usr/local BINDIR ?= /bin -CFLAGS = -g +CFLAGS = -Wunused-variable -Wunused-function -Wconversion + +ifeq ($(DEBUG),1) +CFLAGS += -Og -g +else +CFLAGS += -O2 +endif all: revb diff --git a/revb.c b/revb.c @@ -5,29 +5,25 @@ #include <stdint.h> #include <stdlib.h> -#define CHUNKSIZE 4096 - -uint8_t * -load(FILE *file, uint8_t *data, ssize_t *datalen) +static uint8_t * +load(FILE *file, uint8_t *data, size_t *datalen) { - ssize_t cap, len; - ssize_t nread; - int ret; + size_t cap, len, nread; len = *datalen; - cap = len + CHUNKSIZE; + cap = len + BUFSIZ; data = realloc(data, cap); if (!data) err(1, "realloc"); while (1) { - if (len + CHUNKSIZE > cap) { + if (len + BUFSIZ > cap) { cap *= 2; data = realloc(data, cap); if (!data) err(1, "realloc"); } - nread = fread(data + len, 1, CHUNKSIZE, file); - if (nread <= 0) break; + nread = fread(data + len, 1, BUFSIZ, file); + if (!nread) break; len += nread; } @@ -41,7 +37,7 @@ int main(int argc, const char **argv) { uint8_t *data, tmp; - ssize_t a, b, len; + size_t a, b, len; FILE *file; int i;