7 static char *internal_buf
;
8 static size_t internal_bufsize
;
10 #define SENTINEL (char *)&internal_buf
12 FILE *setmntent(const char *name
, const char *mode
)
14 return fopen(name
, mode
);
17 int endmntent(FILE *f
)
23 struct mntent
*getmntent_r(FILE *f
, struct mntent
*mnt
, char *linebuf
, int buflen
)
25 int n
[8], use_internal
= (linebuf
== SENTINEL
);
33 getline(&internal_buf
, &internal_bufsize
, f
);
34 linebuf
= internal_buf
;
36 fgets(linebuf
, buflen
, f
);
38 if (feof(f
) || ferror(f
)) return 0;
39 if (!strchr(linebuf
, '\n')) {
40 fscanf(f
, "%*[^\n]%*[\n]");
45 len
= strlen(linebuf
);
46 if (len
> INT_MAX
) continue;
47 for (i
= 0; i
< sizeof n
/ sizeof *n
; i
++) n
[i
] = len
;
48 sscanf(linebuf
, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
49 n
, n
+1, n
+2, n
+3, n
+4, n
+5, n
+6, n
+7,
50 &mnt
->mnt_freq
, &mnt
->mnt_passno
);
51 } while (linebuf
[n
[0]] == '#' || n
[1]==len
);
58 mnt
->mnt_fsname
= linebuf
+n
[0];
59 mnt
->mnt_dir
= linebuf
+n
[2];
60 mnt
->mnt_type
= linebuf
+n
[4];
61 mnt
->mnt_opts
= linebuf
+n
[6];
66 struct mntent
*getmntent(FILE *f
)
68 static struct mntent mnt
;
69 return getmntent_r(f
, &mnt
, SENTINEL
, 0);
72 int addmntent(FILE *f
, const struct mntent
*mnt
)
74 if (fseek(f
, 0, SEEK_END
)) return 1;
75 return fprintf(f
, "%s\t%s\t%s\t%s\t%d\t%d\n",
76 mnt
->mnt_fsname
, mnt
->mnt_dir
, mnt
->mnt_type
, mnt
->mnt_opts
,
77 mnt
->mnt_freq
, mnt
->mnt_passno
) < 0;
80 char *hasmntopt(const struct mntent
*mnt
, const char *opt
)
82 return strstr(mnt
->mnt_opts
, opt
);