[Repo Assist] improve: add l_stpcpy, l_stpncpy, l_memccpy — POSIX string copy helpers#162
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
Add three POSIX string utility functions missing from l_os.h: l_stpcpy(dst, src) Like strcpy but returns a pointer to the terminating '\0' in dst, enabling efficient string concatenation without a second strlen pass. l_stpncpy(dst, src, n) Like strncpy but always returns dst+n (the end of the destination window), consistent with the POSIX 2008 definition. l_memccpy(dst, src, c, n) Copies at most n bytes from src to dst, stopping after the first copy of byte c. Returns a pointer to the byte after c in dst, or NULL if c was not found within n bytes. Useful for bounded tokenised copies (e.g., building environment variable strings). All three are aliased to their standard names (stpcpy, stpncpy, memccpy) unless L_DONTOVERRIDE is defined. Tests added to test_strings.c. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
26 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Summary
Add three POSIX string utility functions missing from
l_os.h:l_stpcpychar *stpcpy(char *dst, const char *src)\0in dstl_stpncpychar *stpncpy(char *dst, const char *src, size_t n)dst + nalwaysl_memccpyvoid *memccpy(void *dst, const void *src, int c, size_t n)cin dst, or NULLMotivation
l_stpcpyavoids a secondl_strlenpass when building a string by successive copies — the returned end-pointer feeds directly into the next copy, giving O(n) concatenation:ARM/AArch64 cross-compilers not available in this environment.