OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / misc / mntent / mntent.c
1 /*
2  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <mntent.h>
11 #include <bits/uClibc_mutex.h>
12
13 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
14
15 /* libc_hidden_proto(getmntent_r) */
16 /* libc_hidden_proto(setmntent) */
17 /* libc_hidden_proto(endmntent) */
18
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) */
28
29 /* Reentrant version of getmntent.  */
30 struct mntent *getmntent_r (FILE *filep,
31         struct mntent *mnt, char *buff, int bufsize)
32 {
33         static const char sep[] = " \t\n";
34
35         char *cp, *ptrptr;
36
37         if (!filep || !mnt || !buff)
38             return NULL;
39
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')
43                         continue;
44                 break;
45         }
46
47         /* At the EOF, the buffer should be unchanged. We should
48          * check the return value from fgets ().
49          */
50         if (cp == NULL)
51                 return NULL;
52
53         ptrptr = 0;
54         mnt->mnt_fsname = strtok_r(buff, sep, &ptrptr);
55         if (mnt->mnt_fsname == NULL)
56                 return NULL;
57
58         mnt->mnt_dir = strtok_r(NULL, sep, &ptrptr);
59         if (mnt->mnt_dir == NULL)
60                 return NULL;
61
62         mnt->mnt_type = strtok_r(NULL, sep, &ptrptr);
63         if (mnt->mnt_type == NULL)
64                 return NULL;
65
66         mnt->mnt_opts = strtok_r(NULL, sep, &ptrptr);
67         if (mnt->mnt_opts == NULL)
68                 mnt->mnt_opts = "";
69
70         cp = strtok_r(NULL, sep, &ptrptr);
71         mnt->mnt_freq = (cp != NULL) ? atoi(cp) : 0;
72
73         cp = strtok_r(NULL, sep, &ptrptr);
74         mnt->mnt_passno = (cp != NULL) ? atoi(cp) : 0;
75
76         return mnt;
77 }
78 libc_hidden_def(getmntent_r)
79
80 struct mntent *getmntent(FILE * filep)
81 {
82     struct mntent *tmp;
83     static char *buff = NULL;
84     static struct mntent mnt;
85     __UCLIBC_MUTEX_LOCK(mylock);
86
87     if (!buff) {
88             buff = malloc(BUFSIZ);
89                 if (!buff)
90                     abort();
91     }
92
93     tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
94     __UCLIBC_MUTEX_UNLOCK(mylock);
95     return(tmp);
96 }
97
98 int addmntent(FILE * filep, const struct mntent *mnt)
99 {
100         if (fseek(filep, 0, SEEK_END) < 0)
101                 return 1;
102
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);
105 }
106
107 char *hasmntopt(const struct mntent *mnt, const char *opt)
108 {
109         return strstr(mnt->mnt_opts, opt);
110 }
111
112 FILE *setmntent(const char *name, const char *mode)
113 {
114         return fopen(name, mode);
115 }
116 libc_hidden_def(setmntent)
117
118 int endmntent(FILE * filep)
119 {
120         if (filep != NULL)
121                 fclose(filep);
122         return 1;
123 }
124 libc_hidden_def(endmntent)