minor fixes
[ia32rtools.git] / tools / common.h
1
2 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
3 #define IS(w, y) !strcmp(w, y)
4 #define IS_START(w, y) !strncmp(w, y, strlen(y))
5
6 // read a line, truncating it if it doesn't fit
7 static inline char *my_fgets(char *s, size_t size, FILE *stream)
8 {
9   char *ret, *ret2;
10   char buf[64];
11   int p;
12
13   p = size - 2;
14   if (p >= 0)
15     s[p] = 0;
16
17   ret = fgets(s, size, stream);
18   if (ret != NULL && p >= 0 && s[p] != 0 && s[p] != '\n') {
19     p = sizeof(buf) - 2;
20     do {
21       buf[p] = 0;
22       ret2 = fgets(buf, sizeof(buf), stream);
23     }
24     while (ret2 != NULL && buf[p] != 0 && buf[p] != '\n');
25   }
26
27   return ret;
28 }
29