diff options
author | axtloss <axtlos@getcryst.al> | 2024-07-13 13:32:53 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-07-14 16:43:24 +0200 |
commit | 1a4696492e3cd478080e438950a7664a68fefcd6 (patch) | |
tree | 3b6e6658d5d56d3a28c6c83a8c6b64cffaa27555 | |
parent | 3e85fcb0270c9224ab95dac02c737e6676974c8e (diff) | |
download | extlib-1a4696492e3cd478080e438950a7664a68fefcd6.tar.gz extlib-1a4696492e3cd478080e438950a7664a68fefcd6.tar.bz2 |
Add manpages for each extlib function
-rw-r--r-- | COPYING | 193 | ||||
-rw-r--r-- | doc/fcopy.3 | 75 | ||||
-rw-r--r-- | doc/memset_s.3 | 51 | ||||
-rw-r--r-- | doc/memvcmp.3 | 32 | ||||
-rw-r--r-- | doc/replace_str.3 | 34 | ||||
-rw-r--r-- | doc/rrmdir.3 | 33 | ||||
-rw-r--r-- | doc/set_constraint_handler_s.3 | 147 | ||||
-rw-r--r-- | doc/strlwr.3 | 41 | ||||
-rw-r--r-- | doc/strupr.3 | 41 | ||||
-rw-r--r-- | doc/trim.3 | 40 | ||||
-rw-r--r-- | src/constraint_handler.c | 17 | ||||
-rw-r--r-- | src/extlib.c | 15 | ||||
-rw-r--r-- | src/extlib.h | 26 | ||||
-rw-r--r-- | src/extstring.c | 17 | ||||
-rw-r--r-- | src/memset_s.c | 18 |
15 files changed, 541 insertions, 239 deletions
@@ -1,165 +1,28 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. +BSD 3-Clause License + +Copyright (c) 2024, axtlos <axtlos@disroot.org> + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/doc/fcopy.3 b/doc/fcopy.3 new file mode 100644 index 0000000..5096fe4 --- /dev/null +++ b/doc/fcopy.3 @@ -0,0 +1,75 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH fcopy 3 2024-07-13 "extlib" +.SH NAME +fcopy \- copy a file +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #include <extlib.h> +.P +.BI "size_t fcopy(FILE *src, FILE *dst);" +.fi +.SH DESCRIPTION +If +.I *src +or +.I *dst +is NULL, the +.BR fcopy () +function will return -1 and do nothing else. +Otherwise, this function copies the contents +of +.I *src +to +.IR *dst . +.fi +.SH RETURN VALUE +The +.BR fcopy () +function returns the amount of bytes copied from +.I *src +to +.IR *dst . +.SH EXAMPLES +The following code will write the text "hello" into +a memstream, and then copy the contents of that +file into a second memstream buffer. +.fi +\& +.\" SRC BEGIN (fcopy.c) +.EX +#include <stdio.h> +#include <stdlib.h> +#include <extlib.h> +\& +int +main(void) +{ + char *buf_a, *buf_b; + size_t len_a, len_b; + FILE *file_buf_a = open_memstream (&buf_a, &len_a); + FILE *file_buf_b = open_memstream (&buf_b, &len_b); +\& + fprintf (file_test_a, "hello"); + fflush (file_test_a); + fclose (file_test_a); + file_test_a = fmemopen(buf_a, len_a, "r"); +\& + fcopy (file_test_a, file_test_b); + fclose (file_test_b); +\& + puts (buf_a); + puts (buf_b); + free (buf_a); + free (buf_b); +\& + exit(EXIT_SUCCESS); +} +.EE +.\" SRC END diff --git a/doc/memset_s.3 b/doc/memset_s.3 new file mode 100644 index 0000000..57956d0 --- /dev/null +++ b/doc/memset_s.3 @@ -0,0 +1,51 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH memset_s 3 2024-07-14 "extlib" +.SH NAME +fcopy \- copy a file +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #define __STDC_WANT_LIB_EXT1__ 1 +.P +.B #include <extlib.h> +.P +.BI "errno_t memset_s (void *s, rsize_t max, int c, rsize_t n);" +.fi +.SH DESCRIPTION +The +.BR memset_s() +function behaves the same way as +.BR memset () +except that it will not be removed through Dead Store Elimination, +which makes it useful when sensitive data needs to be cleared. +Unlike +.BR memset() +, +.BR memset_s() +will also return an error and call the currently registered constraint handler +if +.I *s +is a null pointer, +.I max +or +.I n +is greater than RSIZE_MAX, or +.I n +is greater than max. +.fi +.SH RETURN VALUE +The +.BR memset_s () +returns zero on success, non-zero on error. +.I *src +to +.IR *dst . +.SH STANDARDS +.BR memset_s () +conforms to ISO/IEC 9899:2011 ("ISO C11") K.3.7.4.1. diff --git a/doc/memvcmp.3 b/doc/memvcmp.3 new file mode 100644 index 0000000..952c0cf --- /dev/null +++ b/doc/memvcmp.3 @@ -0,0 +1,32 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH memvcmp 3 2024-07-14 "extlib" +.SH NAME +memvcmp \- compare a memory area to a value +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #include <extlib.h> +.P +.BI "int memvcmp (void *str, char val, size_t n);" +.fi +.SH DESCRIPTION +The +.BR memcvmp () +function compares +.I n +bytes of +.I *str +to the value +.I val +. +.fi +.SH RETURN VALUE +.BR memvcmp () +returns zero if the area matches, non-zero if it does not. +.\" SRC END diff --git a/doc/replace_str.3 b/doc/replace_str.3 new file mode 100644 index 0000000..230f6d1 --- /dev/null +++ b/doc/replace_str.3 @@ -0,0 +1,34 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH replace_str 3 2024-07-14 "extlib" +.SH NAME +replace_str \- replace a substring in a string +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #include <extlib.h> +.P +.BI "char *replace_str (char *s, char *old, char *replace);" +.P +.fi +.SH DESCRIPTION +The +.BR replace_str () +function replaces any matches of +.I *old +in the string +.I *s +with the string +.IR *replace . +.fi +.SH RETURN VALUE +.BR replace_str () +returns a copy of +.I *s +with all the substrings replaced. +.\" SRC END diff --git a/doc/rrmdir.3 b/doc/rrmdir.3 new file mode 100644 index 0000000..bb4be4e --- /dev/null +++ b/doc/rrmdir.3 @@ -0,0 +1,33 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH rrmdir 3 2024-07-14 "extlib" +.SH NAME +rrmdir \- recursively remove a directory +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #define _XOPEN_SOURCE 500 +.P +.B #include <extlib.h> +.P +.BI "int rrmdir(char *pathname);" +.fi +.SH DESCRIPTION +.BR rrmdir () +loops over +.I *pathname +using +.BR nftw () +and removes every file and directory found in +.I *pathname +. +.fi +.SH RETURN VALUE +.BR rrmdir () +return zero on sucess, non-zero on error. +.\" SRC END diff --git a/doc/set_constraint_handler_s.3 b/doc/set_constraint_handler_s.3 new file mode 100644 index 0000000..0860465 --- /dev/null +++ b/doc/set_constraint_handler_s.3 @@ -0,0 +1,147 @@ +.\" Copyright 2018 Yuri Pankov <yuripv@yuripv.net> +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd August 18, 2018 +.Dt SET_CONSTRAINT_HANDLER_S 3 +.Os +.Sh NAME +.Nm set_constraint_handler_s , +.Nm abort_handler_s , +.Nm ignore_handler_s +.Nd runtime-constraint violation handling +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.Fd #define __STDC_WANT_LIB_EXT1__ 1 +.In stdlib.h +.Ft constraint_handler_t +.Fo set_constraint_handler_s +.Fa "constraint_handler_t handler" +.Fc +.Ss Handler Prototype +.Ft typedef void +.Fo (*constraint_handler_t) +.Fa "const char * restrict msg" +.Fa "void * restrict ptr" +.Fa "errno_t error" +.Fc +.Ss Predefined Handlers +.Ft void +.Fo abort_handler_s +.Fa "const char * restrict msg" +.Fa "void * restrict ptr" +.Fa "errno_t error" +.Fc +.Ft void +.Fo ignore_handler_s +.Fa "const char * restrict msg" +.Fa "void * restrict ptr" +.Fa "errno_t error" +.Fc +.Sh DESCRIPTION +The +.Fn set_constraint_handler_s +function sets the runtime-constraint violation handler to be +.Fa handler . +.Pp +The runtime-constraint handler is the callback function invoked when a library +function detects a runtime-constraint violation. +.Pp +The arguments are as follows: +.Bl -tag -width "error" +.It Fa msg +A pointer to a character string describing the runtime-constraint violation. +.It Fa ptr +A +.Dv NULL +pointer. +.It Fa error +If the function calling the handler has a return type declared as +.Vt errno_t , +the return value of the function is passed. +Otherwise, a positive value of type +.Vt errno_t +is passed. +.El +.Pp +Only the most recent handler registered with +.Fn set_constraint_handler_s +is called when a runtime-constraint violation occurs. +.Pp +The implementation has a default constraint handler that is used if no calls to +the +.Fn set_constraint_handler_s +function have been made. +If the +.Fa handler +argument to +.Fn set_constraint_handler_s +is a +.Dv NULL +pointer, the default handler becomes the current constraint handler. +.Pp +The +.Fn abort_handler_s +and +.Fn ignore_handler_s +are the standard-defined runtime-constraint handlers provided by the C library. +.Pp +The +.Fn abort_handler_s +function writes the error message including the +.Fa msg +to +.Dv stderr +and calls the +.Xr abort 3 +function. +The +.Fn abort_handler_s +is currently the default runtime-constraint handler. +.Pp +The +.Fn ignore_handler_s +simply returns to its caller. +.Sh RETURN VALUES +The +.Fn set_constraint_handler_s +function returns a pointer to the previously registered handler, or +.Dv NULL +if none was previously registered. +.Pp +The +.Fn abort_handler_s +function does not return to its caller. +.Pp +The +.Fn ignore_handler_s +function returns no value. +.Sh STANDARDS +The +.Fn set_constraint_handler_s +function conforms to +.St -isoC-2011 +K.3.6.1.1. +.Sh AUTHORS +This manual page was written by +.An Yuri Pankov Aq Mt yuripv@yuripv.net . diff --git a/doc/strlwr.3 b/doc/strlwr.3 new file mode 100644 index 0000000..ca2e971 --- /dev/null +++ b/doc/strlwr.3 @@ -0,0 +1,41 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH strlwr 3 2024-07-14 "extlib" +.SH NAME +strlwr, strupr \- convert a string to upper/lowercase +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #include <extlib.h> +.P +.BI "char *strlwr (char *s);" +.P +.BI "char *strupr (char *s);" +.P +.fi +.SH DESCRIPTION +The +.BR strlwr () +function converts +.I *s +to a lowercase version of itself. +The +.BR strupr () +function converts +.I *s +to an uppercase version of itself. +In both functions +.I *s +will be consumed and cannot be used after the function completes. +.fi +.SH RETURN VALUE +.BR strlwr () +and +.BR strupr () +return the string in the appropriate case, the resulting string will have to be manually free'd. +.\" SRC END diff --git a/doc/strupr.3 b/doc/strupr.3 new file mode 100644 index 0000000..ca2e971 --- /dev/null +++ b/doc/strupr.3 @@ -0,0 +1,41 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH strlwr 3 2024-07-14 "extlib" +.SH NAME +strlwr, strupr \- convert a string to upper/lowercase +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #include <extlib.h> +.P +.BI "char *strlwr (char *s);" +.P +.BI "char *strupr (char *s);" +.P +.fi +.SH DESCRIPTION +The +.BR strlwr () +function converts +.I *s +to a lowercase version of itself. +The +.BR strupr () +function converts +.I *s +to an uppercase version of itself. +In both functions +.I *s +will be consumed and cannot be used after the function completes. +.fi +.SH RETURN VALUE +.BR strlwr () +and +.BR strupr () +return the string in the appropriate case, the resulting string will have to be manually free'd. +.\" SRC END diff --git a/doc/trim.3 b/doc/trim.3 new file mode 100644 index 0000000..fe2f7ab --- /dev/null +++ b/doc/trim.3 @@ -0,0 +1,40 @@ +'\" t +.\" Copyright 2024 axtlos (axtlos@disroot.org) +.\" +.\" SPDX-License-Identifier: BSD-3-Clause + +.TH trim 3 2024-07-14 "extlib" +.SH NAME +trim \- trim leading/trailing whitespace from a string +.SH LIBRARY +extlib extended standard library +.RI ( libextlib ", " \-lextlib ) +.SH SYNOPSIS +.nf +.B #include <extlib.h> +.P +.BI "char *trim (char *s, int *rem_front, int *rem_back);" +.P +.fi +.SH DESCRIPTION +The +.BR trim () +function removes leading/trailing newspace from +.IR *s . +If +.I *rem_front +is not NULL, it is set to the amount of leading whitespace removed from +.IR *s . +If +.I *rem_back +is not NULL, it is set to the amount of trailing whitespace removed from string +.IR *s . +.BR trim () +does not consume +.Ir *s , +it needs to be free'd manually. +.fi +.SH RETURN VALUE +.BR trim () +returns the trimmed string. +.\" SRC END diff --git a/src/constraint_handler.c b/src/constraint_handler.c index ca4e9d2..450632e 100644 --- a/src/constraint_handler.c +++ b/src/constraint_handler.c @@ -1,20 +1,5 @@ /* constraint_handler.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 + * SPDX-License-Identifier: BSD-3-Clause */ diff --git a/src/extlib.c b/src/extlib.c index 107e8b4..ce11709 100644 --- a/src/extlib.c +++ b/src/extlib.c @@ -14,7 +14,7 @@ * 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 + * SPDX-License-Identifier: BSD-3-Clause */ @@ -58,20 +58,25 @@ memvcmp (void *str, return memcmp (str, str2, n); } -void -fcopy(FILE *f1, FILE *f2) +size_t +fcopy (FILE *src, FILE *dst) { char buffer[BUFSIZ]; - size_t n; + size_t n, copied = 0; + + if (src == NULL || dst == NULL) + return -1; 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; + return -1; } fflush (f2); + copied += n; } + return copied; } int diff --git a/src/extlib.h b/src/extlib.h index fc7a3d2..5264195 100644 --- a/src/extlib.h +++ b/src/extlib.h @@ -1,20 +1,5 @@ -/* extlib.h - * - * 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 +/* extlib.c + * SPDX-License-Identifier: BSD-3-Clause */ #include <stdlib.h> @@ -52,8 +37,9 @@ void ignore_handler_s (const char *__restrict, void *__restrict, errno_t); #endif -/// Copy the data of one filestream to another */ -void fcopy(FILE *f1, FILE *f2); +/// Copy the data of one filestream to another +/// Returns the amount of bytes copied. +size_t fcopy(FILE *src, FILE *dst); #if (_XOPEN_SOURCE == 500) /// Recursively remove a directory pathname. @@ -73,6 +59,6 @@ char *strupr(char *s); /// Trim spaces from a string char *trim (char *s, int *rem_front, int *rem_back); -/// Match string old and replace it with string replace +/// Match string s for old and replace it with string replace char *replace_str (char *s, char *old, char *replace); diff --git a/src/extstring.c b/src/extstring.c index 477f5f7..8b82bb3 100644 --- a/src/extstring.c +++ b/src/extstring.c @@ -1,20 +1,5 @@ /* extstring.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 + * SPDX-License-Identifier: BSD-3-Clause */ #define USE_SECURE_MEM diff --git a/src/memset_s.c b/src/memset_s.c index deda5d7..dbe26ca 100644 --- a/src/memset_s.c +++ b/src/memset_s.c @@ -1,23 +1,7 @@ /* memset_s.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 + * SPDX-License-Identifier: BSD-3-Clause */ - #define __STDC_WANT_LIB_EXT1__ 1 #include "extlib.h" #include <errno.h> |