]> mj.ucw.cz Git - libucw.git/blob - ucw/ff-binary.c
tableprinter: header option now parsed by xtypes
[libucw.git] / ucw / ff-binary.c
1 /*
2  *      UCW Library -- Fast Buffered I/O: Binary Numbers
3  *
4  *      (c) 1997--2006 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <ucw/lib.h>
11 #include <ucw/fastbuf.h>
12 #include <ucw/ff-binary.h>
13
14 #define GEN(type, name, size, endian)                           \
15 type bget##name##_##endian##_slow(struct fastbuf *f)            \
16 {                                                               \
17   byte buf[size/8];                                             \
18   if (bread(f, buf, sizeof(buf)) != sizeof(buf))                \
19     return ~(type)0;                                            \
20   return get_u##size##_##endian(buf);                           \
21 }                                                               \
22 void bput##name##_##endian##_##slow(struct fastbuf *f, type x)  \
23 {                                                               \
24   byte buf[size/8];                                             \
25   put_u##size##_##endian(buf, x);                               \
26   bwrite_slow(f, buf, sizeof(buf));                             \
27 }
28
29 #define FF_ALL(type, name, size) GEN(type,name,size,be) GEN(type,name,size,le)
30
31 FF_ALL(int, w, 16)
32 FF_ALL(uint, l, 32)
33 FF_ALL(u64, q, 64)
34 FF_ALL(u64, 5, 40)