xref: /netbsd-src/usr.sbin/sesd/srcs/getnobj.c (revision 421949a31fb0942d3d87278998c2d7d432d8b3cb)
1*421949a3Ssevan /* $NetBSD: getnobj.c,v 1.4 2018/01/23 21:06:26 sevan Exp $ */
2f249807bSmjacob /* $FreeBSD: $ */
3f249807bSmjacob /* $OpenBSD: $ */
4f249807bSmjacob /*
5f249807bSmjacob  * Copyright (c) 2000 by Matthew Jacob
6f249807bSmjacob  * All rights reserved.
7f249807bSmjacob  *
8f249807bSmjacob  * Redistribution and use in source and binary forms, with or without
9f249807bSmjacob  * modification, are permitted provided that the following conditions
10f249807bSmjacob  * are met:
11f249807bSmjacob  * 1. Redistributions of source code must retain the above copyright
12f249807bSmjacob  *    notice, this list of conditions, and the following disclaimer,
13f249807bSmjacob  *    without modification, immediately at the beginning of the file.
14f249807bSmjacob  * 2. The name of the author may not be used to endorse or promote products
15f249807bSmjacob  *    derived from this software without specific prior written permission.
16f249807bSmjacob  *
17f249807bSmjacob  * Alternatively, this software may be distributed under the terms of the
18f249807bSmjacob  * the GNU Public License ("GPL").
19f249807bSmjacob  *
20f249807bSmjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21f249807bSmjacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22f249807bSmjacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23f249807bSmjacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24f249807bSmjacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25f249807bSmjacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26f249807bSmjacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27f249807bSmjacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28f249807bSmjacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29f249807bSmjacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30f249807bSmjacob  * SUCH DAMAGE.
31f249807bSmjacob  *
32f249807bSmjacob  * Matthew Jacob
33f249807bSmjacob  * Feral Software
34f249807bSmjacob  * mjacob@feral.com
35f249807bSmjacob  */
36f249807bSmjacob 
37f249807bSmjacob #include <stdlib.h>
38f249807bSmjacob #include <stdio.h>
39f249807bSmjacob #include <unistd.h>
40f249807bSmjacob #include <fcntl.h>
41f249807bSmjacob #include <sys/ioctl.h>
42f249807bSmjacob #include SESINC
43f249807bSmjacob 
44f249807bSmjacob int
main(int argc,char * argv[])45*421949a3Ssevan main(int argc, char *argv[])
46f249807bSmjacob {
47f249807bSmjacob 	unsigned int nobj;
48f249807bSmjacob 	int fd;
49f249807bSmjacob 
50f249807bSmjacob 	while (*++argv != NULL) {
51f249807bSmjacob 		char *name = *argv;
52f249807bSmjacob 		fd = open(name, O_RDONLY);
53f249807bSmjacob 		if (fd < 0) {
54f249807bSmjacob 			perror(name);
55f249807bSmjacob 			continue;
56f249807bSmjacob 		}
57f249807bSmjacob 		if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
58f249807bSmjacob 			perror("SESIOC_GETNOBJ");
59f249807bSmjacob 		} else {
60f249807bSmjacob 			fprintf(stdout, "%s: %d objects\n", name, nobj);
61f249807bSmjacob 		}
62f249807bSmjacob 		close (fd);
63f249807bSmjacob 	}
64f249807bSmjacob 	return (0);
65f249807bSmjacob }
66