Module Name: src
Committed By: matt
Date: Thu May 2 07:17:10 UTC 2013
Modified Files:
src/lib/libutil: Makefile
Added Files:
src/lib/libutil: getbyteorder.3 getbyteorder.c
Log Message:
Add getbyteorder() call.
To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/lib/libutil/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/libutil/getbyteorder.3 \
src/lib/libutil/getbyteorder.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.73 src/lib/libutil/Makefile:1.74
--- src/lib/libutil/Makefile:1.73 Sat Apr 7 16:44:39 2012
+++ src/lib/libutil/Makefile Thu May 2 07:17:09 2013
@@ -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 getlabelsect
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 \
Added files:
Index: src/lib/libutil/getbyteorder.3
diff -u /dev/null src/lib/libutil/getbyteorder.3:1.1
--- /dev/null Thu May 2 07:17:10 2013
+++ src/lib/libutil/getbyteorder.3 Thu May 2 07:17:09 2013
@@ -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 .
Index: src/lib/libutil/getbyteorder.c
diff -u /dev/null src/lib/libutil/getbyteorder.c:1.1
--- /dev/null Thu May 2 07:17:10 2013
+++ src/lib/libutil/getbyteorder.c Thu May 2 07:17:10 2013
@@ -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 <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getbyteorder.c,v 1.1 2013/05/02 07:17:10 matt Exp $");
+#endif
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <util.h>
+
+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);
+}