Norman James | 6a58a27 | 2015-10-07 14:34:16 -0500 | [diff] [blame] | 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: License: CC0 (Public domain) |
| 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 | } |