summaryrefslogtreecommitdiff
path: root/src/linux
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-05 14:11:14 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-05 14:11:14 -0400
commit2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a (patch)
tree9535dc1f44a0cd12ad4fdb629e986b3d8af608ab /src/linux
parente86cc888dfc8a413e52194887e90ea14d4e32cb5 (diff)
downloadmusl-2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a.tar.gz
musl-2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a.tar.bz2
musl-2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a.tar.xz
musl-2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a.zip
add getmntent_r interface (all of mntent is nonstandard anyway)
Diffstat (limited to 'src/linux')
-rw-r--r--src/linux/mntent.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/linux/mntent.c b/src/linux/mntent.c
index e3735666..26d045c2 100644
--- a/src/linux/mntent.c
+++ b/src/linux/mntent.c
@@ -13,21 +13,19 @@ int endmntent(FILE *f)
return 1;
}
-struct mntent *getmntent(FILE *f)
+struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
{
- static char linebuf[256];
- static struct mntent mnt;
int cnt, n[8];
- mnt.mnt_freq = 0;
- mnt.mnt_passno = 0;
+ mnt->mnt_freq = 0;
+ mnt->mnt_passno = 0;
do {
- fgets(linebuf, sizeof linebuf, f);
+ fgets(linebuf, buflen, f);
if (feof(f)) return NULL;
cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
- &mnt.mnt_freq, &mnt.mnt_passno);
+ &mnt->mnt_freq, &mnt->mnt_passno);
} while (cnt >= 8 && linebuf[n[0]] != '#');
linebuf[n[1]] = 0;
@@ -35,12 +33,19 @@ struct mntent *getmntent(FILE *f)
linebuf[n[5]] = 0;
linebuf[n[7]] = 0;
- mnt.mnt_fsname = linebuf+n[0];
- mnt.mnt_dir = linebuf+n[2];
- mnt.mnt_type = linebuf+n[4];
- mnt.mnt_opts = linebuf+n[6];
+ mnt->mnt_fsname = linebuf+n[0];
+ mnt->mnt_dir = linebuf+n[2];
+ mnt->mnt_type = linebuf+n[4];
+ mnt->mnt_opts = linebuf+n[6];
+
+ return mnt;
+}
- return &mnt;
+struct mntent *getmntent(FILE *f)
+{
+ static char linebuf[256];
+ static struct mntent mnt;
+ return getmntent_r(f, &mnt, linebuf, sizeof linebuf);
}
int addmntent(FILE *f, const struct mntent *mnt)