diff options
author | axtloss <axtlos@getcryst.al> | 2024-06-23 03:39:42 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-06-23 03:39:42 +0200 |
commit | fa4666ae07fb7525aa8e84aacf906bc8cb398a6a (patch) | |
tree | e5d1f8b8f3da397c1be313119bb1061bdcadd2d7 /src/extlib.c | |
download | extlib-fa4666ae07fb7525aa8e84aacf906bc8cb398a6a.tar.gz extlib-fa4666ae07fb7525aa8e84aacf906bc8cb398a6a.tar.bz2 |
Add base extlib
Diffstat (limited to 'src/extlib.c')
-rw-r--r-- | src/extlib.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/extlib.c b/src/extlib.c new file mode 100644 index 0000000..ee20d3e --- /dev/null +++ b/src/extlib.c @@ -0,0 +1,58 @@ +/* extlib.c + * + * Copyright 2024 axtlos <axtlos@disroot.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: LGPL-3.0-only + */ + +#include "extlib.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#undef free +#undef malloc + +void +free_secure(void *__ptr, size_t ptrlen) +{ + memset (__ptr, 0, ptrlen); + free (__ptr); + return; +} + +void * +malloc_secure (size_t len) +{ + void *mem = malloc (len); + memset (mem, 0, len); + return mem; +} + +void +fcopy(FILE *f1, FILE *f2) +{ + char buffer[BUFSIZ]; + size_t n; + + while ((n = fread (buffer, sizeof (char), sizeof (buffer), f1)) > 0) + { + if (fwrite (buffer, sizeof (char), n, f2) != n) { + fprintf (stderr, "Failed to copy data"); + return; + } + } +} |