1#include "config.h" 2#include <stdio.h> 3#include <string.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 * It also provides leint32_t, beint32_t etc typedefs, which are annotated for 19 * the sparse checker. 20 * 21 * Example: 22 * #include <stdio.h> 23 * #include <err.h> 24 * #include <ccan/endian/endian.h> 25 * 26 * // 27 * int main(int argc, char *argv[]) 28 * { 29 * uint32_t value; 30 * 31 * if (argc != 2) 32 * errx(1, "Usage: %s <value>", argv[0]); 33 * 34 * value = atoi(argv[1]); 35 * printf("native: %08x\n", value); 36 * printf("little-endian: %08x\n", cpu_to_le32(value)); 37 * printf("big-endian: %08x\n", cpu_to_be32(value)); 38 * printf("byte-reversed: %08x\n", bswap_32(value)); 39 * exit(0); 40 * } 41 * 42 * License: License: CC0 (Public domain) 43 * Author: Rusty Russell <rusty@rustcorp.com.au> 44 */ 45int main(int argc, char *argv[]) 46{ 47 if (argc != 2) 48 return 1; 49 50 if (strcmp(argv[1], "depends") == 0) 51 /* Nothing */ 52 return 0; 53 54 return 1; 55} 56