mailing list of musl libc
 help / color / mirror / code / Atom feed
2a30d1b8b8edc3cb41bf1e703c991580dd2dbcb2 blob 1787 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
// SPDX-License-Identifier: MIT

#define _DEFAULT_SOURCE // for getmntent_r

#include <errno.h>
#include <mntent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "test.h"

#define ASSERT(x) do {				 \
		if (!(x)) {			 \
			t_error(#x " failed\n"); \
			exit(EXIT_FAILURE);	 \
		}				 \
	} while (0);

#define ERR(fmt, ...) do {					       \
		t_error(fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); \
		exit(EXIT_FAILURE);				       \
	} while (0)

void test_getmntent_empty(void)
{
	char fstab[] = "\n";
	FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
	if (!f) ERR("fmemopen");
	ASSERT(!getmntent(f));
	ASSERT(endmntent(f) == 1);
}

void test_getmntent(void)
{
	// Checks that the fifth and sixth fields default to 0.
	char fstab[] = "none /proc proc defaults\n";
	FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
	if (!f) ERR("fmemopen");
	struct mntent *m = getmntent(f);
	ASSERT(m);
	ASSERT(!strcmp(m->mnt_fsname, "none"));
	ASSERT(!strcmp(m->mnt_dir, "/proc"));
	ASSERT(!strcmp(m->mnt_type, "proc"));
	ASSERT(!strcmp(m->mnt_opts, "defaults"));
	ASSERT(m->mnt_freq == 0);
	ASSERT(m->mnt_passno == 0);
	ASSERT(endmntent(f) == 1);
}

void test_getmntent_r(void)
{
	struct mntent m, *r;
	char fstab[] = "/dev/sda\t/\text4\trw,nosuid\t2\t1\n";
	char buf[sizeof(fstab)];

	FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
	if (!f) ERR("fmemopen");

	r = getmntent_r(f, &m, buf, sizeof buf);
	ASSERT(r == &m);
	ASSERT(!strcmp(m.mnt_fsname, "/dev/sda"));
	ASSERT(!strcmp(m.mnt_dir, "/"));
	ASSERT(!strcmp(m.mnt_type, "ext4"));
	ASSERT(!strcmp(m.mnt_opts, "rw,nosuid"));
	ASSERT(m.mnt_freq == 2);
	ASSERT(m.mnt_passno == 1);
	ASSERT(endmntent(f) == 1);
}

int main(void)
{
	test_getmntent_empty();
	test_getmntent();
	test_getmntent_r();
}
debug log:

solving 59d816a ...
found 59d816a in https://inbox.vuxu.org/musl/20210821085420.474615-2-hi@alyssa.is/ ||
	https://inbox.vuxu.org/musl/20210915221155.3977763-2-hi@alyssa.is/

applying [1/2] https://inbox.vuxu.org/musl/20210821085420.474615-2-hi@alyssa.is/
diff --git a/src/functional/mntent.c b/src/functional/mntent.c
new file mode 100644
index 0000000..59d816a

Checking patch src/functional/mntent.c...
Applied patch src/functional/mntent.c cleanly.

skipping https://inbox.vuxu.org/musl/20210915221155.3977763-2-hi@alyssa.is/ for 59d816a
index at:
100644 2a30d1b8b8edc3cb41bf1e703c991580dd2dbcb2	src/functional/mntent.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).