]> git.ozlabs.org Git - ccan/blob - _info
a239d253a14a2d5c7d47ee2daa9523489def9dff
[ccan] / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * endian - endian conversion macros for simple types
7  *
8  * Portable protocols (such as on-disk formats, or network protocols)
9  * are often defined to be a particular endian: little-endian (least
10  * significant bytes first) or big-endian (most significant bytes
11  * first).
12  *
13  * Similarly, some CPUs lay out values in memory in little-endian
14  * order (most commonly, Intel's 8086 and derivatives), or big-endian
15  * order (almost everyone else).
16  *
17  * This module provides conversion routines, inspired by the linux kernel.
18  *
19  * Example:
20  *      #include <stdio.h>
21  *      #include <err.h>
22  *      #include <ccan/endian/endian.h>
23  *
24  *      // 
25  *      int main(int argc, char *argv[])
26  *      {
27  *              uint32_t value;
28  *
29  *              if (argc != 2)
30  *                      errx(1, "Usage: %s <value>", argv[0]);
31  *
32  *              value = atoi(argv[1]);
33  *              printf("native:        %08x\n", value);
34  *              printf("little-endian: %08x\n", cpu_to_le32(value));
35  *              printf("big-endian:    %08x\n", cpu_to_be32(value));
36  *              printf("byte-reversed: %08x\n", bswap_32(value));
37  *              exit(0);
38  *      }
39  *
40  * License: LGPL (2 or any later version)
41  * Author: Rusty Russell <rusty@rustcorp.com.au>
42  */
43 int main(int argc, char *argv[])
44 {
45         if (argc != 2)
46                 return 1;
47
48         if (strcmp(argv[1], "depends") == 0)
49                 /* Nothing */
50                 return 0;
51
52         return 1;
53 }