mailing list of musl libc
 help / color / mirror / code / Atom feed
085ce45d19de7ce3f27555a879de641589477e0c blob 2038 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
#include <stdio.h>
#include <string.h>
#include <mntent.h>
#include <errno.h>

static char *internal_buf;
static size_t internal_bufsize;

#define SENTINEL (char *)&internal_buf

FILE *setmntent(const char *name, const char *mode)
{
	return fopen(name, mode);
}

int endmntent(FILE *f)
{
	if (f) fclose(f);
	return 1;
}

struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
{
	int use_internal = (linebuf == SENTINEL);
	char *sub;

	do {
		char *end_ptr;

		if (use_internal) {
			getline(&internal_buf, &internal_bufsize, f);
			linebuf = internal_buf;
		} else {
			fgets(linebuf, buflen, f);
		}
		if (feof(f) || ferror(f)) return 0;

		end_ptr = strchr(linebuf, '\n');
		if (end_ptr != NULL) {
			while ((end_ptr[-1] == ' ' || end_ptr[-1] == '\t') && end_ptr != linebuf) end_ptr--;
			*end_ptr = '\0';
		} else {
			fscanf(f, "%*[^\n]%*[\n]");
			errno = ERANGE;
		}

		linebuf += strspn(linebuf, " \t");
	} while (linebuf[0] == '\0' || linebuf[0] == '#');

	mnt->mnt_fsname = strsep(&linebuf, " \t");

	if (linebuf) linebuf += strspn(linebuf, " \t");
	sub = strsep(&linebuf, " \t");
	mnt->mnt_dir = sub ? sub : (char *) "";

	if (linebuf) linebuf += strspn(linebuf, " \t");
	sub = strsep (&linebuf, " \t");
	mnt->mnt_type = sub ? sub : (char *) "";

	if (linebuf) linebuf += strspn(linebuf, " \t");
	sub = strsep(&linebuf, " \t");
	mnt->mnt_opts = sub ? sub : (char *) "";

	switch (linebuf ? sscanf(linebuf, " %d %d", &mnt->mnt_freq, &mnt->mnt_passno) : 0) {
	case 0: mnt->mnt_freq = 0;
	case 1: mnt->mnt_passno = 0;
	case 2: break;
	}

	return mnt;
}

struct mntent *getmntent(FILE *f)
{
	static struct mntent mnt;
	return getmntent_r(f, &mnt, SENTINEL, 0);
}

int addmntent(FILE *f, const struct mntent *mnt)
{
	if (fseek(f, 0, SEEK_END)) return 1;
	return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
		mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
		mnt->mnt_freq, mnt->mnt_passno) < 0;
}

char *hasmntopt(const struct mntent *mnt, const char *opt)
{
	return strstr(mnt->mnt_opts, opt);
}
debug log:

solving 085ce45d ...
found 085ce45d in https://inbox.vuxu.org/musl/20211015122000.2490-1-kaihang.zhang@smartx.com/
found eabb8200 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 eabb8200bf94d2b450971ff54d3951d365b939f9	src/misc/mntent.c

applying [1/1] https://inbox.vuxu.org/musl/20211015122000.2490-1-kaihang.zhang@smartx.com/
diff --git a/src/misc/mntent.c b/src/misc/mntent.c
index eabb8200..085ce45d 100644

warning: core.fsyncObjectFiles is deprecated; use core.fsync instead
Checking patch src/misc/mntent.c...
Applied patch src/misc/mntent.c cleanly.

index at:
100644 085ce45d19de7ce3f27555a879de641589477e0c	src/misc/mntent.c

Code repositories for project(s) associated with this 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).