Add elf_core.c into the EXTRA_SOURCES for the static library
[mit.git] / util.h
blobfbda299636964aa0946f927a1d35f693db5233bb
1 #ifndef _UTIL_H
2 #define _UTIL_H
4 #include <stdio.h>
6 char *getline_wrapped(FILE *file, unsigned int *linenum);
8 void filename2modname(char *modname, const char *filename);
9 char *underscores(char *string);
10 char *my_basename(const char *path);
12 const char *next_string(const char *string, unsigned long *secsize);
15 * Change endianness of x if conv is true.
17 #define END(x, conv) \
18 ({ \
19 typeof(x) __x; \
20 if (conv) __swap_bytes(&(x), &(__x), sizeof(__x)); \
21 else __x = (x); \
22 __x; \
25 static inline void __swap_bytes(const void *src, void *dest, unsigned int size)
27 unsigned int i;
28 for (i = 0; i < size; i++)
29 ((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
32 int native_endianness(void);
34 int elf_ident(void *file, unsigned long fsize, int *conv);
35 void *get_section(void *file, unsigned long filesize,
36 const char *secname, unsigned long *secsize);
37 void *get_section32(void *file, unsigned long filesize,
38 const char *secname, unsigned long *secsize, int conv);
39 void *get_section64(void *file, unsigned long filesize,
40 const char *secname, unsigned long *secsize, int conv);
42 #define streq(a,b) (strcmp((a),(b)) == 0)
43 #define strstarts(a,start) (strncmp((a),(start), strlen(start)) == 0)
45 #endif