extern int endmntent(FILE *fp);
extern char *hasmntopt(struct mntent *mnt, char *opt);
-/* Extended function found in some Unixen */
-extern int delmntent(FILE *fp, struct mntent *mnt);
+/* GNUism but useful and we provide it */
+extern struct mntent *getmntent_r(FILE *fp, struct mntent *mnt, char *buf, int len);
+/* Extended function found in some Unixen. Not yet supported */
+/*extern int delmntent(FILE *fp, struct mntent *mnt); */
#endif
if (fp == NULL)
return NULL;
if (strchr(type,'w') || strchr(type,'a'))
- lock = LOCK_SH;
- else
lock = LOCK_EX;
+ else
+ lock = LOCK_SH;
if (flock(fileno(fp), lock) == -1) {
fclose(fp);
return NULL;
static int mntparse(char *p, char **t, char *def)
{
char *d = strtok(p, " \t\n");
+ char *ds = d;
if (d == NULL)
d = def;
else {
}
}
if (t)
- *t = d;
- return atoi(d);
+ *t = ds;
+ return atoi(ds);
}
-struct mntent *getmntent(FILE * fp)
+struct mntent *getmntent_r(FILE * fp, struct mntent *me, char *buf, int len)
{
- static struct mntent me;
- char *p = mntbuf;
+ char *p = buf;
/* Skip blank lines and comments */
do {
- if (fgets(mntbuf, _MAX_MNTLEN, fp) == NULL)
+ if (fgets(buf, len, fp) == NULL)
return NULL;
} while(*p == '\n' || *p == '#');
- mntparse(mntbuf, &me.mnt_fsname, NULL);
- mntparse(NULL, &me.mnt_dir, NULL);
- mntparse(NULL, &me.mnt_type, "fuzix");
- mntparse(NULL, &me.mnt_opts, "");
- me.mnt_freq = mntparse(NULL, NULL, "0");
- me.mnt_passno = mntparse(NULL, NULL, "0");
- if (me.mnt_fsname == NULL || me.mnt_dir == NULL)
+ mntparse(buf, &me->mnt_fsname, NULL);
+ mntparse(NULL, &me->mnt_dir, NULL);
+ mntparse(NULL, &me->mnt_type, "fuzix");
+ mntparse(NULL, &me->mnt_opts, "");
+ me->mnt_freq = mntparse(NULL, NULL, "0");
+ me->mnt_passno = mntparse(NULL, NULL, "0");
+ if (me->mnt_fsname == NULL || me->mnt_dir == NULL)
return NULL;
- return &me;
+ return me;
+}
+
+struct mntent *getmntent(FILE * fp)
+{
+ static struct mntent me;
+ return getmntent_r(fp, &me, mntbuf, _MAX_MNTLEN);
}
void quote_out(char **p, char *s)
return;
while (t < mntbuf + _MAX_MNTLEN - 1) {
if (*s == 0) {
+ *t++ = ' ';
*p = t;
return;
}
quote_out_int(&p, mnt->mnt_freq);
quote_out_int(&p, mnt->mnt_passno);
if (p) {
- *p = '\n';
+ p[-1] = '\n';
if (fwrite(mntbuf, p - mntbuf, 1, fp) == 1)
return 0;
}