build: remove elf_core.c from source dependencies
[mit.git] / util.h
blobd5120726b5142ce0377cbb733a915d913e0db669
1 #ifndef _UTIL_H
2 #define _UTIL_H
4 #include <stdio.h>
6 struct string_table
8 unsigned int cnt;
9 unsigned int max;
10 const char *str[0];
13 char *getline_wrapped(FILE *file, unsigned int *linenum);
15 void filename2modname(char *modname, const char *filename);
16 char *underscores(char *string);
17 char *my_basename(const char *path);
19 struct string_table *strtbl_add(const char *str, struct string_table *tbl);
20 void strtbl_free(struct string_table *tbl);
22 const char *next_string(const char *string, unsigned long *secsize);
25 * Change endianness of x if conv is true.
27 #define END(x, conv) \
28 ({ \
29 typeof(x) __x; \
30 if (conv) __swap_bytes(&(x), &(__x), sizeof(__x)); \
31 else __x = (x); \
32 __x; \
35 static inline void __swap_bytes(const void *src, void *dest, unsigned int size)
37 unsigned int i;
38 for (i = 0; i < size; i++)
39 ((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
42 int native_endianness(void);
44 #define streq(a,b) (strcmp((a),(b)) == 0)
45 #define strstarts(a,start) (strncmp((a),(start), strlen(start)) == 0)
47 #endif