2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 typedef struct pack_S
{
30 #define pack_destroy(pack) free(pack)
31 #define pack_sizeof(pack) ((pack)->cur-(pack)->buf)
32 #define pack_malloc(size) pack_create(malloc(size))
33 #define pack_free(pack) do { free(pack->buf); pack_destroy(pack); } while(0)
34 #define pack_data(pack) ((pack)->buf)
35 #define pack_reset(pack) ((pack)->cur = (pack)->buf)
37 pack_t
pack_create(void *buf
);
41 #define packg(pack,type,val) do { *((type*)((pack)->cur)) = (type)(val); (pack)->cur += sizeof(type); } while(0)
42 #define pack8(pack,val) packg(pack,uint8_t,val)
43 #define pack16(pack,val) packg(pack,uint16_t,val)
44 #define pack32(pack,val) packg(pack,uint32_t,val)
45 #define pack64(pack,val) packg(pack,uint64_t,val)
46 #define packc(pack,val) packg(pack,char,val)
47 #define packs(pack,val) packg(pack,short,val)
48 #define packi(pack,val) packg(pack,int,val)
49 #define packl(pack,val) packg(pack,long,val)
50 #define packobj(pack,obj) packdata(pack,&(obj),sizeof(obj))
52 void packstr(pack_t pack
,const char *str
);
53 void packnstr(pack_t pack
,const char *str
,size_t maxlen
);
54 void packdata(pack_t pack
,void *data
,size_t size
);
58 #define unpackg(pack,type,val) do { *(val) = *((type*)((pack)->cur)); (pack)->cur += sizeof(type); } while(0)
59 #define unpack8(pack,val) unpackg(pack,uint8_t,val)
60 #define unpack16(pack,val) unpackg(pack,uint16_t,val)
61 #define unpack32(pack,val) unpackg(pack,uint32_t,val)
62 #define unpack64(pack,val) unpackg(pack,uint64_t,val)
63 #define unpackc(pack,val) unpackg(pack,char,val)
64 #define unpacks(pack,val) unpackg(pack,short,val)
65 #define unpacki(pack,val) unpackg(pack,int,val)
66 #define unpackl(pack,val) unpackg(pack,long,val)
67 #define unpackobj(pack,obj) unpackdata(pack,&(obj));
69 void unpackstr(pack_t pack
,char **str
);
70 void unpackdata(pack_t pack
,void *data
);