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 cnt
, n
[8], use_internal
= (linebuf
== SENTINEL
);
31 getline(&internal_buf
, &internal_bufsize
, f
);
32 linebuf
= internal_buf
;
34 fgets(linebuf
, buflen
, f
);
36 if (feof(f
) || ferror(f
)) return 0;
37 if (!strchr(linebuf
, '\n')) {
38 fscanf(f
, "%*[^\n]%*[\n]");
42 cnt
= sscanf(linebuf
, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
43 n
, n
+1, n
+2, n
+3, n
+4, n
+5, n
+6, n
+7,
44 &mnt
->mnt_freq
, &mnt
->mnt_passno
);
45 } while (cnt
< 2 || linebuf
[n
[0]] == '#');
52 mnt
->mnt_fsname
= linebuf
+n
[0];
53 mnt
->mnt_dir
= linebuf
+n
[2];
54 mnt
->mnt_type
= linebuf
+n
[4];
55 mnt
->mnt_opts
= linebuf
+n
[6];
60 struct mntent
*getmntent(FILE *f
)
62 static struct mntent mnt
;
63 return getmntent_r(f
, &mnt
, SENTINEL
, 0);
66 int addmntent(FILE *f
, const struct mntent
*mnt
)
68 if (fseek(f
, 0, SEEK_END
)) return 1;
69 return fprintf(f
, "%s\t%s\t%s\t%s\t%d\t%d\n",
70 mnt
->mnt_fsname
, mnt
->mnt_dir
, mnt
->mnt_type
, mnt
->mnt_opts
,
71 mnt
->mnt_freq
, mnt
->mnt_passno
) < 0;
74 char *hasmntopt(const struct mntent
*mnt
, const char *opt
)
76 return strstr(mnt
->mnt_opts
, opt
);