]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/strxcpyx.c
ed71e23f6d3122d07f3c14498a0b010208c45574
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2013 Kay Sievers
9 * Concatenates/copies strings. In any case, terminates in all cases
10 * with '\0' and moves the @dest pointer forward to the added '\0'.
11 * Returns the remaining size, and 0 if the string was truncated.
13 * Due to the intended usage, these helpers silently noop invocations
14 * having zero size. This is technically an exception to the above
15 * statement "terminates in all cases". It's unexpected for such calls to
16 * occur outside of a loop where this is the preferred behavior.
25 size_t strpcpy(char **dest
, size_t size
, const char *src
) {
37 *dest
= mempcpy(*dest
, src
, size
-1);
41 *dest
= mempcpy(*dest
, src
, len
);
49 size_t strpcpyf(char **dest
, size_t size
, const char *src
, ...) {
60 i
= vsnprintf(*dest
, size
, src
, va
);
71 size_t strpcpyl(char **dest
, size_t size
, const char *src
, ...) {
79 size
= strpcpy(dest
, size
, src
);
80 src
= va_arg(va
, char *);
81 } while (src
!= NULL
);
86 size_t strscpy(char *dest
, size_t size
, const char *src
) {
93 return strpcpy(&s
, size
, src
);
96 size_t strscpyl(char *dest
, size_t size
, const char *src
, ...) {
106 size
= strpcpy(&s
, size
, src
);
107 src
= va_arg(va
, char *);
108 } while (src
!= NULL
);