diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index 0bba8b54adfa..abcc211e250b 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.73 2012/04/07 16:44:39 christos Exp $ +# $NetBSD: Makefile,v 1.74 2013/05/02 07:17:09 matt Exp $ # @(#)Makefile 8.1 (Berkeley) 6/4/93 USE_SHLIBDIR= yes @@ -11,7 +11,8 @@ WARNS?= 5 LIB= util CPPFLAGS+=-DLIBC_SCCS -I${.CURDIR} LINTFLAGS+=-w -SRCS+= efun.c getbootfile.c getlabelsector.c getmaxpartitions.c \ +SRCS+= efun.c \ + getbootfile.c getbyteorder.c getlabelsector.c getmaxpartitions.c \ getfsspecname.c getmntopts.c getrawpartition.c getdiskrawname.c \ disklabel_dkcksum.c disklabel_scan.c \ if_media.c \ @@ -22,7 +23,8 @@ SRCS+= efun.c getbootfile.c getlabelsector.c getmaxpartitions.c \ secure_path.c sockaddr_snprintf.c stat_flags.c \ strpct.c ttyaction.c ttymsg.c -MAN= efun.3 getbootfile.3 getfstypename.3 getlabelsector.3 \ +MAN= efun.3 \ + getbootfile.3 getbyteorder.3 getfstypename.3 getlabelsector.3 \ getmaxpartitions.3 getmntopts.3 getrawpartition.3 \ getdiskrawname.3 getfsspecname.3 \ login.3 login_cap.3 loginx.3 \ diff --git a/lib/libutil/getbyteorder.3 b/lib/libutil/getbyteorder.3 new file mode 100644 index 000000000000..4d8943ab2f2c --- /dev/null +++ b/lib/libutil/getbyteorder.3 @@ -0,0 +1,59 @@ +.\" $NetBSD: getbyteorder.3,v 1.1 2013/05/02 07:17:09 matt Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jason R. Thorpe. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd May 1, 2013 +.Dt GETBYTEORDER 3 +.Os +.Sh NAME +.Nm getbyteorder +.Nd get the current byte order +.Sh LIBRARY +.Lb libutil +.Sh SYNOPSIS +.In util.h +.In sys/endian.h +.Ft int +.Fn getbyteorder void +.Sh DESCRIPTION +.Fn getbyteorder +returns LITTLE_ENDIAN, BIG_ENDIAN, +or \-1 in case of an error, setting the global +.Va errno +variable. +The possible values for +.Va errno +are the same as in +.Xr sysctl 3 . +.Sh SEE ALSO +.Xr sysctl 3 +.Sh HISTORY +The +.Fn getbyteorder +function call appeared in +.Nx 7 . diff --git a/lib/libutil/getbyteorder.c b/lib/libutil/getbyteorder.c new file mode 100644 index 000000000000..e29928020ac4 --- /dev/null +++ b/lib/libutil/getbyteorder.c @@ -0,0 +1,54 @@ +/* $NetBSD: getbyteorder.c,v 1.1 2013/05/02 07:17:10 matt Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: getbyteorder.c,v 1.1 2013/05/02 07:17:10 matt Exp $"); +#endif + +#include +#include +#include + +int +getbyteorder(void) +{ + int byteorder, mib[2]; + size_t varlen; + + mib[0] = CTL_HW; + mib[1] = HW_BYTEORDER; + varlen = sizeof(byteorder); + if (sysctl(mib, 2, &byteorder, &varlen, NULL, (size_t)0) < 0) + return (-1); + + return (byteorder); +}