summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeLines
* c_[v]stpeprintf(): Use [[gnu::format(printf(...))]] attributeHEADmainAlejandro Colomar2023-01-29-0/+2
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Microoptimize and simplify some functionsAlejandro Colomar2023-01-29-8/+4
| | | | | | | | Copying the NUL after the call to mempcpy(3) reduces the need to add an offset to the pointer. Also, we can call a function that does exactly that, thus reducing the source code. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Optimize c_ustr2stpe()Alejandro Colomar2023-01-29-3/+2
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Add c_ustr2stpe()Alejandro Colomar2023-01-24-0/+62
| | | | | | | This allows copying with truncation from a measured character sequence to a string. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* lint-c.mk: Add dependency on the pc(5) fileAlejandro Colomar2022-12-30-6/+6
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Add dependency on libc-branchAlejandro Colomar2022-12-30-41/+5
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Add dependency on libc-qualAlejandro Colomar2022-12-30-9/+5
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Add dependency on libc-str-lenAlejandro Colomar2022-12-30-5/+5
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* build-deps.mk: Fix use of pkgconf(1)Alejandro Colomar2022-12-29-1/+1
| | | | | | We need to use also the flags declared by our own pc(5) file. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Add dependency on libc-memAlejandro Colomar2022-12-29-58/+55
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Make this library part of a modular libcAlejandro Colomar2022-12-29-425/+340
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* $TESTSDIR/stpe/00{7,8,9}/*: Add tests for stpeprintf()Alejandro Colomar2022-12-27-0/+138
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* build-deps.mk: Move -I to CPPFLAGSAlejandro Colomar2022-12-27-1/+1
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* build-deps.mk: Silence unwanted warningAlejandro Colomar2022-12-27-0/+1
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* share/tests/libstp/stpe/00{2,3,4,5,6}/*: Add more testsAlejandro Colomar2022-12-27-0/+224
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* .gitignore, Makefile, check.mk, src.mk, share/tests/*: Add tests for the libraryAlejandro Colomar2022-12-27-0/+129
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* verbose.mk: Fix undefined variable errorAlejandro Colomar2022-12-27-0/+3
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.3: stpecpy() doesn't SIGSEGV on invalid inputAlejandro Colomar2022-12-27-3/+0
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.3: tfixAlejandro Colomar2022-12-27-1/+1
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Makefile, install-man.mk, install.mk, src.mk: Add target to install manual pagesAlejandro Colomar2022-12-27-1/+31
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* build-dev.mk, build-lib.mk, build-obj.mk: Also compile with -OfastAlejandro Colomar2022-12-27-6/+6
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Makefile, build.mk: Move definition of $builddir to main MakefileAlejandro Colomar2022-12-27-1/+1
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* lib/*: Make include guard comment more genericAlejandro Colomar2022-12-27-14/+14
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.h: Optimize away a branchAlejandro Colomar2022-12-27-1/+1
| | | | | | | | | The ternary operator can be removed after the optimization in the previous commit. This seems to be the optimization that the compiler was performing, which made it significantly faster than similar code calling strlen(3). Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.h: Call strnlen(3) instead of strlen(3)Alejandro Colomar2022-12-27-2/+2
| | | | | | | | | | It results in considerably faster code when strings truncate by a large margin, but surprisingly, it's also slightly faster when there's no truncation. I suspect that's because it helps simplify how we set 'trunc', but am not entirely sure. Suggested-by: Noah Goldstein <goldstein.w.n@gmail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.h: Reorder calls to optimizeAlejandro Colomar2022-12-27-2/+1
| | | | | | | | | | | | | | | | | | | | | We don't need to call strlen(3) until we need it. Since that's only after the tests for prior truncation, we're still within the same behavior of strlcpy(3) with regard to making sure strings are strings; in fact, by calling strlen(3) before the tests for prior truncation, we were doing even better, since we were testing all of the strings. However, one can write an instrumented wrapper that does what the old stpecpyx(3) did: if (src[strlen(src)] != '\0') raise(SIGSEGV); That way we provide the fastest performance possible. And, anyway, the compiler is also allowed to do that optimization, so we shouldn't rely on it. Suggested-by: Noah Goldstein <goldstein.w.n@gmail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpeprintf.h, stpeprintf.c: Make these functions inlineAlejandro Colomar2022-12-24-39/+45
| | | | | | Let's hope the compiler can use this information for something useful. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.3: tfixAlejandro Colomar2022-12-24-1/+1
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.h, stpecpy.c: stpecpy(): Make the function inlineAlejandro Colomar2022-12-24-26/+30
| | | | | | | | This function has several operations that can be skipped in normal conditions. Inlining will allow the compiler see those, and hopefully transform some calls into mempcpy(3) or stpcpy(3). Signed-off-by: Alejandro Colomar <alx@kernel.org>
* build-deps.mk: Add warning for declarations after statementsAlejandro Colomar2022-12-24-0/+1
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* etc/clang-tidy/config.yaml: Disable unwanted warningsAlejandro Colomar2022-12-24-0/+2
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.h, stpecpy.3, stpecpyx.3, stpecpy.c: Remove stpecpyx()Alejandro Colomar2022-12-24-36/+9
| | | | | | It was equivalent to stpecpy(). Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.c: stpecpy(): Crash on invalid src stringAlejandro Colomar2022-12-24-1/+2
| | | | | | | | After implementing this function in terms of mempcpy(3), it's trivial to make this function crash on invalid input. That removes the need for stpecpyx(3). Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.c: stpecpy(): Implement in terms of mempcpy(3)Alejandro Colomar2022-12-24-9/+8
| | | | | | | | mempcpy(3) is more optimized than memccpy(3); this implementation also has less branches (since memccpy(3) has several internally). Reported-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.c: srcfixAlejandro Colomar2022-12-24-2/+5
| | | | | | Use temporary variable. This will simplify a patch that I'll apply next. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Use lowercase 'stp' for the project nameAlejandro Colomar2022-12-24-8/+8
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* _compiler.h, stpecpy.c, stpeprintf.c: Add stp_impossible() wrapper around ↵Alejandro Colomar2022-12-24-6/+9
| | | | | | | | | | | unreachable() Having conditionals with stp_unreachable() makes it look like there's a branch, but there's not; it's just a hint to the compiler. This wrapper reduces cognitive load, I hope. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.3: tfixAlejandro Colomar2022-12-22-2/+2
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.3, ustpcpy.3, ustr2stp.3, zustr2stp.3, zustr2ustp.3: tfixAlejandro Colomar2022-12-22-6/+6
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* stpecpy.c, stpeprintf.c: Fix UBAlejandro Colomar2022-12-22-4/+4
| | | | | | '>' cannot be used to compare against NULL. Signed-off-by: Alejandro Colomar <alx@kernel.org>
* CONSTRIBUTING, INSTALL, README: Add repository documentationAlejandro Colomar2022-12-22-0/+290
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* .gitignore: Add gitignoreAlejandro Colomar2022-12-22-0/+5
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* libstp-uninstalled.pc: Add pc(5) fileAlejandro Colomar2022-12-22-0/+15
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* etc/: Add config files for lintersAlejandro Colomar2022-12-22-0/+45
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* Makefile, lib/*.mk: Add build systemAlejandro Colomar2022-12-22-0/+839
|
* LICENSES/*: Add license filesAlejandro Colomar2022-12-22-0/+321
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* share/man/*: Add manual pagesAlejandro Colomar2022-12-22-0/+773
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* include/*, src/*: Add source codeAlejandro Colomar2022-12-22-0/+349
| | | | Signed-off-by: Alejandro Colomar <alx@kernel.org>
* voidAlejandro Colomar2022-12-21-0/+0
Signed-off-by: Alejandro Colomar <alx@kernel.org>