summaryrefslogtreecommitdiff
path: root/utils/porting.h
blob: f830741115f5ce9e0393425330cb8a3e46e5fdf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Misc system-specific crap */

#ifndef _PORTING_H_
#define _PORTING_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>

#ifdef __LDSO_LDD_SUPPORT__
# include <sys/wait.h>
#endif

#if defined(_WIN32) || defined(_WINNT)
# include "mmap-windows.c"
#else
# include <sys/mman.h>
#endif

#ifdef BUILDING_LINKAGE
#include <link.h>
/* makefile will include elf.h for us */

#include "bswap.h"
#include "dl-defs.h"
#endif

/* __WORDSIZE ist used for __ELF_NATIVE_CLASS, which is used for ElfW().
  We want to provide the wordsize of the target, not of the host, when
   compiling readelf.host
 */
#include <link.h>
#ifdef ARCH_NATIVE_BIT
#undef __WORDSIZE
#define __WORDSIZE ARCH_NATIVE_BIT
#endif

#ifdef DMALLOC
#include <dmalloc.h>
#endif

#ifndef ARRAY_SIZE
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif

/* For SunOS */
#ifndef PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX
#endif

#ifndef UCLIBC_RUNTIME_PREFIX
# define UCLIBC_RUNTIME_PREFIX "/"
#endif

#undef UCLIBC_ENDIAN_HOST
#define UCLIBC_ENDIAN_LITTLE 1234
#define UCLIBC_ENDIAN_BIG    4321
#if defined(BYTE_ORDER)
# if BYTE_ORDER == LITTLE_ENDIAN
#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
# elif BYTE_ORDER == BIG_ENDIAN
#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
# endif
#elif defined(__BYTE_ORDER)
# if __BYTE_ORDER == __LITTLE_ENDIAN
#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
# elif __BYTE_ORDER == __BIG_ENDIAN
#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
# endif
#endif
#if !defined(UCLIBC_ENDIAN_HOST)
# error "Unknown host byte order!"
#endif

#if defined __GNUC__ || defined __ICC
# define attribute_noreturn __attribute__ ((__noreturn__))
#else
# define attribute_noreturn
#endif

#endif