]> git.jsancho.org Git - lugaru.git/blob - Source/binio.h
d2d3534b657efddc8c0c6b3ca375b1997845730c
[lugaru.git] / Source / binio.h
1 #ifndef binio_h
2 #define binio_h
3
4 #include <stdarg.h>
5 #include <stdio.h>
6
7 #if defined(__cplusplus)
8 extern "C" {
9 #endif
10
11         /*
12         Notes on format of format strings:
13         * whitespace is ignored
14         * each "group" consists of an optional count (defaults to 1),
15         an optional byte-order marker (defaults to H, "host-native"),
16         and a  data-type specifier.
17         * when unpacking, each variable argument is a pointer to the
18         appropriate number of objects of the appropriate type.
19         * when packing, each variable argument is an object of the
20         appropriate type if the count is omitted, or a pointer to the
21         appropriate number of objects of the appropriate type if the
22         count is specified.
23         * the buffer supplied to pack/unpack must be of sufficient length
24         to hold all the data, or the behavior is unspecified.
25         * the file provided to the "f" versions of the functions must be
26         open in the appropriate mode, or the behavior is unspecified.
27         * the file supplied to funpackf must be of sufficient length to
28         hold all the data, or the behavior is unspecified.
29         * the behavior of all functions is unspecified if the format string
30         is incorrectly-formed.
31
32         Data-type specifiers:
33         x skipped byte; no corresponding argument
34         b byte
35         s two-byte two's-complement integer
36         i four-byte two's-complement integer
37         l eight-byte two's-complement integer
38         f four-byte IEEE754 float
39         d eight-byte IEEE754 double
40
41         Byte-order specifiers:
42         L little-endian
43         B big-endian
44         H host's native byte order
45         N network byte order
46         */
47
48 #ifndef ALREADY_DID_BINIO_STDINT
49 #define ALREADY_DID_BINIO_STDINT
50 #if defined(BinIO_STDINT_HEADER)
51 #include BinIO_STDINT_HEADER
52         typedef float              float32_t;
53         typedef double             float64_t;
54 #else
55         typedef unsigned char      uint8_t;
56         typedef unsigned short     uint16_t;
57         typedef unsigned long       uint32_t;
58 #ifdef WIN32
59         typedef unsigned __int64        uint64_t;
60 #else
61         typedef unsigned long long uint64_t;
62 #endif
63         typedef float              float32_t;
64         typedef double             float64_t;
65 #endif
66 #endif
67
68         typedef struct
69         {
70                 float64_t d;
71                 uint64_t  l;
72                 int  i;
73                 float32_t f;
74                 uint16_t  s;
75                 uint8_t   b;
76         }
77         test_data;
78
79         extern void packf    (                    const char *format, ...);
80         extern void spackf   (void *buffer,       const char *format, ...);
81         extern void fpackf   (FILE *file,         const char *format, ...);
82         extern void vspackf  (void *buffer,       const char *format, va_list args);
83         extern void vfpackf  (FILE *file,         const char *format, va_list args);
84
85         extern void unpackf  (                    const char *format, ...);
86         extern void sunpackf (const void *buffer, const char *format, ...);
87         extern void funpackf (FILE       *file,   const char *format, ...);
88         extern void vsunpackf(const void *buffer, const char *format, va_list args);
89         extern void vfunpackf(FILE       *file,   const char *format, va_list args);
90
91 #if defined(__cplusplus)
92 }
93 #endif
94
95 #endif
96