3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#) Copyright (c) 1993 The Regents of the University of California. All rights reserved.
34 * @(#)pathconf.c 8.1 (Berkeley) 6/6/93
35 * $FreeBSD: src/sbin/sysctl/pathconf.c,v 1.4 1999/08/28 00:14:30 peter Exp $
36 * $DragonFly: src/sbin/sysctl/pathconf.c,v 1.5 2004/12/18 22:43:46 swildner Exp $
39 #include <sys/param.h>
40 #include <sys/sysctl.h>
41 #include <sys/unistd.h>
52 { "link_max", CTLTYPE_INT }, \
53 { "max_canon", CTLTYPE_INT }, \
54 { "max_input", CTLTYPE_INT }, \
55 { "name_max", CTLTYPE_INT }, \
56 { "path_max", CTLTYPE_INT }, \
57 { "pipe_buf", CTLTYPE_INT }, \
58 { "chown_restricted", CTLTYPE_INT }, \
59 { "no_trunc", CTLTYPE_INT }, \
60 { "vdisable", CTLTYPE_INT }, \
64 struct ctlname pcnames
[] = PC_NAMES
;
71 struct list pclist
= { pcnames
, PC_MAXID
};
73 int Aflag
, aflag
, nflag
, wflag
, stdinflag
;
75 int findname(char *, char *, char**, struct list
*);
76 void listall(char *, struct list
*);
77 void parse(char *, char *, int);
78 static void usage(void);
81 main(int argc
, char **argv
)
86 while ((ch
= getopt(argc
, argv
, "Aan")) != -1) {
111 if (strcmp(path
, "-") == 0)
114 if (Aflag
|| aflag
) {
115 listall(path
, &pclist
);
121 parse(path
, *argv
, 1);
126 * List all variables known to the system.
129 listall(char *path
, struct list
*lp
)
135 for (lvl2
= 0; lvl2
< lp
->size
; lvl2
++) {
136 if (lp
->list
[lvl2
].ctl_name
== 0)
138 parse(path
, lp
->list
[lvl2
].ctl_name
, Aflag
);
143 * Parse a name into an index.
144 * Lookup and print out the attribute if it exists.
147 parse(char *pathname
, char *string
, int flags
)
150 char *bufp
, buf
[BUFSIZ
];
153 snprintf(buf
, BUFSIZ
, "%s", string
);
154 if ((indx
= findname(string
, "top", &bufp
, &pclist
)) == -1)
157 warnx("name %s in %s is unknown", *bufp
, string
);
161 value
= fpathconf(0, indx
);
163 value
= pathconf(pathname
, indx
);
169 warnx("%s: value is not available", string
);
172 warnx("%s: specification is incomplete", string
);
175 warnx("%s: type is unknown to this program", string
);
183 fprintf(stdout
, "%s = ", string
);
184 fprintf(stdout
, "%d\n", value
);
188 * Scan a list of names searching for a particular name.
191 findname(char *string
, char *level
, char **bufp
, struct list
*namelist
)
195 struct list
*namelist
;
200 if (namelist
->list
== 0 || (name
= strsep(bufp
, ".")) == NULL
) {
201 warnx("%s: incomplete specification", string
);
204 for (i
= 0; i
< namelist
->size
; i
++)
205 if (namelist
->list
[i
].ctl_name
!= NULL
&&
206 strcmp(name
, namelist
->list
[i
].ctl_name
) == 0)
208 if (i
== namelist
->size
) {
209 warnx("%s level name %s in %s is invalid", level
, name
, string
);
219 fprintf(stderr
, "%s\n%s\n%s\n",
220 "usage: pathname [-n] variable ...",
222 " pathname [-n] -A");