]> git.jsancho.org Git - lugaru.git/blob - Source/binio.h
Added newline to all the source/headers in Source.
[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 #if defined(BinIO_STDINT_HEADER)
49 #include BinIO_STDINT_HEADER
50         typedef float              float32_t;
51         typedef double             float64_t;
52 #else
53         typedef unsigned char      uint8_t;
54         typedef unsigned short     uint16_t;
55         typedef unsigned long       uint32_t;
56 #ifdef WIN32
57         typedef unsigned __int64        uint64_t;
58 #else
59         typedef unsigned long long uint64_t;
60 #endif
61         typedef float              float32_t;
62         typedef double             float64_t;
63 #endif
64
65         typedef struct
66         {
67                 float64_t d;
68                 uint64_t  l;
69                 int  i;
70                 float32_t f;
71                 uint16_t  s;
72                 uint8_t   b;
73         }
74         test_data;
75
76         extern void packf    (                    const char *format, ...);
77         extern void spackf   (void *buffer,       const char *format, ...);
78         extern void fpackf   (FILE *file,         const char *format, ...);
79         extern void vspackf  (void *buffer,       const char *format, va_list args);
80         extern void vfpackf  (FILE *file,         const char *format, va_list args);
81
82         extern void unpackf  (                    const char *format, ...);
83         extern void sunpackf (const void *buffer, const char *format, ...);
84         extern void funpackf (FILE       *file,   const char *format, ...);
85         extern void vsunpackf(const void *buffer, const char *format, va_list args);
86         extern void vfunpackf(FILE       *file,   const char *format, va_list args);
87
88 #if defined(__cplusplus)
89 }
90 #endif
91
92 #endif
93