File: | build-scan/../src/test/test-fileio.c |
Warning: | line 395, column 9 Value stored to 'f' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | |
3 | #include <fcntl.h> |
4 | #include <stdio.h> |
5 | #include <unistd.h> |
6 | |
7 | #include "alloc-util.h" |
8 | #include "ctype.h" |
9 | #include "def.h" |
10 | #include "env-util.h" |
11 | #include "fd-util.h" |
12 | #include "fileio.h" |
13 | #include "fs-util.h" |
14 | #include "io-util.h" |
15 | #include "parse-util.h" |
16 | #include "process-util.h" |
17 | #include "string-util.h" |
18 | #include "strv.h" |
19 | #include "util.h" |
20 | |
21 | static void test_parse_env_file(void) { |
22 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char |
23 | t[] = "/tmp/test-fileio-in-XXXXXX", |
24 | p[] = "/tmp/test-fileio-out-XXXXXX"; |
25 | int fd, r; |
26 | FILE *f; |
27 | _cleanup_free___attribute__((cleanup(freep))) char *one = NULL((void*)0), *two = NULL((void*)0), *three = NULL((void*)0), *four = NULL((void*)0), *five = NULL((void*)0), |
28 | *six = NULL((void*)0), *seven = NULL((void*)0), *eight = NULL((void*)0), *nine = NULL((void*)0), *ten = NULL((void*)0); |
29 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **a = NULL((void*)0), **b = NULL((void*)0); |
30 | char **i; |
31 | unsigned k; |
32 | |
33 | fd = mkostemp_safe(p); |
34 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 34, __PRETTY_FUNCTION__); } while (0); |
35 | close(fd); |
36 | |
37 | fd = mkostemp_safe(t); |
38 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 38, __PRETTY_FUNCTION__); } while (0); |
39 | |
40 | f = fdopen(fd, "w"); |
41 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 41, __PRETTY_FUNCTION__ ); } while (0); |
42 | |
43 | fputs("one=BAR \n" |
44 | "# comment\n" |
45 | " # comment \n" |
46 | " ; comment \n" |
47 | " two = bar \n" |
48 | "invalid line\n" |
49 | "invalid line #comment\n" |
50 | "three = \"333\n" |
51 | "xxxx\"\n" |
52 | "four = \'44\\\"44\'\n" |
53 | "five = \'55\\\'55\' \"FIVE\" cinco \n" |
54 | "six = seis sechs\\\n" |
55 | " sis\n" |
56 | "seven=\"sevenval\" #nocomment\n" |
57 | "eight=eightval #nocomment\n" |
58 | "export nine=nineval\n" |
59 | "ten=ignored\n" |
60 | "ten=ignored\n" |
61 | "ten=", f); |
62 | |
63 | fflush(f); |
64 | fclose(f); |
65 | |
66 | r = load_env_file(NULL((void*)0), t, NULL((void*)0), &a); |
67 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 67, __PRETTY_FUNCTION__); } while (0); |
68 | |
69 | STRV_FOREACH(i, a)for ((i) = (a); (i) && *(i); (i)++) |
70 | log_info("Got: <%s>", *i)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 70, __func__, "Got: <%s>" , *i) : -abs(_e); }); |
71 | |
72 | assert_se(streq_ptr(a[0], "one=BAR"))do { if ((__builtin_expect(!!(!(streq_ptr(a[0], "one=BAR"))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[0], \"one=BAR\")" ), "../src/test/test-fileio.c", 72, __PRETTY_FUNCTION__); } while (0); |
73 | assert_se(streq_ptr(a[1], "two=bar"))do { if ((__builtin_expect(!!(!(streq_ptr(a[1], "two=bar"))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[1], \"two=bar\")" ), "../src/test/test-fileio.c", 73, __PRETTY_FUNCTION__); } while (0); |
74 | assert_se(streq_ptr(a[2], "three=333\nxxxx"))do { if ((__builtin_expect(!!(!(streq_ptr(a[2], "three=333\nxxxx" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[2], \"three=333\\nxxxx\")" ), "../src/test/test-fileio.c", 74, __PRETTY_FUNCTION__); } while (0); |
75 | assert_se(streq_ptr(a[3], "four=44\"44"))do { if ((__builtin_expect(!!(!(streq_ptr(a[3], "four=44\"44" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[3], \"four=44\\\"44\")" ), "../src/test/test-fileio.c", 75, __PRETTY_FUNCTION__); } while (0); |
76 | assert_se(streq_ptr(a[4], "five=55\'55FIVEcinco"))do { if ((__builtin_expect(!!(!(streq_ptr(a[4], "five=55\'55FIVEcinco" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[4], \"five=55\\'55FIVEcinco\")" ), "../src/test/test-fileio.c", 76, __PRETTY_FUNCTION__); } while (0); |
77 | assert_se(streq_ptr(a[5], "six=seis sechs sis"))do { if ((__builtin_expect(!!(!(streq_ptr(a[5], "six=seis sechs sis" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[5], \"six=seis sechs sis\")" ), "../src/test/test-fileio.c", 77, __PRETTY_FUNCTION__); } while (0); |
78 | assert_se(streq_ptr(a[6], "seven=sevenval#nocomment"))do { if ((__builtin_expect(!!(!(streq_ptr(a[6], "seven=sevenval#nocomment" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[6], \"seven=sevenval#nocomment\")" ), "../src/test/test-fileio.c", 78, __PRETTY_FUNCTION__); } while (0); |
79 | assert_se(streq_ptr(a[7], "eight=eightval #nocomment"))do { if ((__builtin_expect(!!(!(streq_ptr(a[7], "eight=eightval #nocomment" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[7], \"eight=eightval #nocomment\")" ), "../src/test/test-fileio.c", 79, __PRETTY_FUNCTION__); } while (0); |
80 | assert_se(streq_ptr(a[8], "export nine=nineval"))do { if ((__builtin_expect(!!(!(streq_ptr(a[8], "export nine=nineval" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[8], \"export nine=nineval\")" ), "../src/test/test-fileio.c", 80, __PRETTY_FUNCTION__); } while (0); |
81 | assert_se(streq_ptr(a[9], "ten="))do { if ((__builtin_expect(!!(!(streq_ptr(a[9], "ten="))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[9], \"ten=\")" ), "../src/test/test-fileio.c", 81, __PRETTY_FUNCTION__); } while (0); |
82 | assert_se(a[10] == NULL)do { if ((__builtin_expect(!!(!(a[10] == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a[10] == NULL"), "../src/test/test-fileio.c" , 82, __PRETTY_FUNCTION__); } while (0); |
83 | |
84 | strv_env_clean(a)strv_env_clean_with_callback(a, ((void*)0), ((void*)0)); |
85 | |
86 | k = 0; |
87 | STRV_FOREACH(i, b)for ((i) = (b); (i) && *(i); (i)++) { |
88 | log_info("Got2: <%s>", *i)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 88, __func__, "Got2: <%s>" , *i) : -abs(_e); }); |
89 | assert_se(streq(*i, a[k++]))do { if ((__builtin_expect(!!(!((strcmp((*i),(a[k++])) == 0)) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*i, a[k++])" ), "../src/test/test-fileio.c", 89, __PRETTY_FUNCTION__); } while (0); |
90 | } |
91 | |
92 | r = parse_env_file( |
93 | NULL((void*)0), t, NULL((void*)0), |
94 | "one", &one, |
95 | "two", &two, |
96 | "three", &three, |
97 | "four", &four, |
98 | "five", &five, |
99 | "six", &six, |
100 | "seven", &seven, |
101 | "eight", &eight, |
102 | "export nine", &nine, |
103 | "ten", &ten, |
104 | NULL((void*)0)); |
105 | |
106 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 106, __PRETTY_FUNCTION__); } while (0); |
107 | |
108 | log_info("one=[%s]", strna(one))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 108, __func__, "one=[%s]", strna (one)) : -abs(_e); }); |
109 | log_info("two=[%s]", strna(two))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 109, __func__, "two=[%s]", strna (two)) : -abs(_e); }); |
110 | log_info("three=[%s]", strna(three))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 110, __func__, "three=[%s]", strna (three)) : -abs(_e); }); |
111 | log_info("four=[%s]", strna(four))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 111, __func__, "four=[%s]", strna (four)) : -abs(_e); }); |
112 | log_info("five=[%s]", strna(five))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 112, __func__, "five=[%s]", strna (five)) : -abs(_e); }); |
113 | log_info("six=[%s]", strna(six))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 113, __func__, "six=[%s]", strna (six)) : -abs(_e); }); |
114 | log_info("seven=[%s]", strna(seven))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 114, __func__, "seven=[%s]", strna (seven)) : -abs(_e); }); |
115 | log_info("eight=[%s]", strna(eight))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 115, __func__, "eight=[%s]", strna (eight)) : -abs(_e); }); |
116 | log_info("export nine=[%s]", strna(nine))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 116, __func__, "export nine=[%s]" , strna(nine)) : -abs(_e); }); |
117 | log_info("ten=[%s]", strna(nine))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 117, __func__, "ten=[%s]", strna (nine)) : -abs(_e); }); |
118 | |
119 | assert_se(streq(one, "BAR"))do { if ((__builtin_expect(!!(!((strcmp((one),("BAR")) == 0)) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(one, \"BAR\")" ), "../src/test/test-fileio.c", 119, __PRETTY_FUNCTION__); } while (0); |
120 | assert_se(streq(two, "bar"))do { if ((__builtin_expect(!!(!((strcmp((two),("bar")) == 0)) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(two, \"bar\")" ), "../src/test/test-fileio.c", 120, __PRETTY_FUNCTION__); } while (0); |
121 | assert_se(streq(three, "333\nxxxx"))do { if ((__builtin_expect(!!(!((strcmp((three),("333\nxxxx") ) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(three, \"333\\nxxxx\")" ), "../src/test/test-fileio.c", 121, __PRETTY_FUNCTION__); } while (0); |
122 | assert_se(streq(four, "44\"44"))do { if ((__builtin_expect(!!(!((strcmp((four),("44\"44")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(four, \"44\\\"44\")" ), "../src/test/test-fileio.c", 122, __PRETTY_FUNCTION__); } while (0); |
123 | assert_se(streq(five, "55\'55FIVEcinco"))do { if ((__builtin_expect(!!(!((strcmp((five),("55\'55FIVEcinco" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(five, \"55\\'55FIVEcinco\")" ), "../src/test/test-fileio.c", 123, __PRETTY_FUNCTION__); } while (0); |
124 | assert_se(streq(six, "seis sechs sis"))do { if ((__builtin_expect(!!(!((strcmp((six),("seis sechs sis" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(six, \"seis sechs sis\")" ), "../src/test/test-fileio.c", 124, __PRETTY_FUNCTION__); } while (0); |
125 | assert_se(streq(seven, "sevenval#nocomment"))do { if ((__builtin_expect(!!(!((strcmp((seven),("sevenval#nocomment" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(seven, \"sevenval#nocomment\")" ), "../src/test/test-fileio.c", 125, __PRETTY_FUNCTION__); } while (0); |
126 | assert_se(streq(eight, "eightval #nocomment"))do { if ((__builtin_expect(!!(!((strcmp((eight),("eightval #nocomment" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(eight, \"eightval #nocomment\")" ), "../src/test/test-fileio.c", 126, __PRETTY_FUNCTION__); } while (0); |
127 | assert_se(streq(nine, "nineval"))do { if ((__builtin_expect(!!(!((strcmp((nine),("nineval")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(nine, \"nineval\")" ), "../src/test/test-fileio.c", 127, __PRETTY_FUNCTION__); } while (0); |
128 | assert_se(ten == NULL)do { if ((__builtin_expect(!!(!(ten == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ten == NULL"), "../src/test/test-fileio.c" , 128, __PRETTY_FUNCTION__); } while (0); |
129 | |
130 | r = write_env_file(p, a); |
131 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 131, __PRETTY_FUNCTION__); } while (0); |
132 | |
133 | r = load_env_file(NULL((void*)0), p, NULL((void*)0), &b); |
134 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 134, __PRETTY_FUNCTION__); } while (0); |
135 | } |
136 | |
137 | static void test_parse_multiline_env_file(void) { |
138 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char |
139 | t[] = "/tmp/test-fileio-in-XXXXXX", |
140 | p[] = "/tmp/test-fileio-out-XXXXXX"; |
141 | int fd, r; |
142 | FILE *f; |
143 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **a = NULL((void*)0), **b = NULL((void*)0); |
144 | char **i; |
145 | |
146 | fd = mkostemp_safe(p); |
147 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 147, __PRETTY_FUNCTION__); } while (0); |
148 | close(fd); |
149 | |
150 | fd = mkostemp_safe(t); |
151 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 151, __PRETTY_FUNCTION__); } while (0); |
152 | |
153 | f = fdopen(fd, "w"); |
154 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 154, __PRETTY_FUNCTION__ ); } while (0); |
155 | |
156 | fputs("one=BAR\\\n" |
157 | " VAR\\\n" |
158 | "\tGAR\n" |
159 | "#comment\n" |
160 | "two=\"bar\\\n" |
161 | " var\\\n" |
162 | "\tgar\"\n" |
163 | "#comment\n" |
164 | "tri=\"bar \\\n" |
165 | " var \\\n" |
166 | "\tgar \"\n", f); |
167 | |
168 | fflush(f); |
169 | fclose(f); |
170 | |
171 | r = load_env_file(NULL((void*)0), t, NULL((void*)0), &a); |
172 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 172, __PRETTY_FUNCTION__); } while (0); |
173 | |
174 | STRV_FOREACH(i, a)for ((i) = (a); (i) && *(i); (i)++) |
175 | log_info("Got: <%s>", *i)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 175, __func__, "Got: <%s>" , *i) : -abs(_e); }); |
176 | |
177 | assert_se(streq_ptr(a[0], "one=BAR VAR\tGAR"))do { if ((__builtin_expect(!!(!(streq_ptr(a[0], "one=BAR VAR\tGAR" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[0], \"one=BAR VAR\\tGAR\")" ), "../src/test/test-fileio.c", 177, __PRETTY_FUNCTION__); } while (0); |
178 | assert_se(streq_ptr(a[1], "two=bar var\tgar"))do { if ((__builtin_expect(!!(!(streq_ptr(a[1], "two=bar var\tgar" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[1], \"two=bar var\\tgar\")" ), "../src/test/test-fileio.c", 178, __PRETTY_FUNCTION__); } while (0); |
179 | assert_se(streq_ptr(a[2], "tri=bar var \tgar "))do { if ((__builtin_expect(!!(!(streq_ptr(a[2], "tri=bar var \tgar " ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(a[2], \"tri=bar var \\tgar \")" ), "../src/test/test-fileio.c", 179, __PRETTY_FUNCTION__); } while (0); |
180 | assert_se(a[3] == NULL)do { if ((__builtin_expect(!!(!(a[3] == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a[3] == NULL"), "../src/test/test-fileio.c" , 180, __PRETTY_FUNCTION__); } while (0); |
181 | |
182 | r = write_env_file(p, a); |
183 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 183, __PRETTY_FUNCTION__); } while (0); |
184 | |
185 | r = load_env_file(NULL((void*)0), p, NULL((void*)0), &b); |
186 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 186, __PRETTY_FUNCTION__); } while (0); |
187 | } |
188 | |
189 | static void test_merge_env_file(void) { |
190 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char t[] = "/tmp/test-fileio-XXXXXX"; |
191 | int fd, r; |
192 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
193 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **a = NULL((void*)0); |
194 | char **i; |
195 | |
196 | fd = mkostemp_safe(t); |
197 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 197, __PRETTY_FUNCTION__); } while (0); |
198 | |
199 | log_info("/* %s (%s) */", __func__, t)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 199, __func__, "/* %s (%s) */" , __func__, t) : -abs(_e); }); |
200 | |
201 | f = fdopen(fd, "w"); |
202 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 202, __PRETTY_FUNCTION__ ); } while (0); |
203 | |
204 | r = write_string_stream(f, |
205 | "one=1 \n" |
206 | "twelve=${one}2\n" |
207 | "twentyone=2${one}\n" |
208 | "one=2\n" |
209 | "twentytwo=2${one}\n" |
210 | "xxx_minus_three=$xxx - 3\n" |
211 | "xxx=0x$one$one$one\n" |
212 | "yyy=${one:-fallback}\n" |
213 | "zzz=${one:+replacement}\n" |
214 | "zzzz=${foobar:-${nothing}}\n" |
215 | "zzzzz=${nothing:+${nothing}}\n" |
216 | , WRITE_STRING_FILE_AVOID_NEWLINE); |
217 | assert(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 217, __PRETTY_FUNCTION__); } while (0); |
218 | |
219 | r = merge_env_file(&a, NULL((void*)0), t); |
220 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 220, __PRETTY_FUNCTION__); } while (0); |
221 | strv_sort(a); |
222 | |
223 | STRV_FOREACH(i, a)for ((i) = (a); (i) && *(i); (i)++) |
224 | log_info("Got: <%s>", *i)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 224, __func__, "Got: <%s>" , *i) : -abs(_e); }); |
225 | |
226 | assert_se(streq(a[0], "one=2"))do { if ((__builtin_expect(!!(!((strcmp((a[0]),("one=2")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[0], \"one=2\")" ), "../src/test/test-fileio.c", 226, __PRETTY_FUNCTION__); } while (0); |
227 | assert_se(streq(a[1], "twelve=12"))do { if ((__builtin_expect(!!(!((strcmp((a[1]),("twelve=12")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[1], \"twelve=12\")" ), "../src/test/test-fileio.c", 227, __PRETTY_FUNCTION__); } while (0); |
228 | assert_se(streq(a[2], "twentyone=21"))do { if ((__builtin_expect(!!(!((strcmp((a[2]),("twentyone=21" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[2], \"twentyone=21\")" ), "../src/test/test-fileio.c", 228, __PRETTY_FUNCTION__); } while (0); |
229 | assert_se(streq(a[3], "twentytwo=22"))do { if ((__builtin_expect(!!(!((strcmp((a[3]),("twentytwo=22" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[3], \"twentytwo=22\")" ), "../src/test/test-fileio.c", 229, __PRETTY_FUNCTION__); } while (0); |
230 | assert_se(streq(a[4], "xxx=0x222"))do { if ((__builtin_expect(!!(!((strcmp((a[4]),("xxx=0x222")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[4], \"xxx=0x222\")" ), "../src/test/test-fileio.c", 230, __PRETTY_FUNCTION__); } while (0); |
231 | assert_se(streq(a[5], "xxx_minus_three= - 3"))do { if ((__builtin_expect(!!(!((strcmp((a[5]),("xxx_minus_three= - 3" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[5], \"xxx_minus_three= - 3\")" ), "../src/test/test-fileio.c", 231, __PRETTY_FUNCTION__); } while (0); |
232 | assert_se(streq(a[6], "yyy=2"))do { if ((__builtin_expect(!!(!((strcmp((a[6]),("yyy=2")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[6], \"yyy=2\")" ), "../src/test/test-fileio.c", 232, __PRETTY_FUNCTION__); } while (0); |
233 | assert_se(streq(a[7], "zzz=replacement"))do { if ((__builtin_expect(!!(!((strcmp((a[7]),("zzz=replacement" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[7], \"zzz=replacement\")" ), "../src/test/test-fileio.c", 233, __PRETTY_FUNCTION__); } while (0); |
234 | assert_se(streq(a[8], "zzzz="))do { if ((__builtin_expect(!!(!((strcmp((a[8]),("zzzz=")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[8], \"zzzz=\")" ), "../src/test/test-fileio.c", 234, __PRETTY_FUNCTION__); } while (0); |
235 | assert_se(streq(a[9], "zzzzz="))do { if ((__builtin_expect(!!(!((strcmp((a[9]),("zzzzz=")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[9], \"zzzzz=\")" ), "../src/test/test-fileio.c", 235, __PRETTY_FUNCTION__); } while (0); |
236 | assert_se(a[10] == NULL)do { if ((__builtin_expect(!!(!(a[10] == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a[10] == NULL"), "../src/test/test-fileio.c" , 236, __PRETTY_FUNCTION__); } while (0); |
237 | |
238 | r = merge_env_file(&a, NULL((void*)0), t); |
239 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 239, __PRETTY_FUNCTION__); } while (0); |
240 | strv_sort(a); |
241 | |
242 | STRV_FOREACH(i, a)for ((i) = (a); (i) && *(i); (i)++) |
243 | log_info("Got2: <%s>", *i)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 243, __func__, "Got2: <%s>" , *i) : -abs(_e); }); |
244 | |
245 | assert_se(streq(a[0], "one=2"))do { if ((__builtin_expect(!!(!((strcmp((a[0]),("one=2")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[0], \"one=2\")" ), "../src/test/test-fileio.c", 245, __PRETTY_FUNCTION__); } while (0); |
246 | assert_se(streq(a[1], "twelve=12"))do { if ((__builtin_expect(!!(!((strcmp((a[1]),("twelve=12")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[1], \"twelve=12\")" ), "../src/test/test-fileio.c", 246, __PRETTY_FUNCTION__); } while (0); |
247 | assert_se(streq(a[2], "twentyone=21"))do { if ((__builtin_expect(!!(!((strcmp((a[2]),("twentyone=21" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[2], \"twentyone=21\")" ), "../src/test/test-fileio.c", 247, __PRETTY_FUNCTION__); } while (0); |
248 | assert_se(streq(a[3], "twentytwo=22"))do { if ((__builtin_expect(!!(!((strcmp((a[3]),("twentytwo=22" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[3], \"twentytwo=22\")" ), "../src/test/test-fileio.c", 248, __PRETTY_FUNCTION__); } while (0); |
249 | assert_se(streq(a[4], "xxx=0x222"))do { if ((__builtin_expect(!!(!((strcmp((a[4]),("xxx=0x222")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[4], \"xxx=0x222\")" ), "../src/test/test-fileio.c", 249, __PRETTY_FUNCTION__); } while (0); |
250 | assert_se(streq(a[5], "xxx_minus_three=0x222 - 3"))do { if ((__builtin_expect(!!(!((strcmp((a[5]),("xxx_minus_three=0x222 - 3" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[5], \"xxx_minus_three=0x222 - 3\")" ), "../src/test/test-fileio.c", 250, __PRETTY_FUNCTION__); } while (0); |
251 | assert_se(streq(a[6], "yyy=2"))do { if ((__builtin_expect(!!(!((strcmp((a[6]),("yyy=2")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[6], \"yyy=2\")" ), "../src/test/test-fileio.c", 251, __PRETTY_FUNCTION__); } while (0); |
252 | assert_se(streq(a[7], "zzz=replacement"))do { if ((__builtin_expect(!!(!((strcmp((a[7]),("zzz=replacement" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[7], \"zzz=replacement\")" ), "../src/test/test-fileio.c", 252, __PRETTY_FUNCTION__); } while (0); |
253 | assert_se(streq(a[8], "zzzz="))do { if ((__builtin_expect(!!(!((strcmp((a[8]),("zzzz=")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[8], \"zzzz=\")" ), "../src/test/test-fileio.c", 253, __PRETTY_FUNCTION__); } while (0); |
254 | assert_se(streq(a[9], "zzzzz="))do { if ((__builtin_expect(!!(!((strcmp((a[9]),("zzzzz=")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a[9], \"zzzzz=\")" ), "../src/test/test-fileio.c", 254, __PRETTY_FUNCTION__); } while (0); |
255 | assert_se(a[10] == NULL)do { if ((__builtin_expect(!!(!(a[10] == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a[10] == NULL"), "../src/test/test-fileio.c" , 255, __PRETTY_FUNCTION__); } while (0); |
256 | } |
257 | |
258 | static void test_merge_env_file_invalid(void) { |
259 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char t[] = "/tmp/test-fileio-XXXXXX"; |
260 | int fd, r; |
261 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
262 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **a = NULL((void*)0); |
263 | char **i; |
264 | |
265 | fd = mkostemp_safe(t); |
266 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 266, __PRETTY_FUNCTION__); } while (0); |
267 | |
268 | log_info("/* %s (%s) */", __func__, t)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 268, __func__, "/* %s (%s) */" , __func__, t) : -abs(_e); }); |
269 | |
270 | f = fdopen(fd, "w"); |
271 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 271, __PRETTY_FUNCTION__ ); } while (0); |
272 | |
273 | r = write_string_stream(f, |
274 | "unset one \n" |
275 | "unset one= \n" |
276 | "unset one=1 \n" |
277 | "one \n" |
278 | "one = \n" |
279 | "one two =\n" |
280 | "\x20two=\n" |
281 | "#comment=comment\n" |
282 | ";comment2=comment2\n" |
283 | "#\n" |
284 | "\n\n" /* empty line */ |
285 | , WRITE_STRING_FILE_AVOID_NEWLINE); |
286 | assert(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 286, __PRETTY_FUNCTION__); } while (0); |
287 | |
288 | r = merge_env_file(&a, NULL((void*)0), t); |
289 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 289, __PRETTY_FUNCTION__); } while (0); |
290 | |
291 | STRV_FOREACH(i, a)for ((i) = (a); (i) && *(i); (i)++) |
292 | log_info("Got: <%s>", *i)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 292, __func__, "Got: <%s>" , *i) : -abs(_e); }); |
293 | |
294 | assert_se(strv_isempty(a))do { if ((__builtin_expect(!!(!(strv_isempty(a))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv_isempty(a)"), "../src/test/test-fileio.c" , 294, __PRETTY_FUNCTION__); } while (0); |
295 | } |
296 | |
297 | static void test_executable_is_script(void) { |
298 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char t[] = "/tmp/test-fileio-XXXXXX"; |
299 | int fd, r; |
300 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
301 | char *command; |
302 | |
303 | fd = mkostemp_safe(t); |
304 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 304, __PRETTY_FUNCTION__); } while (0); |
305 | |
306 | f = fdopen(fd, "w"); |
307 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 307, __PRETTY_FUNCTION__ ); } while (0); |
308 | |
309 | fputs("#! /bin/script -a -b \ngoo goo", f); |
310 | fflush(f); |
311 | |
312 | r = executable_is_script(t, &command); |
313 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fileio.c" , 313, __PRETTY_FUNCTION__); } while (0); |
314 | assert_se(streq(command, "/bin/script"))do { if ((__builtin_expect(!!(!((strcmp((command),("/bin/script" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(command, \"/bin/script\")" ), "../src/test/test-fileio.c", 314, __PRETTY_FUNCTION__); } while (0); |
315 | free(command); |
316 | |
317 | r = executable_is_script("/bin/sh", &command); |
318 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 318 , __PRETTY_FUNCTION__); } while (0); |
319 | |
320 | r = executable_is_script("/usr/bin/yum", &command); |
321 | assert_se(r > 0 || r == -ENOENT)do { if ((__builtin_expect(!!(!(r > 0 || r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0 || r == -ENOENT"), "../src/test/test-fileio.c" , 321, __PRETTY_FUNCTION__); } while (0); |
322 | if (r > 0) { |
323 | assert_se(startswith(command, "/"))do { if ((__builtin_expect(!!(!(startswith(command, "/"))),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("startswith(command, \"/\")" ), "../src/test/test-fileio.c", 323, __PRETTY_FUNCTION__); } while (0); |
324 | free(command); |
325 | } |
326 | } |
327 | |
328 | static void test_status_field(void) { |
329 | _cleanup_free___attribute__((cleanup(freep))) char *t = NULL((void*)0), *p = NULL((void*)0), *s = NULL((void*)0), *z = NULL((void*)0); |
330 | unsigned long long total = 0, buffers = 0; |
331 | int r; |
332 | |
333 | assert_se(get_proc_field("/proc/self/status", "Threads", WHITESPACE, &t) == 0)do { if ((__builtin_expect(!!(!(get_proc_field("/proc/self/status" , "Threads", " \t\n\r", &t) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("get_proc_field(\"/proc/self/status\", \"Threads\", WHITESPACE, &t) == 0" ), "../src/test/test-fileio.c", 333, __PRETTY_FUNCTION__); } while (0); |
334 | puts(t); |
335 | assert_se(streq(t, "1"))do { if ((__builtin_expect(!!(!((strcmp((t),("1")) == 0))),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(t, \"1\")" ), "../src/test/test-fileio.c", 335, __PRETTY_FUNCTION__); } while (0); |
336 | |
337 | r = get_proc_field("/proc/meminfo", "MemTotal", WHITESPACE" \t\n\r", &p); |
338 | if (r != -ENOENT2) { |
339 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 339 , __PRETTY_FUNCTION__); } while (0); |
340 | puts(p); |
341 | assert_se(safe_atollu(p, &total) == 0)do { if ((__builtin_expect(!!(!(safe_atollu(p, &total) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("safe_atollu(p, &total) == 0" ), "../src/test/test-fileio.c", 341, __PRETTY_FUNCTION__); } while (0); |
342 | } |
343 | |
344 | r = get_proc_field("/proc/meminfo", "Buffers", WHITESPACE" \t\n\r", &s); |
345 | if (r != -ENOENT2) { |
346 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 346 , __PRETTY_FUNCTION__); } while (0); |
347 | puts(s); |
348 | assert_se(safe_atollu(s, &buffers) == 0)do { if ((__builtin_expect(!!(!(safe_atollu(s, &buffers) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("safe_atollu(s, &buffers) == 0" ), "../src/test/test-fileio.c", 348, __PRETTY_FUNCTION__); } while (0); |
349 | } |
350 | |
351 | if (p) |
352 | assert_se(buffers < total)do { if ((__builtin_expect(!!(!(buffers < total)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("buffers < total"), "../src/test/test-fileio.c" , 352, __PRETTY_FUNCTION__); } while (0); |
353 | |
354 | /* Seccomp should be a good test for field full of zeros. */ |
355 | r = get_proc_field("/proc/meminfo", "Seccomp", WHITESPACE" \t\n\r", &z); |
356 | if (r != -ENOENT2) { |
357 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 357 , __PRETTY_FUNCTION__); } while (0); |
358 | puts(z); |
359 | assert_se(safe_atollu(z, &buffers) == 0)do { if ((__builtin_expect(!!(!(safe_atollu(z, &buffers) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("safe_atollu(z, &buffers) == 0" ), "../src/test/test-fileio.c", 359, __PRETTY_FUNCTION__); } while (0); |
360 | } |
361 | } |
362 | |
363 | static void test_capeff(void) { |
364 | int pid, p; |
365 | |
366 | for (pid = 0; pid < 2; pid++) { |
367 | _cleanup_free___attribute__((cleanup(freep))) char *capeff = NULL((void*)0); |
368 | int r; |
369 | |
370 | r = get_process_capeff(0, &capeff); |
371 | log_info("capeff: '%s' (r=%d)", capeff, r)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fileio.c", 371, __func__, "capeff: '%s' (r=%d)" , capeff, r) : -abs(_e); }); |
372 | |
373 | if (IN_SET(r, -ENOENT, -EPERM)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){-2, -1})/sizeof(int)]; switch(r) { case - 2: case -1: _found = 1; break; default: break; } _found; })) |
374 | return; |
375 | |
376 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 376 , __PRETTY_FUNCTION__); } while (0); |
377 | assert_se(*capeff)do { if ((__builtin_expect(!!(!(*capeff)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("*capeff"), "../src/test/test-fileio.c", 377, __PRETTY_FUNCTION__); } while (0); |
378 | p = capeff[strspn(capeff, HEXDIGITS"0123456789" "abcdefABCDEF")]; |
379 | assert_se(!p || isspace(p))do { if ((__builtin_expect(!!(!(!p || ((*__ctype_b_loc ())[(int ) ((p))] & (unsigned short int) _ISspace))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!p || isspace(p)"), "../src/test/test-fileio.c" , 379, __PRETTY_FUNCTION__); } while (0); |
380 | } |
381 | } |
382 | |
383 | static void test_write_string_stream(void) { |
384 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char fn[] = "/tmp/test-write_string_stream-XXXXXX"; |
385 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
386 | int fd; |
387 | char buf[64]; |
388 | |
389 | fd = mkostemp_safe(fn); |
390 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 390, __PRETTY_FUNCTION__); } while (0); |
391 | |
392 | f = fdopen(fd, "r"); |
393 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 393, __PRETTY_FUNCTION__ ); } while (0); |
394 | assert_se(write_string_stream(f, "boohoo", 0) < 0)do { if ((__builtin_expect(!!(!(write_string_stream(f, "boohoo" , 0) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("write_string_stream(f, \"boohoo\", 0) < 0"), "../src/test/test-fileio.c" , 394, __PRETTY_FUNCTION__); } while (0); |
395 | f = safe_fclose(f); |
Value stored to 'f' is never read | |
396 | |
397 | f = fopen(fn, "r+"); |
398 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 398, __PRETTY_FUNCTION__ ); } while (0); |
399 | |
400 | assert_se(write_string_stream(f, "boohoo", 0) == 0)do { if ((__builtin_expect(!!(!(write_string_stream(f, "boohoo" , 0) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "write_string_stream(f, \"boohoo\", 0) == 0"), "../src/test/test-fileio.c" , 400, __PRETTY_FUNCTION__); } while (0); |
401 | rewind(f); |
402 | |
403 | assert_se(fgets(buf, sizeof(buf), f))do { if ((__builtin_expect(!!(!(fgets(buf, sizeof(buf), f))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fgets(buf, sizeof(buf), f)" ), "../src/test/test-fileio.c", 403, __PRETTY_FUNCTION__); } while (0); |
404 | assert_se(streq(buf, "boohoo\n"))do { if ((__builtin_expect(!!(!((strcmp((buf),("boohoo\n")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, \"boohoo\\n\")" ), "../src/test/test-fileio.c", 404, __PRETTY_FUNCTION__); } while (0); |
405 | f = safe_fclose(f); |
406 | |
407 | f = fopen(fn, "w+"); |
408 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 408, __PRETTY_FUNCTION__ ); } while (0); |
409 | |
410 | assert_se(write_string_stream(f, "boohoo", WRITE_STRING_FILE_AVOID_NEWLINE) == 0)do { if ((__builtin_expect(!!(!(write_string_stream(f, "boohoo" , WRITE_STRING_FILE_AVOID_NEWLINE) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("write_string_stream(f, \"boohoo\", WRITE_STRING_FILE_AVOID_NEWLINE) == 0" ), "../src/test/test-fileio.c", 410, __PRETTY_FUNCTION__); } while (0); |
411 | rewind(f); |
412 | |
413 | assert_se(fgets(buf, sizeof(buf), f))do { if ((__builtin_expect(!!(!(fgets(buf, sizeof(buf), f))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fgets(buf, sizeof(buf), f)" ), "../src/test/test-fileio.c", 413, __PRETTY_FUNCTION__); } while (0); |
414 | printf(">%s<", buf); |
415 | assert_se(streq(buf, "boohoo"))do { if ((__builtin_expect(!!(!((strcmp((buf),("boohoo")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, \"boohoo\")" ), "../src/test/test-fileio.c", 415, __PRETTY_FUNCTION__); } while (0); |
416 | } |
417 | |
418 | static void test_write_string_file(void) { |
419 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char fn[] = "/tmp/test-write_string_file-XXXXXX"; |
420 | char buf[64] = {}; |
421 | _cleanup_close___attribute__((cleanup(closep))) int fd; |
422 | |
423 | fd = mkostemp_safe(fn); |
424 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 424, __PRETTY_FUNCTION__); } while (0); |
425 | |
426 | assert_se(write_string_file(fn, "boohoo", WRITE_STRING_FILE_CREATE) == 0)do { if ((__builtin_expect(!!(!(write_string_file(fn, "boohoo" , WRITE_STRING_FILE_CREATE) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("write_string_file(fn, \"boohoo\", WRITE_STRING_FILE_CREATE) == 0" ), "../src/test/test-fileio.c", 426, __PRETTY_FUNCTION__); } while (0); |
427 | |
428 | assert_se(read(fd, buf, sizeof(buf)) == 7)do { if ((__builtin_expect(!!(!(read(fd, buf, sizeof(buf)) == 7)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read(fd, buf, sizeof(buf)) == 7" ), "../src/test/test-fileio.c", 428, __PRETTY_FUNCTION__); } while (0); |
429 | assert_se(streq(buf, "boohoo\n"))do { if ((__builtin_expect(!!(!((strcmp((buf),("boohoo\n")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, \"boohoo\\n\")" ), "../src/test/test-fileio.c", 429, __PRETTY_FUNCTION__); } while (0); |
430 | } |
431 | |
432 | static void test_write_string_file_no_create(void) { |
433 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX"; |
434 | _cleanup_close___attribute__((cleanup(closep))) int fd; |
435 | char buf[64] = {0}; |
436 | |
437 | fd = mkostemp_safe(fn); |
438 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 438, __PRETTY_FUNCTION__); } while (0); |
439 | |
440 | assert_se(write_string_file("/a/file/which/does/not/exists/i/guess", "boohoo", 0) < 0)do { if ((__builtin_expect(!!(!(write_string_file("/a/file/which/does/not/exists/i/guess" , "boohoo", 0) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("write_string_file(\"/a/file/which/does/not/exists/i/guess\", \"boohoo\", 0) < 0" ), "../src/test/test-fileio.c", 440, __PRETTY_FUNCTION__); } while (0); |
441 | assert_se(write_string_file(fn, "boohoo", 0) == 0)do { if ((__builtin_expect(!!(!(write_string_file(fn, "boohoo" , 0) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "write_string_file(fn, \"boohoo\", 0) == 0"), "../src/test/test-fileio.c" , 441, __PRETTY_FUNCTION__); } while (0); |
442 | |
443 | assert_se(read(fd, buf, sizeof(buf)) == STRLEN("boohoo\n"))do { if ((__builtin_expect(!!(!(read(fd, buf, sizeof(buf)) == (sizeof("""boohoo\n""") - 1))),0))) log_assert_failed_realm( LOG_REALM_SYSTEMD, ("read(fd, buf, sizeof(buf)) == STRLEN(\"boohoo\\n\")" ), "../src/test/test-fileio.c", 443, __PRETTY_FUNCTION__); } while (0); |
444 | assert_se(streq(buf, "boohoo\n"))do { if ((__builtin_expect(!!(!((strcmp((buf),("boohoo\n")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, \"boohoo\\n\")" ), "../src/test/test-fileio.c", 444, __PRETTY_FUNCTION__); } while (0); |
445 | } |
446 | |
447 | static void test_write_string_file_verify(void) { |
448 | _cleanup_free___attribute__((cleanup(freep))) char *buf = NULL((void*)0), *buf2 = NULL((void*)0); |
449 | int r; |
450 | |
451 | assert_se(read_one_line_file("/proc/cmdline", &buf) >= 0)do { if ((__builtin_expect(!!(!(read_one_line_file("/proc/cmdline" , &buf) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("read_one_line_file(\"/proc/cmdline\", &buf) >= 0") , "../src/test/test-fileio.c", 451, __PRETTY_FUNCTION__); } while (0); |
452 | assert_se(buf2 = strjoin(buf, "\n"))do { if ((__builtin_expect(!!(!(buf2 = strjoin_real((buf), "\n" , ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("buf2 = strjoin(buf, \"\\n\")"), "../src/test/test-fileio.c" , 452, __PRETTY_FUNCTION__); } while (0); |
453 | |
454 | r = write_string_file("/proc/cmdline", buf, 0); |
455 | assert_se(IN_SET(r, -EACCES, -EIO))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){-13, -5})/sizeof(int)]; switch(r) { case -13 : case -5: _found = 1; break; default: break; } _found; }))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("IN_SET(r, -EACCES, -EIO)" ), "../src/test/test-fileio.c", 455, __PRETTY_FUNCTION__); } while (0); |
456 | r = write_string_file("/proc/cmdline", buf2, 0); |
457 | assert_se(IN_SET(r, -EACCES, -EIO))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){-13, -5})/sizeof(int)]; switch(r) { case -13 : case -5: _found = 1; break; default: break; } _found; }))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("IN_SET(r, -EACCES, -EIO)" ), "../src/test/test-fileio.c", 457, __PRETTY_FUNCTION__); } while (0); |
458 | |
459 | assert_se(write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0)do { if ((__builtin_expect(!!(!(write_string_file("/proc/cmdline" , buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("write_string_file(\"/proc/cmdline\", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0" ), "../src/test/test-fileio.c", 459, __PRETTY_FUNCTION__); } while (0); |
460 | assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0)do { if ((__builtin_expect(!!(!(write_string_file("/proc/cmdline" , buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("write_string_file(\"/proc/cmdline\", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0" ), "../src/test/test-fileio.c", 460, __PRETTY_FUNCTION__); } while (0); |
461 | |
462 | r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE); |
463 | assert_se(IN_SET(r, -EACCES, -EIO))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){-13, -5})/sizeof(int)]; switch(r) { case -13 : case -5: _found = 1; break; default: break; } _found; }))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("IN_SET(r, -EACCES, -EIO)" ), "../src/test/test-fileio.c", 463, __PRETTY_FUNCTION__); } while (0); |
464 | assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0)do { if ((__builtin_expect(!!(!(write_string_file("/proc/cmdline" , buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE ) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("write_string_file(\"/proc/cmdline\", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0" ), "../src/test/test-fileio.c", 464, __PRETTY_FUNCTION__); } while (0); |
465 | } |
466 | |
467 | static void test_load_env_file_pairs(void) { |
468 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char fn[] = "/tmp/test-load_env_file_pairs-XXXXXX"; |
469 | int fd, r; |
470 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
471 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0); |
472 | char **k, **v; |
473 | |
474 | fd = mkostemp_safe(fn); |
475 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 475, __PRETTY_FUNCTION__); } while (0); |
476 | |
477 | r = write_string_file(fn, |
478 | "NAME=\"Arch Linux\"\n" |
479 | "ID=arch\n" |
480 | "PRETTY_NAME=\"Arch Linux\"\n" |
481 | "ANSI_COLOR=\"0;36\"\n" |
482 | "HOME_URL=\"https://www.archlinux.org/\"\n" |
483 | "SUPPORT_URL=\"https://bbs.archlinux.org/\"\n" |
484 | "BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n", |
485 | WRITE_STRING_FILE_CREATE); |
486 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 486 , __PRETTY_FUNCTION__); } while (0); |
487 | |
488 | f = fdopen(fd, "r"); |
489 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 489, __PRETTY_FUNCTION__ ); } while (0); |
490 | |
491 | r = load_env_file_pairs(f, fn, NULL((void*)0), &l); |
492 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 492, __PRETTY_FUNCTION__); } while (0); |
493 | |
494 | assert_se(strv_length(l) == 14)do { if ((__builtin_expect(!!(!(strv_length(l) == 14)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv_length(l) == 14"), "../src/test/test-fileio.c" , 494, __PRETTY_FUNCTION__); } while (0); |
495 | STRV_FOREACH_PAIR(k, v, l)for ((k) = (l), (v) = (k+1); (k) && *(k) && * (v); (k) += 2, (v) = (k + 1)) { |
496 | assert_se(STR_IN_SET(*k, "NAME", "ID", "PRETTY_NAME", "ANSI_COLOR", "HOME_URL", "SUPPORT_URL", "BUG_REPORT_URL"))do { if ((__builtin_expect(!!(!((!!strv_find((((char**) ((const char*[]) { "NAME", "ID", "PRETTY_NAME", "ANSI_COLOR", "HOME_URL" , "SUPPORT_URL", "BUG_REPORT_URL", ((void*)0) }))), (*k))))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("STR_IN_SET(*k, \"NAME\", \"ID\", \"PRETTY_NAME\", \"ANSI_COLOR\", \"HOME_URL\", \"SUPPORT_URL\", \"BUG_REPORT_URL\")" ), "../src/test/test-fileio.c", 496, __PRETTY_FUNCTION__); } while (0); |
497 | printf("%s=%s\n", *k, *v); |
498 | if (streq(*k, "NAME")(strcmp((*k),("NAME")) == 0)) assert_se(streq(*v, "Arch Linux"))do { if ((__builtin_expect(!!(!((strcmp((*v),("Arch Linux")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"Arch Linux\")" ), "../src/test/test-fileio.c", 498, __PRETTY_FUNCTION__); } while (0); |
499 | if (streq(*k, "ID")(strcmp((*k),("ID")) == 0)) assert_se(streq(*v, "arch"))do { if ((__builtin_expect(!!(!((strcmp((*v),("arch")) == 0)) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"arch\")" ), "../src/test/test-fileio.c", 499, __PRETTY_FUNCTION__); } while (0); |
500 | if (streq(*k, "PRETTY_NAME")(strcmp((*k),("PRETTY_NAME")) == 0)) assert_se(streq(*v, "Arch Linux"))do { if ((__builtin_expect(!!(!((strcmp((*v),("Arch Linux")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"Arch Linux\")" ), "../src/test/test-fileio.c", 500, __PRETTY_FUNCTION__); } while (0); |
501 | if (streq(*k, "ANSI_COLOR")(strcmp((*k),("ANSI_COLOR")) == 0)) assert_se(streq(*v, "0;36"))do { if ((__builtin_expect(!!(!((strcmp((*v),("0;36")) == 0)) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"0;36\")" ), "../src/test/test-fileio.c", 501, __PRETTY_FUNCTION__); } while (0); |
502 | if (streq(*k, "HOME_URL")(strcmp((*k),("HOME_URL")) == 0)) assert_se(streq(*v, "https://www.archlinux.org/"))do { if ((__builtin_expect(!!(!((strcmp((*v),("https://www.archlinux.org/" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"https://www.archlinux.org/\")" ), "../src/test/test-fileio.c", 502, __PRETTY_FUNCTION__); } while (0); |
503 | if (streq(*k, "SUPPORT_URL")(strcmp((*k),("SUPPORT_URL")) == 0)) assert_se(streq(*v, "https://bbs.archlinux.org/"))do { if ((__builtin_expect(!!(!((strcmp((*v),("https://bbs.archlinux.org/" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"https://bbs.archlinux.org/\")" ), "../src/test/test-fileio.c", 503, __PRETTY_FUNCTION__); } while (0); |
504 | if (streq(*k, "BUG_REPORT_URL")(strcmp((*k),("BUG_REPORT_URL")) == 0)) assert_se(streq(*v, "https://bugs.archlinux.org/"))do { if ((__builtin_expect(!!(!((strcmp((*v),("https://bugs.archlinux.org/" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(*v, \"https://bugs.archlinux.org/\")" ), "../src/test/test-fileio.c", 504, __PRETTY_FUNCTION__); } while (0); |
505 | } |
506 | } |
507 | |
508 | static void test_search_and_fopen(void) { |
509 | const char *dirs[] = {"/tmp/foo/bar", "/tmp", NULL((void*)0)}; |
510 | |
511 | char name[] = "/tmp/test-search_and_fopen.XXXXXX"; |
512 | int fd, r; |
513 | FILE *f; |
514 | |
515 | fd = mkostemp_safe(name); |
516 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 516, __PRETTY_FUNCTION__); } while (0); |
517 | close(fd); |
518 | |
519 | r = search_and_fopen(basename(name), "r", NULL((void*)0), dirs, &f); |
520 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 520, __PRETTY_FUNCTION__); } while (0); |
521 | fclose(f); |
522 | |
523 | r = search_and_fopen(name, "r", NULL((void*)0), dirs, &f); |
524 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 524, __PRETTY_FUNCTION__); } while (0); |
525 | fclose(f); |
526 | |
527 | r = search_and_fopen(basename(name), "r", "/", dirs, &f); |
528 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 528, __PRETTY_FUNCTION__); } while (0); |
529 | fclose(f); |
530 | |
531 | r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "r", NULL((void*)0), dirs, &f); |
532 | assert_se(r < 0)do { if ((__builtin_expect(!!(!(r < 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r < 0"), "../src/test/test-fileio.c" , 532, __PRETTY_FUNCTION__); } while (0); |
533 | r = search_and_fopen("afilewhichdoesnotexistiguess", "r", NULL((void*)0), dirs, &f); |
534 | assert_se(r < 0)do { if ((__builtin_expect(!!(!(r < 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r < 0"), "../src/test/test-fileio.c" , 534, __PRETTY_FUNCTION__); } while (0); |
535 | |
536 | r = unlink(name); |
537 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 537 , __PRETTY_FUNCTION__); } while (0); |
538 | |
539 | r = search_and_fopen(basename(name), "r", NULL((void*)0), dirs, &f); |
540 | assert_se(r < 0)do { if ((__builtin_expect(!!(!(r < 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r < 0"), "../src/test/test-fileio.c" , 540, __PRETTY_FUNCTION__); } while (0); |
541 | } |
542 | |
543 | static void test_search_and_fopen_nulstr(void) { |
544 | const char dirs[] = "/tmp/foo/bar\0/tmp\0"; |
545 | |
546 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char name[] = "/tmp/test-search_and_fopen.XXXXXX"; |
547 | int fd, r; |
548 | FILE *f; |
549 | |
550 | fd = mkostemp_safe(name); |
551 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 551, __PRETTY_FUNCTION__); } while (0); |
552 | close(fd); |
553 | |
554 | r = search_and_fopen_nulstr(basename(name), "r", NULL((void*)0), dirs, &f); |
555 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 555, __PRETTY_FUNCTION__); } while (0); |
556 | fclose(f); |
557 | |
558 | r = search_and_fopen_nulstr(name, "r", NULL((void*)0), dirs, &f); |
559 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 559, __PRETTY_FUNCTION__); } while (0); |
560 | fclose(f); |
561 | |
562 | r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "r", NULL((void*)0), dirs, &f); |
563 | assert_se(r < 0)do { if ((__builtin_expect(!!(!(r < 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r < 0"), "../src/test/test-fileio.c" , 563, __PRETTY_FUNCTION__); } while (0); |
564 | r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "r", NULL((void*)0), dirs, &f); |
565 | assert_se(r < 0)do { if ((__builtin_expect(!!(!(r < 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r < 0"), "../src/test/test-fileio.c" , 565, __PRETTY_FUNCTION__); } while (0); |
566 | |
567 | r = unlink(name); |
568 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 568 , __PRETTY_FUNCTION__); } while (0); |
569 | |
570 | r = search_and_fopen_nulstr(basename(name), "r", NULL((void*)0), dirs, &f); |
571 | assert_se(r < 0)do { if ((__builtin_expect(!!(!(r < 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r < 0"), "../src/test/test-fileio.c" , 571, __PRETTY_FUNCTION__); } while (0); |
572 | } |
573 | |
574 | static void test_writing_tmpfile(void) { |
575 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX"; |
576 | _cleanup_free___attribute__((cleanup(freep))) char *contents = NULL((void*)0); |
577 | size_t size; |
578 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; |
579 | struct iovec iov[3]; |
580 | int r; |
581 | |
582 | iov[0] = IOVEC_MAKE_STRING("abc\n")(struct iovec) { .iov_base = ((char*) "abc\n"), .iov_len = (strlen ("abc\n")) }; |
583 | iov[1] = IOVEC_MAKE_STRING(ALPHANUMERICAL "\n")(struct iovec) { .iov_base = ((char*) "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "\n"), .iov_len = ( strlen("abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "\n")) }; |
584 | iov[2] = IOVEC_MAKE_STRING("")(struct iovec) { .iov_base = ((char*) ""), .iov_len = (strlen ("")) }; |
585 | |
586 | fd = mkostemp_safe(name); |
587 | printf("tmpfile: %s", name); |
588 | |
589 | r = writev(fd, iov, 3); |
590 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fileio.c" , 590, __PRETTY_FUNCTION__); } while (0); |
591 | |
592 | r = read_full_file(name, &contents, &size); |
593 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fileio.c", 593 , __PRETTY_FUNCTION__); } while (0); |
594 | printf("contents: %s", contents); |
595 | assert_se(streq(contents, "abc\n" ALPHANUMERICAL "\n"))do { if ((__builtin_expect(!!(!((strcmp((contents),("abc\n" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "\n")) == 0))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(contents, \"abc\\n\" ALPHANUMERICAL \"\\n\")" ), "../src/test/test-fileio.c", 595, __PRETTY_FUNCTION__); } while (0); |
596 | } |
597 | |
598 | static void test_tempfn(void) { |
599 | char *ret = NULL((void*)0), *p; |
600 | |
601 | assert_se(tempfn_xxxxxx("/foo/bar/waldo", NULL, &ret) >= 0)do { if ((__builtin_expect(!!(!(tempfn_xxxxxx("/foo/bar/waldo" , ((void*)0), &ret) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tempfn_xxxxxx(\"/foo/bar/waldo\", NULL, &ret) >= 0" ), "../src/test/test-fileio.c", 601, __PRETTY_FUNCTION__); } while (0); |
602 | assert_se(streq_ptr(ret, "/foo/bar/.#waldoXXXXXX"))do { if ((__builtin_expect(!!(!(streq_ptr(ret, "/foo/bar/.#waldoXXXXXX" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(ret, \"/foo/bar/.#waldoXXXXXX\")" ), "../src/test/test-fileio.c", 602, __PRETTY_FUNCTION__); } while (0); |
603 | free(ret); |
604 | |
605 | assert_se(tempfn_xxxxxx("/foo/bar/waldo", "[miau]", &ret) >= 0)do { if ((__builtin_expect(!!(!(tempfn_xxxxxx("/foo/bar/waldo" , "[miau]", &ret) >= 0)),0))) log_assert_failed_realm( LOG_REALM_SYSTEMD, ("tempfn_xxxxxx(\"/foo/bar/waldo\", \"[miau]\", &ret) >= 0" ), "../src/test/test-fileio.c", 605, __PRETTY_FUNCTION__); } while (0); |
606 | assert_se(streq_ptr(ret, "/foo/bar/.#[miau]waldoXXXXXX"))do { if ((__builtin_expect(!!(!(streq_ptr(ret, "/foo/bar/.#[miau]waldoXXXXXX" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(ret, \"/foo/bar/.#[miau]waldoXXXXXX\")" ), "../src/test/test-fileio.c", 606, __PRETTY_FUNCTION__); } while (0); |
607 | free(ret); |
608 | |
609 | assert_se(tempfn_random("/foo/bar/waldo", NULL, &ret) >= 0)do { if ((__builtin_expect(!!(!(tempfn_random("/foo/bar/waldo" , ((void*)0), &ret) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tempfn_random(\"/foo/bar/waldo\", NULL, &ret) >= 0" ), "../src/test/test-fileio.c", 609, __PRETTY_FUNCTION__); } while (0); |
610 | assert_se(p = startswith(ret, "/foo/bar/.#waldo"))do { if ((__builtin_expect(!!(!(p = startswith(ret, "/foo/bar/.#waldo" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("p = startswith(ret, \"/foo/bar/.#waldo\")" ), "../src/test/test-fileio.c", 610, __PRETTY_FUNCTION__); } while (0); |
611 | assert_se(strlen(p) == 16)do { if ((__builtin_expect(!!(!(strlen(p) == 16)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strlen(p) == 16"), "../src/test/test-fileio.c" , 611, __PRETTY_FUNCTION__); } while (0); |
612 | assert_se(in_charset(p, "0123456789abcdef"))do { if ((__builtin_expect(!!(!(in_charset(p, "0123456789abcdef" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_charset(p, \"0123456789abcdef\")" ), "../src/test/test-fileio.c", 612, __PRETTY_FUNCTION__); } while (0); |
613 | free(ret); |
614 | |
615 | assert_se(tempfn_random("/foo/bar/waldo", "[wuff]", &ret) >= 0)do { if ((__builtin_expect(!!(!(tempfn_random("/foo/bar/waldo" , "[wuff]", &ret) >= 0)),0))) log_assert_failed_realm( LOG_REALM_SYSTEMD, ("tempfn_random(\"/foo/bar/waldo\", \"[wuff]\", &ret) >= 0" ), "../src/test/test-fileio.c", 615, __PRETTY_FUNCTION__); } while (0); |
616 | assert_se(p = startswith(ret, "/foo/bar/.#[wuff]waldo"))do { if ((__builtin_expect(!!(!(p = startswith(ret, "/foo/bar/.#[wuff]waldo" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("p = startswith(ret, \"/foo/bar/.#[wuff]waldo\")" ), "../src/test/test-fileio.c", 616, __PRETTY_FUNCTION__); } while (0); |
617 | assert_se(strlen(p) == 16)do { if ((__builtin_expect(!!(!(strlen(p) == 16)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strlen(p) == 16"), "../src/test/test-fileio.c" , 617, __PRETTY_FUNCTION__); } while (0); |
618 | assert_se(in_charset(p, "0123456789abcdef"))do { if ((__builtin_expect(!!(!(in_charset(p, "0123456789abcdef" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_charset(p, \"0123456789abcdef\")" ), "../src/test/test-fileio.c", 618, __PRETTY_FUNCTION__); } while (0); |
619 | free(ret); |
620 | |
621 | assert_se(tempfn_random_child("/foo/bar/waldo", NULL, &ret) >= 0)do { if ((__builtin_expect(!!(!(tempfn_random_child("/foo/bar/waldo" , ((void*)0), &ret) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tempfn_random_child(\"/foo/bar/waldo\", NULL, &ret) >= 0" ), "../src/test/test-fileio.c", 621, __PRETTY_FUNCTION__); } while (0); |
622 | assert_se(p = startswith(ret, "/foo/bar/waldo/.#"))do { if ((__builtin_expect(!!(!(p = startswith(ret, "/foo/bar/waldo/.#" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("p = startswith(ret, \"/foo/bar/waldo/.#\")" ), "../src/test/test-fileio.c", 622, __PRETTY_FUNCTION__); } while (0); |
623 | assert_se(strlen(p) == 16)do { if ((__builtin_expect(!!(!(strlen(p) == 16)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strlen(p) == 16"), "../src/test/test-fileio.c" , 623, __PRETTY_FUNCTION__); } while (0); |
624 | assert_se(in_charset(p, "0123456789abcdef"))do { if ((__builtin_expect(!!(!(in_charset(p, "0123456789abcdef" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_charset(p, \"0123456789abcdef\")" ), "../src/test/test-fileio.c", 624, __PRETTY_FUNCTION__); } while (0); |
625 | free(ret); |
626 | |
627 | assert_se(tempfn_random_child("/foo/bar/waldo", "[kikiriki]", &ret) >= 0)do { if ((__builtin_expect(!!(!(tempfn_random_child("/foo/bar/waldo" , "[kikiriki]", &ret) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tempfn_random_child(\"/foo/bar/waldo\", \"[kikiriki]\", &ret) >= 0" ), "../src/test/test-fileio.c", 627, __PRETTY_FUNCTION__); } while (0); |
628 | assert_se(p = startswith(ret, "/foo/bar/waldo/.#[kikiriki]"))do { if ((__builtin_expect(!!(!(p = startswith(ret, "/foo/bar/waldo/.#[kikiriki]" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("p = startswith(ret, \"/foo/bar/waldo/.#[kikiriki]\")" ), "../src/test/test-fileio.c", 628, __PRETTY_FUNCTION__); } while (0); |
629 | assert_se(strlen(p) == 16)do { if ((__builtin_expect(!!(!(strlen(p) == 16)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strlen(p) == 16"), "../src/test/test-fileio.c" , 629, __PRETTY_FUNCTION__); } while (0); |
630 | assert_se(in_charset(p, "0123456789abcdef"))do { if ((__builtin_expect(!!(!(in_charset(p, "0123456789abcdef" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_charset(p, \"0123456789abcdef\")" ), "../src/test/test-fileio.c", 630, __PRETTY_FUNCTION__); } while (0); |
631 | free(ret); |
632 | } |
633 | |
634 | static const char buffer[] = |
635 | "Some test data\n" |
636 | "With newlines, and a NUL byte\0" |
637 | "\n" |
638 | "an empty line\n" |
639 | "an ignored line\n" |
640 | "and a very long line that is supposed to be truncated, because it is so long\n"; |
641 | |
642 | static void test_read_line_one_file(FILE *f) { |
643 | _cleanup_free___attribute__((cleanup(freep))) char *line = NULL((void*)0); |
644 | |
645 | assert_se(read_line(f, (size_t) -1, &line) == 15 && streq(line, "Some test data"))do { if ((__builtin_expect(!!(!(read_line(f, (size_t) -1, & line) == 15 && (strcmp((line),("Some test data")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, (size_t) -1, &line) == 15 && streq(line, \"Some test data\")" ), "../src/test/test-fileio.c", 645, __PRETTY_FUNCTION__); } while (0); |
646 | line = mfree(line); |
647 | |
648 | assert_se(read_line(f, 1024, &line) == 30 && streq(line, "With newlines, and a NUL byte"))do { if ((__builtin_expect(!!(!(read_line(f, 1024, &line) == 30 && (strcmp((line),("With newlines, and a NUL byte" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, 1024, &line) == 30 && streq(line, \"With newlines, and a NUL byte\")" ), "../src/test/test-fileio.c", 648, __PRETTY_FUNCTION__); } while (0); |
649 | line = mfree(line); |
650 | |
651 | assert_se(read_line(f, 1024, &line) == 1 && streq(line, ""))do { if ((__builtin_expect(!!(!(read_line(f, 1024, &line) == 1 && (strcmp((line),("")) == 0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("read_line(f, 1024, &line) == 1 && streq(line, \"\")" ), "../src/test/test-fileio.c", 651, __PRETTY_FUNCTION__); } while (0); |
652 | line = mfree(line); |
653 | |
654 | assert_se(read_line(f, 1024, &line) == 14 && streq(line, "an empty line"))do { if ((__builtin_expect(!!(!(read_line(f, 1024, &line) == 14 && (strcmp((line),("an empty line")) == 0))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, 1024, &line) == 14 && streq(line, \"an empty line\")" ), "../src/test/test-fileio.c", 654, __PRETTY_FUNCTION__); } while (0); |
655 | line = mfree(line); |
656 | |
657 | assert_se(read_line(f, (size_t) -1, NULL) == 16)do { if ((__builtin_expect(!!(!(read_line(f, (size_t) -1, ((void *)0)) == 16)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, (size_t) -1, NULL) == 16"), "../src/test/test-fileio.c" , 657, __PRETTY_FUNCTION__); } while (0); |
658 | |
659 | assert_se(read_line(f, 16, &line) == -ENOBUFS)do { if ((__builtin_expect(!!(!(read_line(f, 16, &line) == -105)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, 16, &line) == -ENOBUFS" ), "../src/test/test-fileio.c", 659, __PRETTY_FUNCTION__); } while (0); |
660 | line = mfree(line); |
661 | |
662 | /* read_line() stopped when it hit the limit, that means when we continue reading we'll read at the first |
663 | * character after the previous limit. Let's make use of tha to continue our test. */ |
664 | assert_se(read_line(f, 1024, &line) == 61 && streq(line, "line that is supposed to be truncated, because it is so long"))do { if ((__builtin_expect(!!(!(read_line(f, 1024, &line) == 61 && (strcmp((line),("line that is supposed to be truncated, because it is so long" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, 1024, &line) == 61 && streq(line, \"line that is supposed to be truncated, because it is so long\")" ), "../src/test/test-fileio.c", 664, __PRETTY_FUNCTION__); } while (0); |
665 | line = mfree(line); |
666 | |
667 | assert_se(read_line(f, 1024, &line) == 1 && streq(line, ""))do { if ((__builtin_expect(!!(!(read_line(f, 1024, &line) == 1 && (strcmp((line),("")) == 0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("read_line(f, 1024, &line) == 1 && streq(line, \"\")" ), "../src/test/test-fileio.c", 667, __PRETTY_FUNCTION__); } while (0); |
668 | line = mfree(line); |
669 | |
670 | assert_se(read_line(f, 1024, &line) == 0 && streq(line, ""))do { if ((__builtin_expect(!!(!(read_line(f, 1024, &line) == 0 && (strcmp((line),("")) == 0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("read_line(f, 1024, &line) == 0 && streq(line, \"\")" ), "../src/test/test-fileio.c", 670, __PRETTY_FUNCTION__); } while (0); |
671 | } |
672 | |
673 | static void test_read_line(void) { |
674 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
675 | |
676 | f = fmemopen((void*) buffer, sizeof(buffer), "re"); |
677 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 677, __PRETTY_FUNCTION__ ); } while (0); |
678 | |
679 | test_read_line_one_file(f); |
680 | } |
681 | |
682 | static void test_read_line2(void) { |
683 | _cleanup_(unlink_tempfilep)__attribute__((cleanup(unlink_tempfilep))) char name[] = "/tmp/test-fileio.XXXXXX"; |
684 | int fd; |
685 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
686 | |
687 | fd = mkostemp_safe(name); |
688 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fileio.c" , 688, __PRETTY_FUNCTION__); } while (0); |
689 | assert_se((size_t) write(fd, buffer, sizeof(buffer)) == sizeof(buffer))do { if ((__builtin_expect(!!(!((size_t) write(fd, buffer, sizeof (buffer)) == sizeof(buffer))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("(size_t) write(fd, buffer, sizeof(buffer)) == sizeof(buffer)" ), "../src/test/test-fileio.c", 689, __PRETTY_FUNCTION__); } while (0); |
690 | |
691 | assert_se(lseek(fd, 0, SEEK_SET) == 0)do { if ((__builtin_expect(!!(!(lseek(fd, 0, 0) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lseek(fd, 0, SEEK_SET) == 0"), "../src/test/test-fileio.c" , 691, __PRETTY_FUNCTION__); } while (0); |
692 | assert_se(f = fdopen(fd, "r"))do { if ((__builtin_expect(!!(!(f = fdopen(fd, "r"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f = fdopen(fd, \"r\")"), "../src/test/test-fileio.c" , 692, __PRETTY_FUNCTION__); } while (0); |
693 | |
694 | test_read_line_one_file(f); |
695 | } |
696 | |
697 | static void test_read_line3(void) { |
698 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
699 | _cleanup_free___attribute__((cleanup(freep))) char *line = NULL((void*)0); |
700 | int r; |
701 | |
702 | f = fopen("/proc/cmdline", "re"); |
703 | if (!f && IN_SET(errno, ENOENT, EPERM)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){2, 1})/sizeof(int)]; switch((*__errno_location ())) { case 2: case 1: _found = 1; break; default: break; } _found ; })) |
704 | return; |
705 | assert_se(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/test/test-fileio.c", 705, __PRETTY_FUNCTION__ ); } while (0); |
706 | |
707 | r = read_line(f, LINE_MAX2048, &line); |
708 | assert_se((size_t) r == strlen(line) + 1)do { if ((__builtin_expect(!!(!((size_t) r == strlen(line) + 1 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(size_t) r == strlen(line) + 1" ), "../src/test/test-fileio.c", 708, __PRETTY_FUNCTION__); } while (0); |
709 | assert_se(read_line(f, LINE_MAX, NULL) == 0)do { if ((__builtin_expect(!!(!(read_line(f, 2048, ((void*)0) ) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("read_line(f, LINE_MAX, NULL) == 0" ), "../src/test/test-fileio.c", 709, __PRETTY_FUNCTION__); } while (0); |
710 | } |
711 | |
712 | int main(int argc, char *argv[]) { |
713 | log_set_max_level(LOG_DEBUG)log_set_max_level_realm(LOG_REALM_SYSTEMD, (7)); |
714 | log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD); |
715 | log_open(); |
716 | |
717 | test_parse_env_file(); |
718 | test_parse_multiline_env_file(); |
719 | test_merge_env_file(); |
720 | test_merge_env_file_invalid(); |
721 | test_executable_is_script(); |
722 | test_status_field(); |
723 | test_capeff(); |
724 | test_write_string_stream(); |
725 | test_write_string_file(); |
726 | test_write_string_file_no_create(); |
727 | test_write_string_file_verify(); |
728 | test_load_env_file_pairs(); |
729 | test_search_and_fopen(); |
730 | test_search_and_fopen_nulstr(); |
731 | test_writing_tmpfile(); |
732 | test_tempfn(); |
733 | test_read_line(); |
734 | test_read_line2(); |
735 | test_read_line3(); |
736 | |
737 | return 0; |
738 | } |