]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/strxcpyx.c
46712ed67deefaba402fb98e823c5fe1d873abc9
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2013 Kay Sievers
7 * Concatenates/copies strings. In any case, terminates in all cases
8 * with '\0' and moves the @dest pointer forward to the added '\0'.
9 * Returns the remaining size, and 0 if the string was truncated.
11 * Due to the intended usage, these helpers silently noop invocations
12 * having zero size. This is technically an exception to the above
13 * statement "terminates in all cases". It's unexpected for such calls to
14 * occur outside of a loop where this is the preferred behavior.
23 size_t strpcpy(char **dest
, size_t size
, const char *src
) {
35 *dest
= mempcpy(*dest
, src
, size
-1);
39 *dest
= mempcpy(*dest
, src
, len
);
47 size_t strpcpyf(char **dest
, size_t size
, const char *src
, ...) {
58 i
= vsnprintf(*dest
, size
, src
, va
);
69 size_t strpcpyl(char **dest
, size_t size
, const char *src
, ...) {
77 size
= strpcpy(dest
, size
, src
);
78 src
= va_arg(va
, char *);
79 } while (src
!= NULL
);
84 size_t strscpy(char *dest
, size_t size
, const char *src
) {
91 return strpcpy(&s
, size
, src
);
94 size_t strscpyl(char *dest
, size_t size
, const char *src
, ...) {
104 size
= strpcpy(&s
, size
, src
);
105 src
= va_arg(va
, char *);
106 } while (src
!= NULL
);