From e077f341ca5758360b4c050c493a1d81b06c72a0 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sun, 6 Jan 2002 08:51:00 +0000 Subject: Support statvfs and statfs. Added getmntent_r (and made it use strtok_r instead of strtok), taught getmntent to use getmntent_r. -Erik --- libc/misc/mntent/mntent.c | 54 ++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'libc/misc/mntent') diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c index 9e8fda613..ea5cf23d8 100644 --- a/libc/misc/mntent/mntent.c +++ b/libc/misc/mntent/mntent.c @@ -4,15 +4,18 @@ #include - -struct mntent *getmntent(FILE * filep) +/* Reentrant version of the above function. */ +struct mntent *getmntent_r (FILE *filep, + struct mntent *mnt, char *buff, int bufsize) { char *cp, *sep = " \t\n"; - static char buff[BUFSIZ]; - static struct mntent mnt; + static char *ptrptr = 0; + + if (!filep || !mnt || !buff) + return NULL; /* Loop on the file, skipping comment lines. - FvK 03/07/93 */ - while ((cp = fgets(buff, sizeof buff, filep)) != NULL) { + while ((cp = fgets(buff, bufsize, filep)) != NULL) { if (buff[0] == '#' || buff[0] == '\n') continue; break; @@ -24,29 +27,42 @@ struct mntent *getmntent(FILE * filep) if (cp == NULL) return NULL; - mnt.mnt_fsname = strtok(buff, sep); - if (mnt.mnt_fsname == NULL) + ptrptr = 0; + mnt->mnt_fsname = strtok_r(buff, sep, &ptrptr); + if (mnt->mnt_fsname == NULL) return NULL; - mnt.mnt_dir = strtok(NULL, sep); - if (mnt.mnt_dir == NULL) + ptrptr = 0; + mnt->mnt_dir = strtok_r(NULL, sep, &ptrptr); + if (mnt->mnt_dir == NULL) return NULL; - mnt.mnt_type = strtok(NULL, sep); - if (mnt.mnt_type == NULL) + ptrptr = 0; + mnt->mnt_type = strtok_r(NULL, sep, &ptrptr); + if (mnt->mnt_type == NULL) return NULL; - mnt.mnt_opts = strtok(NULL, sep); - if (mnt.mnt_opts == NULL) - mnt.mnt_opts = ""; + ptrptr = 0; + mnt->mnt_opts = strtok_r(NULL, sep, &ptrptr); + if (mnt->mnt_opts == NULL) + mnt->mnt_opts = ""; - cp = strtok(NULL, sep); - mnt.mnt_freq = (cp != NULL) ? atoi(cp) : 0; + ptrptr = 0; + cp = strtok_r(NULL, sep, &ptrptr); + mnt->mnt_freq = (cp != NULL) ? atoi(cp) : 0; - cp = strtok(NULL, sep); - mnt.mnt_passno = (cp != NULL) ? atoi(cp) : 0; + ptrptr = 0; + cp = strtok_r(NULL, sep, &ptrptr); + mnt->mnt_passno = (cp != NULL) ? atoi(cp) : 0; - return &mnt; + return mnt; +} + +struct mntent *getmntent(FILE * filep) +{ + static char buff[BUFSIZ]; + static struct mntent mnt; + return(getmntent_r(filep, &mnt, buff, sizeof buff)); } int addmntent(FILE * filep, const struct mntent *mnt) -- cgit v1.2.3