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.
12 libc_hidden_proto(strstr)
13 libc_hidden_proto(strtok_r)
14 libc_hidden_proto(atoi)
15 libc_hidden_proto(fopen)
16 libc_hidden_proto(fclose)
17 libc_hidden_proto(fseek)
18 libc_hidden_proto(fgets)
19 libc_hidden_proto(abort)
20 libc_hidden_proto(fprintf)
22 #ifdef __UCLIBC_HAS_THREADS__
24 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
26 #define LOCK __pthread_mutex_lock(&mylock)
27 #define UNLOCK __pthread_mutex_unlock(&mylock)
29 /* Reentrant version of getmntent. */
30 struct mntent *getmntent_r (FILE *filep,
31 struct mntent *mnt, char *buff, int bufsize)
34 const char *sep = " \t\n";
36 if (!filep || !mnt || !buff)
39 /* Loop on the file, skipping comment lines. - FvK 03/07/93 */
40 while ((cp = fgets(buff, bufsize, filep)) != NULL) {
41 if (buff[0] == '#' || buff[0] == '\n')
46 /* At the EOF, the buffer should be unchanged. We should
47 * check the return value from fgets ().
53 mnt->mnt_fsname = strtok_r(buff, sep, &ptrptr);
54 if (mnt->mnt_fsname == NULL)
57 mnt->mnt_dir = strtok_r(NULL, sep, &ptrptr);
58 if (mnt->mnt_dir == NULL)
61 mnt->mnt_type = strtok_r(NULL, sep, &ptrptr);
62 if (mnt->mnt_type == NULL)
65 mnt->mnt_opts = strtok_r(NULL, sep, &ptrptr);
66 if (mnt->mnt_opts == NULL)
69 cp = strtok_r(NULL, sep, &ptrptr);
70 mnt->mnt_freq = (cp != NULL) ? atoi(cp) : 0;
72 cp = strtok_r(NULL, sep, &ptrptr);
73 mnt->mnt_passno = (cp != NULL) ? atoi(cp) : 0;
77 libc_hidden_proto(getmntent_r)
78 libc_hidden_def(getmntent_r)
80 struct mntent *getmntent(FILE * filep)
83 static char *buff = NULL;
84 static struct mntent mnt;
88 buff = malloc(BUFSIZ);
93 tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
98 int addmntent(FILE * filep, const struct mntent *mnt)
100 if (fseek(filep, 0, SEEK_END) < 0)
103 if (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) < 1)
110 char *hasmntopt(const struct mntent *mnt, const char *opt)
112 return strstr(mnt->mnt_opts, opt);
115 FILE *setmntent(const char *name, const char *mode)
117 return fopen(name, mode);
119 libc_hidden_proto(setmntent)
120 libc_hidden_def(setmntent)
122 int endmntent(FILE * filep)
128 libc_hidden_proto(endmntent)
129 libc_hidden_def(endmntent)