-
Notifications
You must be signed in to change notification settings - Fork 252
Add STRNCPYTAIL(), and use it instead of its pattern #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]> | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
|
|
||
| #include "config.h" | ||
|
|
||
| #include "string/strcpy/strncpytail.h" | ||
|
|
||
| #include <stddef.h> | ||
|
|
||
|
|
||
| extern inline char *strncpytail(char *restrict dst, const char *restrict src, | ||
| size_t dsize); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]> | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
|
|
||
| #ifndef SHADOW_INCLUDE_LIB_STRING_STRCPY_STRNCPYTAIL_H_ | ||
| #define SHADOW_INCLUDE_LIB_STRING_STRCPY_STRNCPYTAIL_H_ | ||
|
|
||
|
|
||
| #include "config.h" | ||
|
|
||
| #include <stddef.h> | ||
| #include <string.h> | ||
| #include <sys/param.h> | ||
|
|
||
| #include "attr.h" | ||
| #include "sizeof.h" | ||
| #include "string/strchr/strnul.h" | ||
|
|
||
|
|
||
| #define STRNCPYTAIL(dst, src) strncpytail(dst, src, countof(dst)) | ||
|
|
||
|
|
||
| ATTR_STRING(2) | ||
| inline char *strncpytail(char *restrict dst, const char *restrict src, | ||
| size_t dsize); | ||
|
|
||
|
|
||
| // nonstring copy tail-of-string | ||
alejandro-colomar marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm standing by this term. For the mnemonic comment explaining the name, nonstring is the most appropriate thing to use. You can think of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We already have "fixed-width null-padded character array", which is what utmp(5) members are. nonstring is a more generic thing, which englobes this and other creatures. But for this mnemonic use case, nonstring is easier to remember. @Karlson2k Please do not respond here. I already know your opinion, and am not going to agree with it. Anyone interested in it, can read the lengthy thread above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hallyn Please merge when you're happy with the name. Feel free to close all conversations, if you need that to be able to merge. |
||
| inline char * | ||
| strncpytail(char *restrict dst, const char *restrict src, size_t dsize) | ||
| { | ||
| return strncpy(dst, strnul(src) - MIN(strlen(src), dsize), dsize); | ||
| } | ||
|
|
||
|
|
||
| #endif // include guard | ||
Uh oh!
There was an error while loading. Please reload this page.