]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/bswap.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / bswap.3
1 .\" Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH BSWAP 3 2019-03-06 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 bswap_16, bswap_32, bswap_64 \- reverse order of bytes
28 .SH SYNOPSIS
29 .nf
30 .B #include <byteswap.h>
31 .PP
32 .BI bswap_16( x );
33 .BI bswap_32( x );
34 .BI bswap_64( x );
35 .fi
36 .SH DESCRIPTION
37 These macros return a value in which the order of the bytes
38 in their 2-, 4-, or 8-byte arguments is reversed.
39 .SH RETURN VALUE
40 These macros return the value of their argument with the bytes reversed.
41 .SH ERRORS
42 These macros always succeed.
43 .SH CONFORMING TO
44 These macros are GNU extensions.
45 .SH EXAMPLES
46 The program below swaps the bytes of the 8-byte integer supplied as
47 its command-line argument.
48 The following shell session demonstrates the use of the program:
49 .PP
50 .in +4n
51 .EX
52 $ \fB./a.out 0x0123456789abcdef\fP
53 0x123456789abcdef ==> 0xefcdab8967452301
54 .EE
55 .in
56 .SS Program source
57 \&
58 .EX
59 #include <stdio.h>
60 #include <stdint.h>
61 #include <stdlib.h>
62 #include <inttypes.h>
63 #include <byteswap.h>
64
65 int
66 main(int argc, char *argv[])
67 {
68 uint64_t x;
69
70 if (argc != 2) {
71 fprintf(stderr, "Usage: %s <num>\en", argv[0]);
72 exit(EXIT_FAILURE);
73 }
74
75 x = strtoul(argv[1], NULL, 0);
76 printf("0x%" PRIx64 " ==> 0x%" PRIx64 "\en", x, bswap_64(x));
77
78 exit(EXIT_SUCCESS);
79 }
80 .EE
81 .SH SEE ALSO
82 .BR byteorder (3),
83 .BR endian (3)