2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
11 #include <bits/uClibc_mutex.h>
13 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
17 /* Reentrant version of getmntent. */
18 struct mntent *getmntent_r (FILE *filep,
19 struct mntent *mnt, char *buff, int bufsize)
21 static const char sep[] = " \t\n";
25 if (!filep || !mnt || !buff)
28 /* Loop on the file, skipping comment lines. - FvK 03/07/93 */
29 while ((cp = fgets(buff, bufsize, filep)) != NULL) {
30 if (buff[0] == '#' || buff[0] == '\n')
35 /* At the EOF, the buffer should be unchanged. We should
36 * check the return value from fgets ().
42 mnt->mnt_fsname = strtok_r(buff, sep, &ptrptr);
43 if (mnt->mnt_fsname == NULL)
46 mnt->mnt_dir = strtok_r(NULL, sep, &ptrptr);
47 if (mnt->mnt_dir == NULL)
50 mnt->mnt_type = strtok_r(NULL, sep, &ptrptr);
51 if (mnt->mnt_type == NULL)
54 mnt->mnt_opts = strtok_r(NULL, sep, &ptrptr);
55 if (mnt->mnt_opts == NULL)
58 cp = strtok_r(NULL, sep, &ptrptr);
59 mnt->mnt_freq = (cp != NULL) ? atoi(cp) : 0;
61 cp = strtok_r(NULL, sep, &ptrptr);
62 mnt->mnt_passno = (cp != NULL) ? atoi(cp) : 0;
66 libc_hidden_def(getmntent_r)
68 struct mntent *getmntent(FILE * filep)
71 static char *buff = NULL;
72 static struct mntent mnt;
73 __UCLIBC_MUTEX_LOCK(mylock);
76 buff = malloc(BUFSIZ);
81 tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
82 __UCLIBC_MUTEX_UNLOCK(mylock);
86 int addmntent(FILE * filep, const struct mntent *mnt)
88 if (fseek(filep, 0, SEEK_END) < 0)
91 return (fprintf (filep, "%s %s %s %s %d %d\n", mnt->mnt_fsname, mnt->mnt_dir,
92 mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno) < 0 ? 1 : 0);
95 char *hasmntopt(const struct mntent *mnt, const char *opt)
97 return strstr(mnt->mnt_opts, opt);
100 FILE *setmntent(const char *name, const char *mode)
102 return fopen(name, mode);
104 libc_hidden_def(setmntent)
106 int endmntent(FILE * filep)
112 libc_hidden_def(endmntent)