1 /* Declarations for common convenience functions.
2 Copyright (C) 2006-2011 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
30 #define LIB_SYSTEM_H 1
38 #if __BYTE_ORDER == __LITTLE_ENDIAN
40 # define BE32(n) bswap_32 (n)
41 #elif __BYTE_ORDER == __BIG_ENDIAN
43 # define LE32(n) bswap_32 (n)
45 # error "Unknown byte order"
48 extern void *xmalloc (size_t) __attribute__ ((__malloc__));
49 extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__));
50 extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__));
52 extern char *xstrdup (const char *) __attribute__ ((__malloc__));
53 extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__));
56 extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len);
57 extern int crc32_file (int fd, uint32_t *resp);
59 /* A special gettext function we use if the strings are too short. */
60 #define sgettext(Str) \
61 ({ const char *__res = strrchr (gettext (Str), '|'); \
62 __res ? __res + 1 : Str; })
64 #define gettext_noop(Str) Str
67 #define pwrite_retry(fd, buf, len, off) \
68 TEMP_FAILURE_RETRY (pwrite (fd, buf, len, off))
69 #define write_retry(fd, buf, n) \
70 TEMP_FAILURE_RETRY (write (fd, buf, n))
71 #define pread_retry(fd, buf, len, off) \
72 TEMP_FAILURE_RETRY (pread (fd, buf, len, off))
75 /* We need define two variables, argp_program_version_hook and
76 argp_program_bug_address, in all programs. argp.h declares these
77 variables as non-const (which is correct in general). But we can
78 do better, it is not going to change. So we want to move them into
79 the .rodata section. Define macros to do the trick. */
80 #define ARGP_PROGRAM_VERSION_HOOK_DEF \
81 void (*const apvh) (FILE *, struct argp_state *) \
82 __asm ("argp_program_version_hook")
83 #define ARGP_PROGRAM_BUG_ADDRESS_DEF \
84 const char *const apba__ __asm ("argp_program_bug_address")
87 /* The demangler from libstdc++. */
88 extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,
89 size_t *length, int *status);
95 /* Command line parser. */
96 extern const struct argp color_argp;
104 } __attribute__ ((packed));
105 extern enum color_enum color_mode;
107 /* Colors to use for the various components. */
108 extern char *color_address;
109 extern char *color_bytes;
110 extern char *color_mnemonic;
111 extern char *color_operand1;
112 extern char *color_operand2;
113 extern char *color_operand3;
114 extern char *color_label;
115 extern char *color_undef;
116 extern char *color_undef_tls;
117 extern char *color_undef_weak;
118 extern char *color_symbol;
119 extern char *color_tls;
120 extern char *color_weak;
122 extern const char color_off[];
124 #endif /* system.h */