_cleanup_fclose_ FILE *f = NULL;
char c;
- f = fmemopen((void*) chars, sizeof(chars), "re");
+ f = fmemopen_unlocked((void*) chars, sizeof(chars), "re");
assert_se(f);
for (unsigned i = 0; i < sizeof(chars); i++) {
line = mfree(line);
/* read_line() stopped when it hit the limit, that means when we continue reading we'll read at the first
- * character after the previous limit. Let's make use of tha to continue our test. */
+ * character after the previous limit. Let's make use of that to continue our test. */
assert_se(read_line(f, 1024, &line) == 62 && streq(line, "line that is supposed to be truncated, because it is so long"));
line = mfree(line);
static void test_read_line(void) {
_cleanup_fclose_ FILE *f = NULL;
- f = fmemopen((void*) buffer, sizeof(buffer), "re");
+ f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "re");
assert_se(f);
test_read_line_one_file(f);
assert_se(f);
r = read_line(f, LINE_MAX, &line);
- assert_se((size_t) r == strlen(line) + 1);
+ assert_se(r >= 0);
+ if (r == 0)
+ assert_se(line && isempty(line));
+ else
+ assert_se((size_t) r == strlen(line) + 1);
assert_se(read_line(f, LINE_MAX, NULL) == 0);
}
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *s = NULL;
- assert_se(f = fmemopen((void*) eof_endings[i].string, eof_endings[i].length, "r"));
+ assert_se(f = fmemopen_unlocked((void*) eof_endings[i].string, eof_endings[i].length, "r"));
r = read_line(f, (size_t) -1, &s);
assert_se((size_t) r == eof_endings[i].length);
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *s = NULL;
- assert_se(f = fmemopen((void*) test, sizeof(test)-1, "r"));
+ assert_se(f = fmemopen_unlocked((void*) test, sizeof(test)-1, "r"));
assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 13 && streq_ptr(s, "string nr. 1"));
s = mfree(s);