xref: /netbsd-src/lib/libc/gen/getdevmajor.3 (revision 01869ca4d24a86379a68731bf9706a9f0820fe4e)
1.\"	$NetBSD: getdevmajor.3,v 1.6 2017/07/03 21:32:49 wiz Exp $
2.\"
3.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Andrew Brown.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. 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.
20.\"
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
31.\" SUCH DAMAGE.
32.\"
33.Dd January 20, 2009
34.Dt GETDEVMAJOR 3
35.Os
36.Sh NAME
37.Nm getdevmajor
38.Nd get block or character device major number
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In stdlib.h
43.In sys/stat.h
44.Ft devmajor_t
45.Fn getdevmajor "const char *name" "mode_t type"
46.Sh DESCRIPTION
47The
48.Fn getdevmajor
49function returns the major device number of the block or character
50device specified by
51.Ar name
52and a file type matching the one encoded in
53.Fa type
54which must be one of
55.Dv S_IFBLK
56or
57.Dv S_IFCHR .
58.Sh RETURN VALUES
59If no device matches the specified values, no information is
60available, or an error occurs,
61.Dv NODEVMAJOR
62is returned and
63.Va errno
64is set to indicate the error.
65.Sh EXAMPLES
66To retrieve the major number for
67.Xr pty 4
68slave devices (aka pts devices):
69.Bd -literal -offset indent
70#include <stdlib.h>
71#include <sys/stat.h>
72.sp
73devmajor_t pts;
74pts = getdevmajor("pts", S_IFCHR);
75.Ed
76.Pp
77To retrieve the major numbers for the block and character
78.Xr wd 4
79devices:
80.Bd -literal -offset indent
81#include <stdlib.h>
82#include <sys/stat.h>
83.sp
84devmajor_t c, b;
85c = getdevmajor("wd", S_IFCHR);
86b = getdevmajor("wd", S_IFBLK);
87.Ed
88.Sh ERRORS
89The
90.Fn getdevmajor
91function may fail and set
92.Va errno
93for any of the errors specified for the library functions
94.Xr malloc 3
95and
96.Xr sysctlbyname 3 .
97In addition, the following errors may be reported:
98.Bl -tag -width Er
99.It Bq Er EINVAL
100The value of the
101.Fa type
102argument is not
103.Dv S_IFCHR
104or
105.Dv S_IFBLK .
106.It Bq Er ENOENT
107The named device is not found.
108.El
109.Sh SEE ALSO
110.Xr stat 2 ,
111.Xr devname 3 ,
112.Xr malloc 3 ,
113.Xr sysctlbyname 3
114.Sh HISTORY
115The
116.Fn getdevmajor
117function call appeared in
118.Nx 3.0 .
119