6 FILE *setmntent(const char *name, const char *mode)
8 return fopen(name, mode);
11 int endmntent(FILE *f)
17 struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
25 fgets(linebuf, buflen, f);
26 if (feof(f) || ferror(f)) return 0;
27 if (!strchr(linebuf, '\n')) {
28 if (fseeko(f, -(off_t)strlen(linebuf), SEEK_CUR))
29 fscanf(f, "%*[^\n]%*[\n]");
33 cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
34 n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
35 &mnt->mnt_freq, &mnt->mnt_passno);
36 } while (cnt < 2 || linebuf[n[0]] == '#');
43 mnt->mnt_fsname = linebuf+n[0];
44 mnt->mnt_dir = linebuf+n[2];
45 mnt->mnt_type = linebuf+n[4];
46 mnt->mnt_opts = linebuf+n[6];
51 struct mntent *getmntent(FILE *f)
53 static char linebuf[256];
54 static struct mntent mnt;
55 return getmntent_r(f, &mnt, linebuf, sizeof linebuf);
58 int addmntent(FILE *f, const struct mntent *mnt)
60 if (fseek(f, 0, SEEK_END)) return 1;
61 return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
62 mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
63 mnt->mnt_freq, mnt->mnt_passno) < 0;
66 char *hasmntopt(const struct mntent *mnt, const char *opt)
68 return strstr(mnt->mnt_opts, opt);