6 static char *internal_buf;
7 static size_t internal_bufsize;
9 #define SENTINEL (char *)&internal_buf
11 FILE *setmntent(const char *name, const char *mode)
13 return fopen(name, mode);
16 int endmntent(FILE *f)
22 struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
24 int n[8], use_internal = (linebuf == SENTINEL);
32 getline(&internal_buf, &internal_bufsize, f);
33 linebuf = internal_buf;
35 fgets(linebuf, buflen, f);
37 if (feof(f) || ferror(f)) return 0;
38 if (!strchr(linebuf, '\n')) {
39 fscanf(f, "%*[^\n]%*[\n]");
44 len = strlen(linebuf);
45 for (i = 0; i < sizeof n / sizeof *n; i++) n[i] = len;
46 sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
47 n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
48 &mnt->mnt_freq, &mnt->mnt_passno);
49 } while (linebuf[n[0]] == '#' || n[1]==len);
56 mnt->mnt_fsname = linebuf+n[0];
57 mnt->mnt_dir = linebuf+n[2];
58 mnt->mnt_type = linebuf+n[4];
59 mnt->mnt_opts = linebuf+n[6];
64 struct mntent *getmntent(FILE *f)
66 static struct mntent mnt;
67 return getmntent_r(f, &mnt, SENTINEL, 0);
70 int addmntent(FILE *f, const struct mntent *mnt)
72 if (fseek(f, 0, SEEK_END)) return 1;
73 return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
74 mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
75 mnt->mnt_freq, mnt->mnt_passno) < 0;
78 char *hasmntopt(const struct mntent *mnt, const char *opt)
80 return strstr(mnt->mnt_opts, opt);