Skip to content

Commit 2d1f9f3

Browse files
committed
make the code includable into other programs:
* make static all symbols which do not need to be exported * rename main() to mount_FOO() * new main() now just calls mount_FOO(), main() is only compiled in if MOUNT_NOMAIN is not defined * a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local versions removed
1 parent 3075e83 commit 2d1f9f3

File tree

22 files changed

+442
-354
lines changed

22 files changed

+442
-354
lines changed

sbin/mount/fattr.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* $NetBSD: fattr.c,v 1.1 2000/10/30 20:56:57 jdolecek Exp $ */
2+
3+
/*-
4+
* Copyright (c) 2000 The NetBSD Foundation, Inc.
5+
* All rights reserved.
6+
*
7+
* This code is derived from software contributed to The NetBSD Foundation
8+
* by Scott Telford <s.telford@ed.ac.uk>.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
* 3. All advertising materials mentioning features or use of this software
19+
* must display the following acknowledgement:
20+
* This product includes software developed by the NetBSD
21+
* Foundation, Inc. and its contributors.
22+
* 4. Neither the name of The NetBSD Foundation nor the names of its
23+
* contributors may be used to endorse or promote products derived
24+
* from this software without specific prior written permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
* POSSIBILITY OF SUCH DAMAGE.
37+
*/
38+
39+
#include <sys/cdefs.h>
40+
#ifndef lint
41+
__RCSID("$NetBSD: fattr.c,v 1.1 2000/10/30 20:56:57 jdolecek Exp $");
42+
#endif /* not lint */
43+
44+
#include <sys/cdefs.h>
45+
#include <sys/param.h>
46+
#include <sys/mount.h>
47+
#include <sys/stat.h>
48+
#include <ctype.h>
49+
#include <err.h>
50+
#include <grp.h>
51+
#include <pwd.h>
52+
#include <stdio.h>
53+
#include <stdlib.h>
54+
#include <string.h>
55+
#include <unistd.h>
56+
57+
#include "fattr.h"
58+
59+
gid_t
60+
a_gid(s)
61+
char *s;
62+
{
63+
struct group *gr;
64+
char *gname;
65+
gid_t gid;
66+
67+
if ((gr = getgrnam(s)) != NULL)
68+
gid = gr->gr_gid;
69+
else {
70+
for (gname = s; *s && isdigit(*s); ++s);
71+
if (!*s)
72+
gid = atoi(gname);
73+
else
74+
errx(1, "unknown group id: %s", gname);
75+
}
76+
return (gid);
77+
}
78+
79+
uid_t
80+
a_uid(s)
81+
char *s;
82+
{
83+
struct passwd *pw;
84+
char *uname;
85+
uid_t uid;
86+
87+
if ((pw = getpwnam(s)) != NULL)
88+
uid = pw->pw_uid;
89+
else {
90+
for (uname = s; *s && isdigit(*s); ++s);
91+
if (!*s)
92+
uid = atoi(uname);
93+
else
94+
errx(1, "unknown user id: %s", uname);
95+
}
96+
return (uid);
97+
}
98+
99+
mode_t
100+
a_mask(s)
101+
char *s;
102+
{
103+
int done, rv;
104+
char *ep;
105+
106+
done = 0;
107+
rv = -1;
108+
if (*s >= '0' && *s <= '7') {
109+
done = 1;
110+
rv = strtol(optarg, &ep, 8);
111+
}
112+
if (!done || rv < 0 || *ep)
113+
errx(1, "invalid file mode: %s", s);
114+
return (rv);
115+
}

