OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / man3 / endian.3
1 .\" Copyright (C) 2009, Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\" a few pieces remain from an earlier version
4 .\" Copyright (C) 2008, Nanno Langstraat <nal@ii.nl>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH ENDIAN 3 2010\-09\-10 GNU "Linux Programmer's Manual"
32 .SH 名前
33 htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh,
34 htobe64, htole64, be64toh, le64toh \- convert values between host and
35 big\-/little\-endian byte order
36 .SH 書式
37 .nf
38 \fB#define _BSD_SOURCE\fP             /* See feature_test_macros(7) */
39 \fB#include <endian.h>\fP
40
41 \fBuint16_t htobe16(uint16_t \fP\fIhost_16bits\fP\fB);\fP
42 \fBuint16_t htole16(uint16_t \fP\fIhost_16bits\fP\fB);\fP
43 \fBuint16_t be16toh(uint16_t \fP\fIbig_endian_16bits\fP\fB);\fP
44 \fBuint16_t le16toh(uint16_t \fP\fIlittle_endian_16bits\fP\fB);\fP
45
46 \fBuint32_t htobe32(uint32_t \fP\fIhost_32bits\fP\fB);\fP
47 \fBuint32_t htole32(uint32_t \fP\fIhost_32bits\fP\fB);\fP
48 \fBuint32_t be32toh(uint32_t \fP\fIbig_endian_32bits\fP\fB);\fP
49 \fBuint32_t le32toh(uint32_t \fP\fIlittle_endian_32bits\fP\fB);\fP
50
51 \fBuint64_t htobe64(uint64_t \fP\fIhost_64bits\fP\fB);\fP
52 \fBuint64_t htole64(uint64_t \fP\fIhost_64bits\fP\fB);\fP
53 \fBuint64_t be64toh(uint64_t \fP\fIbig_endian_64bits\fP\fB);\fP
54 \fBuint64_t le64toh(uint64_t \fP\fIlittle_endian_64bits\fP\fB);\fP
55 .fi
56 .SH 説明
57 These functions convert the byte encoding of integer values from the byte
58 order that the current CPU (the "host") uses, to and from little\-endian and
59 big\-endian byte order.
60
61 The number, \fInn\fP, in the name of each function indicates the size of
62 integer handled by the function, either 16, 32, or 64 bits.
63
64 The functions with names of the form "htobe\fInn\fP" convert from host byte
65 order to big\-endian order.
66
67 The functions with names of the form "htole\fInn\fP" convert from host byte
68 order to little\-endian order.
69
70 The functions with names of the form "be\fInn\fPtoh" convert from big\-endian
71 order to host byte order.
72
73 The functions with names of the form "le\fInn\fPtoh" convert from little\-endian
74 order to host byte order.
75 .SH バージョン
76 These function were added to glibc in version 2.9.
77 .SH 準拠
78 These functions are nonstandard.  Similar functions are present on the BSDs,
79 where the required header file is \fI<sys/endian.h>\fP instead of
80 \fI<endian.h>\fP.  Unfortunately, NetBSD, FreeBSD, and glibc haven't
81 followed the original OpenBSD naming convention for these functions, whereby
82 the \fInn\fP component always appears at the end of the function name (thus,
83 for example, in NetBSD, FreeBSD, and glibc, the equivalent of OpenBSDs
84 "betoh32" is "be32toh").
85 .SH 注意
86 These functions are similar to the older \fBbyteorder\fP(3)  family of
87 functions.  For example, \fBbe32toh\fP()  is identical to \fBntohl\fP()\fB.\fP
88
89 The advantage of the \fBbyteorder\fP(3)  functions is that they are standard
90 functions available on all UNIX systems.  On the other hand, the fact that
91 they were designed for use in the context of TCP/IP means that they lack the
92 64\-bit and little\-endian variants described in this page.
93 .SH 例
94 The program below display the results of converting an integer from host
95 byte order to both little\-endian and big\-endian byte order.  Since host byte
96 order is either little\-endian or big\-endian, only one of these conversions
97 will have an effect.  When we run this program on a little\-endian system
98 such as x86\-32, we see the following:
99 .in +4n
100 .nf
101
102 $ \fB./a.out\fP
103 x.u32 = 0x44332211
104 htole32(x.u32) = 0x44332211
105 htobe32(x.u32) = 0x11223344
106 .fi
107 .in
108 .SS プログラムのソース
109 \&
110 .nf
111 #include <endian.h>
112 #include <stdint.h>
113 #include <stdio.h>
114 #include <stdlib.h>
115
116 int
117 main(int argc, char *argv[])
118 {
119     union {
120         uint32_t u32;
121         uint8_t arr[4];
122     } x;
123
124     x.arr[0] = 0x11;    /* Lowest\-address byte */
125     x.arr[1] = 0x22;
126     x.arr[2] = 0x33;
127     x.arr[3] = 0x44;    /* Highest\-address byte */
128
129     printf("x.u32 = 0x%x\en", x.u32);
130     printf("htole32(x.u32) = 0x%x\en", htole32(x.u32));
131     printf("htobe32(x.u32) = 0x%x\en", htobe32(x.u32));
132
133     exit(EXIT_SUCCESS);
134 }
135 .fi
136 .SH 関連項目
137 \fBbyteorder\fP(3)