X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmisc%2Fmntent.c;h=eabb8200bf94d2b450971ff54d3951d365b939f9;hb=d88e5dfa8b989dafff4b748bfb3cba3512c8482e;hp=3eafba5e0b387ce98e0aefde2bbdaf8288757af9;hpb=b9bb8f67bbac9bab5314fb00974ad469476e936e;p=musl diff --git a/src/misc/mntent.c b/src/misc/mntent.c index 3eafba5e..eabb8200 100644 --- a/src/misc/mntent.c +++ b/src/misc/mntent.c @@ -3,6 +3,11 @@ #include #include +static char *internal_buf; +static size_t internal_bufsize; + +#define SENTINEL (char *)&internal_buf + FILE *setmntent(const char *name, const char *mode) { return fopen(name, mode); @@ -10,19 +15,24 @@ FILE *setmntent(const char *name, const char *mode) int endmntent(FILE *f) { - fclose(f); + if (f) fclose(f); return 1; } struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen) { - int cnt, n[8]; + int cnt, n[8], use_internal = (linebuf == SENTINEL); mnt->mnt_freq = 0; mnt->mnt_passno = 0; do { - fgets(linebuf, buflen, f); + if (use_internal) { + getline(&internal_buf, &internal_bufsize, f); + linebuf = internal_buf; + } else { + fgets(linebuf, buflen, f); + } if (feof(f) || ferror(f)) return 0; if (!strchr(linebuf, '\n')) { fscanf(f, "%*[^\n]%*[\n]"); @@ -49,9 +59,8 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle struct mntent *getmntent(FILE *f) { - static char linebuf[256]; static struct mntent mnt; - return getmntent_r(f, &mnt, linebuf, sizeof linebuf); + return getmntent_r(f, &mnt, SENTINEL, 0); } int addmntent(FILE *f, const struct mntent *mnt)