finish unifying thread register handling in preparation for porting
[musl] / src / linux / mntent.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <mntent.h>
4
5 FILE *setmntent(const char *name, const char *mode)
6 {
7         return fopen(name, mode);
8 }
9
10 int endmntent(FILE *f)
11 {
12         fclose(f);
13         return 1;
14 }
15
16 struct mntent *getmntent(FILE *f)
17 {
18         static char linebuf[256];
19         static struct mntent mnt;
20         int cnt, n[8];
21
22         mnt.mnt_freq = 0;
23         mnt.mnt_passno = 0;
24
25         do {
26                 fgets(linebuf, sizeof linebuf, f);
27                 if (feof(f)) return NULL;
28                 cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
29                         n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
30                         &mnt.mnt_freq, &mnt.mnt_passno);
31         } while (cnt >= 8 && linebuf[n[0]] != '#');
32
33         linebuf[n[1]] = 0;
34         linebuf[n[3]] = 0;
35         linebuf[n[5]] = 0;
36         linebuf[n[7]] = 0;
37
38         mnt.mnt_fsname = linebuf+n[0];
39         mnt.mnt_dir = linebuf+n[2];
40         mnt.mnt_type = linebuf+n[4];
41         mnt.mnt_opts = linebuf+n[6];
42
43         return &mnt;
44 }
45
46 int addmntent(FILE *f, const struct mntent *mnt)
47 {
48         fseek(f, 0, SEEK_END);
49         return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
50                 mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
51                 mnt->mnt_freq, mnt->mnt_passno) < 0;
52 }
53
54 char *hasmntopt(const struct mntent *mnt, const char *opt)
55 {
56         return strstr(mnt->mnt_opts, opt);
57 }