1*b1fc4beeSmatt /* $NetBSD: getbyteorder.c,v 1.1 2013/05/02 07:17:10 matt Exp $ */
2*b1fc4beeSmatt
3*b1fc4beeSmatt /*-
4*b1fc4beeSmatt * Copyright (c) 1996 The NetBSD Foundation, Inc.
5*b1fc4beeSmatt * All rights reserved.
6*b1fc4beeSmatt *
7*b1fc4beeSmatt * This code is derived from software contributed to The NetBSD Foundation
8*b1fc4beeSmatt * by Jason R. Thorpe.
9*b1fc4beeSmatt *
10*b1fc4beeSmatt * Redistribution and use in source and binary forms, with or without
11*b1fc4beeSmatt * modification, are permitted provided that the following conditions
12*b1fc4beeSmatt * are met:
13*b1fc4beeSmatt * 1. Redistributions of source code must retain the above copyright
14*b1fc4beeSmatt * notice, this list of conditions and the following disclaimer.
15*b1fc4beeSmatt * 2. Redistributions in binary form must reproduce the above copyright
16*b1fc4beeSmatt * notice, this list of conditions and the following disclaimer in the
17*b1fc4beeSmatt * documentation and/or other materials provided with the distribution.
18*b1fc4beeSmatt *
19*b1fc4beeSmatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*b1fc4beeSmatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*b1fc4beeSmatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*b1fc4beeSmatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*b1fc4beeSmatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*b1fc4beeSmatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*b1fc4beeSmatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*b1fc4beeSmatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*b1fc4beeSmatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*b1fc4beeSmatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*b1fc4beeSmatt * POSSIBILITY OF SUCH DAMAGE.
30*b1fc4beeSmatt */
31*b1fc4beeSmatt
32*b1fc4beeSmatt #include <sys/cdefs.h>
33*b1fc4beeSmatt #if defined(LIBC_SCCS) && !defined(lint)
34*b1fc4beeSmatt __RCSID("$NetBSD: getbyteorder.c,v 1.1 2013/05/02 07:17:10 matt Exp $");
35*b1fc4beeSmatt #endif
36*b1fc4beeSmatt
37*b1fc4beeSmatt #include <sys/param.h>
38*b1fc4beeSmatt #include <sys/sysctl.h>
39*b1fc4beeSmatt #include <util.h>
40*b1fc4beeSmatt
41*b1fc4beeSmatt int
getbyteorder(void)42*b1fc4beeSmatt getbyteorder(void)
43*b1fc4beeSmatt {
44*b1fc4beeSmatt int byteorder, mib[2];
45*b1fc4beeSmatt size_t varlen;
46*b1fc4beeSmatt
47*b1fc4beeSmatt mib[0] = CTL_HW;
48*b1fc4beeSmatt mib[1] = HW_BYTEORDER;
49*b1fc4beeSmatt varlen = sizeof(byteorder);
50*b1fc4beeSmatt if (sysctl(mib, 2, &byteorder, &varlen, NULL, (size_t)0) < 0)
51*b1fc4beeSmatt return (-1);
52*b1fc4beeSmatt
53*b1fc4beeSmatt return (byteorder);
54*b1fc4beeSmatt }
55