sbin/mount/fattr.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* $NetBSD: fattr.h,v 1.1 2000/10/30 20:56:58 jdolecek Exp $ */
2+
3+
/*-
4+
* Copyright (c) 2000 The NetBSD Foundation, Inc.
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
* 3. All advertising materials mentioning features or use of this software
16+
* must display the following acknowledgement:
17+
* This product includes software developed by the NetBSD
18+
* Foundation, Inc. and its contributors.
19+
* 4. Neither the name of The NetBSD Foundation nor the names of its
20+
* contributors may be used to endorse or promote products derived
21+
* from this software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
* POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
gid_t a_gid __P((char *));
37+
uid_t a_uid __P((char *));
38+
mode_t a_mask __P((char *));

sbin/mount_ados/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# $NetBSD: Makefile,v 1.8 1998/03/01 02:20:11 fvdl Exp $
1+
# $NetBSD: Makefile,v 1.9 2000/10/30 20:56:58 jdolecek Exp $
22

33
PROG= mount_ados
4-
SRCS= mount_ados.c getmntopts.c
4+
SRCS= mount_ados.c getmntopts.c fattr.c
55
MAN= mount_ados.8
66

77
MOUNT= ${.CURDIR}/../mount

sbin/mount_ados/mount_ados.c

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: mount_ados.c,v 1.11 2000/06/14 17:25:26 cgd Exp $ */
1+
/* $NetBSD: mount_ados.c,v 1.12 2000/10/30 20:56:58 jdolecek Exp $ */
22

33
/*
44
* Copyright (c) 1994 Christopher G. Demetriou
@@ -36,7 +36,7 @@
3636

3737
#include <sys/cdefs.h>
3838
#ifndef lint
39-
__RCSID("$NetBSD: mount_ados.c,v 1.11 2000/06/14 17:25:26 cgd Exp $");
39+
__RCSID("$NetBSD: mount_ados.c,v 1.12 2000/10/30 20:56:58 jdolecek Exp $");
4040
#endif /* not lint */
4141

4242
#include <sys/cdefs.h>
@@ -55,20 +55,27 @@ __RCSID("$NetBSD: mount_ados.c,v 1.11 2000/06/14 17:25:26 cgd Exp $");
5555
#include <adosfs/adosfs.h>
5656

5757
#include "mntopts.h"
58+
#include <fattr.h>
5859

