Clean up get_section()
[mit.git] / util.h
blobc73ad219a2ba3896914d953fcb19118dda8b0a4b
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);
11 const char *next_string(const char *string, unsigned long *secsize);
14 * Change endianness of x if conv is true.
16 #define END(x, conv) \
17 ({ \
18 typeof(x) __x; \
19 if (conv) __swap_bytes(&(x), &(__x), sizeof(__x)); \
20 else __x = (x); \
21 __x; \
24 static inline void __swap_bytes(const void *src, void *dest, unsigned int size)
26 unsigned int i;
27 for (i = 0; i < size; i++)
28 ((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
31 int native_endianness(void);
33 int elf_ident(void *file, unsigned long fsize, int *conv);
34 void *get_section(void *file, unsigned long filesize,
35 const char *secname, unsigned long *secsize);
36 void *get_section32(void *file, unsigned long filesize,
37 const char *secname, unsigned long *secsize, int conv);
38 void *get_section64(void *file, unsigned long filesize,
39 const char *secname, unsigned long *secsize, int conv);
41 #define streq(a,b) (strcmp((a),(b)) == 0)
42 #define strstarts(a,start) (strncmp((a),(start), strlen(start)) == 0)
43 #define my_basename(path) ((strrchr((path), '/') ?: (path) - 1) + 1)
45 #endif