forked from burstzp/vitas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.h
27 lines (24 loc) · 1.25 KB
/
item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef ITEM
#define ITEM
#include <stdlib.h>
typedef struct _item {
int rbytes;
int nbytes; /* size of data */
unsigned char nsuffix; /* length of flags-and-length string */
unsigned char nkey; /* key length, w/terminating null and padding */
void *end[];
} item;
#define ITEM_key(item) ((char*)&((item)->end[0]))
#define ITEM_suffix(item) ((char*) &((item)->end[0]) + (item)->nkey + 1)
#define ITEM_flags(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 + (item)->nsuffix)
#define ITEM_data2(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 + (item)->nsuffix)
#define ITEM_expired(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 + (item)->nsuffix) + sizeof(int)
#define ITEM_data(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 + (item)->nsuffix) + sizeof(int) * 2
#define ITEM_ntotal(item) (sizeof(struct _stritem) + (item)->nkey + 1 + (item)->nsuffix + (item)->nbytes)
item* new_item(size_t);
item* item_alloc(const char*, size_t, const int, int nbytes);
int item_alloc1(item**, char*, size_t*);//,const int,const int nbytes);
int item_alloc2(item**, const char*, size_t, const int, const int, int nbytes);//,const int,const int nbytes);
void item_set_data(item*,char*,size_t);
void free_item(item*);
#endif