59-
const struct mntopt mopts[] = {
60+
static const struct mntopt mopts[] = {
6061
MOPT_STDOPTS,
6162
{ NULL }
6263
};
6364

64-
gid_t a_gid __P((char *));
65-
uid_t a_uid __P((char *));
66-
mode_t a_mask __P((char *));
6765
int main __P((int, char *[]));
68-
void usage __P((void));
66+
int mount_ados __P((int argc, char **argv));
67+
static void usage __P((void));
6968

69+
#ifndef MOUNT_NOMAIN
7070
int
71-
main(argc, argv)
71+
main(int argc, char **argv)
72+
{
73+
return mount_ados(argc, argv);
74+
}
75+
#endif
76+
77+
int
78+
mount_ados(argc, argv)
7279
int argc;
7380
char **argv;
7481
{
@@ -143,65 +150,7 @@ main(argc, argv)
143150
exit (0);
144151
}
145152

146-
gid_t
147-
a_gid(s)
148-
char *s;
149-
{
150-
struct group *gr;
151-
char *gname;
152-
gid_t gid;
153-
154-
if ((gr = getgrnam(s)) != NULL)
155-
gid = gr->gr_gid;
156-
else {
157-
for (gname = s; *s && isdigit(*s); ++s);
158-
if (!*s)
159-
gid = atoi(gname);
160-
else
161-
errx(1, "unknown group id: %s", gname);
162-
}
163-
return (gid);
164-
}
165-
166-
uid_t
167-
a_uid(s)
168-
char *s;
169-
{
170-
struct passwd *pw;
171-
char *uname;
172-
uid_t uid;
173-
174-
if ((pw = getpwnam(s)) != NULL)
175-
uid = pw->pw_uid;
176-
else {
177-
for (uname = s; *s && isdigit(*s); ++s);
178-
if (!*s)
179-
uid = atoi(uname);
180-
else
181-
errx(1, "unknown user id: %s", uname);
182-
}
183-
return (uid);
184-
}
185-
186-
mode_t
187-
a_mask(s)
188-
char *s;
189-
{
190-
int done, rv;
191-
char *ep;
192-
193-
done = 0;
194-
rv = -1;
195-
if (*s >= '0' && *s <= '7') {
196-
done = 1;
197-
rv = strtol(optarg, &ep, 8);
198-
}
199-
if (!done || rv < 0 || *ep)
200-
errx(1, "invalid file mode: %s", s);
201-
return (rv);
202-
}
203-
204-
void
153+
static void
205154
usage()
206155
{
207156

sbin/mount_cd9660/mount_cd9660.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: mount_cd9660.c,v 1.13 2000/07/15 21:40:43 jdolecek Exp $ */
1+
/* $NetBSD: mount_cd9660.c,v 1.14 2000/10/30 20:56:58 jdolecek Exp $ */
22

33
/*
44
* Copyright (c) 1992, 1993, 1994
@@ -50,7 +50,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
5050
#if 0
5151
static char sccsid[] = "@(#)mount_cd9660.c 8.7 (Berkeley) 5/1/95";
5252
#else
53-
__RCSID("$NetBSD: mount_cd9660.c,v 1.13 2000/07/15 21:40:43 jdolecek Exp $");
53+
__RCSID("$NetBSD: mount_cd9660.c,v 1.14 2000/10/30 20:56:58 jdolecek Exp $");
5454
#endif
5555
#endif /* not lint */
5656

@@ -67,7 +67,7 @@ __RCSID("$NetBSD: mount_cd9660.c,v 1.13 2000/07/15 21:40:43 jdolecek Exp $");
6767

6868
#include "mntopts.h"
6969

70-
const struct mntopt mopts[] = {
70+
static const struct mntopt mopts[] = {
7171
MOPT_STDOPTS,
7272
MOPT_UPDATE,
7373
{ "extatt", 0, ISOFSMNT_EXTATT, 1 },
@@ -81,12 +81,23 @@ const struct mntopt mopts[] = {
8181
};
8282

8383
int main __P((int, char *[]));
84-
void usage __P((void));
84+
int mount_cd9660 __P((int argc, char **argv));
85+
static void usage __P((void));
8586

87+
#ifndef MOUNT_NOMAIN
8688
int
8789
main(argc, argv)
8890
int argc;
8991
char **argv;
92+
{
93+
return mount_cd9660(argc, argv);
94+
}
95+
#endif
96+
97+
int
98+
mount_cd9660(argc, argv)
99+
int argc;
100+
char **argv;
90101
{
91102
struct iso_args args;
92103
int ch, mntflags, opts;
@@ -146,7 +157,7 @@ main(argc, argv)
146157
exit(0);
147158
}
148159

149-
void
160+
static void
150161
usage()
151162
{
152163
(void)fprintf(stderr,

sbin/mount_ext2fs/mount_ext2fs.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: mount_ext2fs.c,v 1.7 2000/04/14 06:03:39 simonb Exp $ */
1+
/* $NetBSD: mount_ext2fs.c,v 1.8 2000/10/30 20:56:58 jdolecek Exp $ */
22

33
/*-
44
* Copyright (c) 1993, 1994
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1993, 1994\n\
4343
#if 0
4444
static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95";
4545
#else
46-
__RCSID("$NetBSD: mount_ext2fs.c,v 1.7 2000/04/14 06:03:39 simonb Exp $");
46+
__RCSID("$NetBSD: mount_ext2fs.c,v 1.8 2000/10/30 20:56:58 jdolecek Exp $");
4747
#endif
4848
#endif /* not lint */
4949

@@ -61,8 +61,9 @@ __RCSID("$NetBSD: mount_ext2fs.c,v 1.7 2000/04/14 06:03:39 simonb Exp $");
6161

6262
#include "mntopts.h"
6363

64-
void ext2fs_usage __P((void));
64+
static void ext2fs_usage __P((void));
6565
int main __P((int, char *[]));
66+
int mount_ext2fs __P((int argc, char **argv));
6667

6768
static const struct mntopt mopts[] = {
6869
MOPT_STDOPTS,
@@ -75,10 +76,20 @@ static const struct mntopt mopts[] = {
7576
{ NULL }
7677
};
7778

79+
#ifndef MOUNT_NOMAIN
7880
int
7981
main(argc, argv)
8082
int argc;
8183
char *argv[];
84+
{
85+
return mount_ext2fs(argc, argv);
86+
}
87+
#endif
88+
89+
int
90+
mount_ext2fs(argc, argv)
91+
int argc;
92+
char *argv[];
8293
{
8394
struct ufs_args args; /* XXX ffs_args */
8495
int ch, mntflags;
@@ -133,7 +144,7 @@ main(argc, argv)
133144
exit(0);
134145
}
135146

136-
void
147+
static void
137148
ext2fs_usage()
138149
{
139150
(void)fprintf(stderr,

0 commit comments

Comments
 (0)