2 * Copyright (C) 2006 Michael Buesch <m@bues.ch>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
20 void dump(const char *data,
22 const char *description)
27 fprintf(stderr, "Data dump (%s, %zd bytes):",
29 for (i = 0; i < size; i++) {
32 fprintf(stderr, "\n0x%08zx: 0x%02x, ",
35 fprintf(stderr, "0x%02x, ", c & 0xff);
37 fprintf(stderr, "\n");
40 void * xmalloc(size_t size)
46 fprintf(stderr, "Out of memory\n");
54 char * xstrdup(const char *str)
60 fprintf(stderr, "Out of memory\n");
67 be16_t cpu_to_be16(uint16_t x)
70 uint8_t *tmp = (uint8_t *)(&ret);
72 tmp[0] = (x & 0xFF00) >> 8;
73 tmp[1] = (x & 0x00FF);
78 be32_t cpu_to_be32(uint32_t x)
81 uint8_t *tmp = (uint8_t *)(&ret);
83 tmp[0] = (x & 0xFF000000) >> 24;
84 tmp[1] = (x & 0x00FF0000) >> 16;
85 tmp[2] = (x & 0x0000FF00) >> 8;
86 tmp[3] = (x & 0x000000FF);