]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
6e6fb527 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2012 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <string.h> | |
22 | ||
6e6fb527 LP |
23 | #include "macro.h" |
24 | #include "replace-var.h" | |
07630cea LP |
25 | #include "string-util.h" |
26 | #include "util.h" | |
6e6fb527 LP |
27 | |
28 | static char *lookup(const char *variable, void *userdata) { | |
605405c6 | 29 | return strjoin("<<<", variable, ">>>"); |
6e6fb527 LP |
30 | } |
31 | ||
32 | int main(int argc, char *argv[]) { | |
33 | char *r; | |
34 | ||
35 | assert_se(r = replace_var("@@@foobar@xyz@HALLO@foobar@test@@testtest@TEST@...@@@", lookup, NULL)); | |
36 | puts(r); | |
37 | assert_se(streq(r, "@@@foobar@xyz<<<HALLO>>>foobar@test@@testtest<<<TEST>>>...@@@")); | |
38 | free(r); | |
39 | ||
40 | assert_se(r = strreplace("XYZFFFFXYZFFFFXYZ", "XYZ", "ABC")); | |
41 | puts(r); | |
42 | assert_se(streq(r, "ABCFFFFABCFFFFABC")); | |
43 | free(r); | |
44 | ||
45 | return 0; | |
46 | } |