Skip to content

[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
mainfrom
repo-assist/improve-stpcpy-memccpy-2026-05-01-d2a12aa-1f649aa3be86f423
Draft

[Repo Assist] improve: add l_stpcpy, l_stpncpy, l_memccpy — POSIX string copy helpers#162
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/improve-stpcpy-memccpy-2026-05-01-d2a12aa-1f649aa3be86f423

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 1, 2026

🤖 This is an automated pull request from Repo Assist.

Summary

Add three POSIX string utility functions missing from l_os.h:

Function Signature Returns
l_stpcpy char *stpcpy(char *dst, const char *src) Pointer to terminating \0 in dst
l_stpncpy char *stpncpy(char *dst, const char *src, size_t n) dst + n always
l_memccpy void *memccpy(void *dst, const void *src, int c, size_t n) Pointer past c in dst, or NULL

Motivation

l_stpcpy avoids a second l_strlen pass when building a string by successive copies — the returned end-pointer feeds directly into the next copy, giving O(n) concatenation:

char *p = buf;
p = l_stpcpy(p, first);
p = l_stpcpy(p, " ");
p = l_stpcpy(p, last);
```

`l_memccpy` is the bounded counterpart that stops at a sentinel byte, avoiding a separate `l_memchr` pass for delimiter-separated byte streams.

## Changes

- **`l_os.h`**: forward declarations + implementations after `l_strncat`; `#define` aliases in `#ifndef L_DONTOVERRIDE` block.
- **`tests/test_strings.c`**: `test_stpcpy_stpncpy_memccpy()` covering copy correctness, pointer chaining, zero-padding, truncation, found/not-found, and `n=0` edge cases.
- **`docs/`**: regenerated API.md, COMPAT.md, COVERAGE.md.

## Test Status

```
Linux (gcc)   Build  PASS
Linux (gcc)   Test   PASS
Linux (gcc)   Verify PASS
Linux (clang) Build  PASS
Linux (clang) Test   PASS
Linux (clang) Verify PASS
Docs          Generate PASS

ARM/AArch64 cross-compilers not available in this environment.

Generated by 🌈 Repo Assist at Run.

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants