4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
35 static int mntprtent(FILE *, struct mntent
*);
37 static struct mntent
*mntp
;
44 mntp
= (struct mntent
*)calloc(1, sizeof (struct mntent
));
51 unsigned char *cp
= (unsigned char *) *p
;
52 unsigned char *retstr
;
54 while (*cp
&& isspace(*cp
))
57 while (*cp
&& !isspace(*cp
))
64 return ((char *)retstr
);
71 unsigned char *cp
= (unsigned char *) *p
;
73 while (*cp
&& isspace(*cp
))
75 for (; *cp
&& isdigit(*cp
); cp
++) {
79 while (*cp
&& !isspace(*cp
))
90 mnttabscan(FILE *mnttabp
, struct mntent
*mnt
)
92 static char *line
= NULL
;
96 line
= (char *)malloc(BUFSIZ
+1);
98 cp
= fgets(line
, BUFSIZ
, mnttabp
);
102 } while (*cp
== '#');
103 mnt
->mnt_fsname
= mntstr(&cp
);
106 mnt
->mnt_dir
= mntstr(&cp
);
109 mnt
->mnt_type
= mntstr(&cp
);
112 mnt
->mnt_opts
= mntstr(&cp
);
115 mnt
->mnt_freq
= mntdigit(&cp
);
118 mnt
->mnt_passno
= mntdigit(&cp
);
123 setmntent(char *fname
, char *flag
)
127 if ((mnttabp
= fopen(fname
, flag
)) == NULL
) {
130 for (; *flag
; flag
++) {
131 if (*flag
== 'w' || *flag
== 'a' || *flag
== '+') {
132 if (flock(fileno(mnttabp
), LOCK_EX
) < 0) {
143 endmntent(FILE *mnttabp
)
153 getmntent(FILE *mnttabp
)
158 return ((struct mntent
*)0);
160 return ((struct mntent
*)0);
161 nfields
= mnttabscan(mnttabp
, mntp
);
162 if (nfields
== EOF
|| nfields
!= 6)
163 return ((struct mntent
*)0);
168 addmntent(FILE *mnttabp
, struct mntent
*mnt
)
170 if (fseek(mnttabp
, 0L, 2) < 0)
172 if (mnt
== (struct mntent
*)0)
174 if (mnt
->mnt_fsname
== NULL
|| mnt
->mnt_dir
== NULL
||
175 mnt
->mnt_type
== NULL
|| mnt
->mnt_opts
== NULL
)
178 mntprtent(mnttabp
, mnt
);
185 unsigned char *cp
= (unsigned char *) *p
;
186 unsigned char *retstr
;
188 while (*cp
&& isspace(*cp
))
191 while (*cp
&& *cp
!= ',')
198 return ((char *)retstr
);
202 hasmntopt(struct mntent
*mnt
, char *opt
)
205 static char *tmpopts
;
208 tmpopts
= (char *)calloc(256, sizeof (char));
212 strcpy(tmpopts
, mnt
->mnt_opts
);
215 for (; *f
; f
= mntopt(&opts
)) {
216 if (strncmp(opt
, f
, strlen(opt
)) == 0)
217 return (f
- tmpopts
+ mnt
->mnt_opts
);
223 mntprtent(FILE *mnttabp
, struct mntent
*mnt
)
225 fprintf(mnttabp
, "%s %s %s %s %d %d\n",