5 FILE *setmntent(const char *name, const char *mode)
7 return fopen(name, mode);
10 int endmntent(FILE *f)
16 struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
24 fgets(linebuf, buflen, f);
25 if (feof(f)) return NULL;
26 cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
27 n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
28 &mnt->mnt_freq, &mnt->mnt_passno);
29 } while (cnt < 2 || linebuf[n[0]] == '#');
36 mnt->mnt_fsname = linebuf+n[0];
37 mnt->mnt_dir = linebuf+n[2];
38 mnt->mnt_type = linebuf+n[4];
39 mnt->mnt_opts = linebuf+n[6];
44 struct mntent *getmntent(FILE *f)
46 static char linebuf[256];
47 static struct mntent mnt;
48 return getmntent_r(f, &mnt, linebuf, sizeof linebuf);
51 int addmntent(FILE *f, const struct mntent *mnt)
53 fseek(f, 0, SEEK_END);
54 return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
55 mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
56 mnt->mnt_freq, mnt->mnt_passno) < 0;
59 char *hasmntopt(const struct mntent *mnt, const char *opt)
61 return strstr(mnt->mnt_opts, opt);