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);
15 /* libc_hidden_proto(getmntent_r) */
16 /* libc_hidden_proto(setmntent) */
17 /* libc_hidden_proto(endmntent) */
19 /* Experimentally off - libc_hidden_proto(strstr) */
20 /* Experimentally off - libc_hidden_proto(strtok_r) */
21 /* libc_hidden_proto(atoi) */
22 /* libc_hidden_proto(fopen) */
23 /* libc_hidden_proto(fclose) */
24 /* libc_hidden_proto(fseek) */
25 /* libc_hidden_proto(fgets) */
26 /* libc_hidden_proto(abort) */
27 /* libc_hidden_proto(fprintf) */
29 /* Reentrant version of getmntent. */
30 struct mntent *getmntent_r (FILE *filep,
31 struct mntent *mnt, char *buff, int bufsize)
33 static const char sep[] = " \t\n";
37 if (!filep || !mnt || !buff)
40 /* Loop on the file, skipping comment lines. - FvK 03/07/93 */
41 while ((cp = fgets(buff, bufsize, filep)) != NULL) {
42 if (buff[0] == '#' || buff[0] == '\n')
47 /* At the EOF, the buffer should be unchanged. We should
48 * check the return value from fgets ().
54 mnt->mnt_fsname = strtok_r(buff, sep, &ptrptr);
55 if (mnt->mnt_fsname == NULL)
58 mnt->mnt_dir = strtok_r(NULL, sep, &ptrptr);
59 if (mnt->mnt_dir == NULL)
62 mnt->mnt_type = strtok_r(NULL, sep, &ptrptr);
63 if (mnt->mnt_type == NULL)
66 mnt->mnt_opts = strtok_r(NULL, sep, &ptrptr);
67 if (mnt->mnt_opts == NULL)
70 cp = strtok_r(NULL, sep, &ptrptr);
71 mnt->mnt_freq = (cp != NULL) ? atoi(cp) : 0;
73 cp = strtok_r(NULL, sep, &ptrptr);
74 mnt->mnt_passno = (cp != NULL) ? atoi(cp) : 0;
78 libc_hidden_def(getmntent_r)
80 struct mntent *getmntent(FILE * filep)
83 static char *buff = NULL;
84 static struct mntent mnt;
85 __UCLIBC_MUTEX_LOCK(mylock);
88 buff = malloc(BUFSIZ);
93 tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
94 __UCLIBC_MUTEX_UNLOCK(mylock);
98 int addmntent(FILE * filep, const struct mntent *mnt)
100 if (fseek(filep, 0, SEEK_END) < 0)
103 return (fprintf (filep, "%s %s %s %s %d %d\n", mnt->mnt_fsname, mnt->mnt_dir,
104 mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno) < 0 ? 1 : 0);
107 char *hasmntopt(const struct mntent *mnt, const char *opt)
109 return strstr(mnt->mnt_opts, opt);
112 FILE *setmntent(const char *name, const char *mode)
114 return fopen(name, mode);
116 libc_hidden_def(setmntent)
118 int endmntent(FILE * filep)
124 libc_hidden_def(endmntent)