20 #ifndef VB_LIBVBISAM_H
21 #define VB_LIBVBISAM_H
31 #define _LFS64_LARGEFILE 1
32 #define _LFS64_STDIO 1
33 #define _FILE_OFFSET_BITS 64
34 #define _LARGEFILE64_SOURCE 1
35 #define __USE_LARGEFILE64 1
36 #define __USE_FILE_OFFSET64 1
38 #define _LARGE_FILES 1
40 #if defined(__hpux__) && !defined(__LP64__)
41 #define _APP32_64BIT_OFF_T 1
49 #include <sys/types.h>
63 #define WINDOWS_LEAN_AND_MEAN
66 #include <sys/locking.h>
67 #define open(x, y, z) _open(x, y, z)
68 #define read(x, y, z) _read(x, y, z)
69 #define write(x, y, z) _write(x, y, z)
71 #define lseek(x, y, z) _lseeki64(x, y, z)
73 #define lseek(x, y, z) _lseek(x, y, z)
75 #define close(x) _close(x)
76 #define unlink(x) _unlink(x)
83 typedef unsigned short mode_t;
92 #define _CRT_SECURE_NO_DEPRECATE 1
93 #define inline _inline
95 #pragma warning(disable: 4996)
96 #define strncasecmp _strnicmp
97 #define strcasecmp _stricmp
98 #define __attribute__(x)
104 #define inline __inline
109 #define VB_OFFLEN_7F 0x7fffffffffffffffLL
110 #define VB_OFFLEN_3F 0x3fffffffffffffffLL
111 #define VB_OFFLEN_40 0x4000000000000000LL
114 #define VB_OFFLEN_7F 0x7FFFFFFF
115 #define VB_OFFLEN_3F 0x3FFFFFFF
116 #define VB_OFFLEN_40 0x40000000
120 #define VB_MAX_FILES 128
126 #if defined(__GNUC__) && defined(linux) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
127 #define VB_HIDDEN __attribute__ ((visibility("hidden")))
138 #define off_t __int64
142 #ifdef HAVE_BUILTIN_EXPECT
143 #define likely(x) __builtin_expect(!!(x), 1)
144 #define unlikely(x) __builtin_expect(!!(x), 0)
146 #define likely(x) (x)
147 #define unlikely(x) (x)
152 #if !defined(__i386__) && !defined(__x86_64__) && !defined(__powerpc__) && !defined(__powerpc64__) && !defined(__ppc__) && !defined(__amd64__)
153 #if defined(_MSC_VER)
154 #define ALLOW_MISALIGNED
155 #define MISALIGNED __unaligned
160 #define ALLOW_MISALIGNED
166 #if defined(ALLOW_MISALIGNED) && !defined(WORDS_BIGENDIAN)
167 #define inl_ldint(x) (int)(VB_BSWAP_16(*((unsigned short MISALIGNED *)(x))))
172 #ifndef WORDS_BIGENDIAN
176 unsigned char *pctemp = (
unsigned char *) &ivalue;
177 unsigned char *pctemp2 = (
unsigned char *) pclocation;
179 *(pctemp + 0) = *(pctemp2 + 0);
180 *(pctemp + 1) = *(pctemp2 + 1);
186 #if defined(ALLOW_MISALIGNED) && !defined(WORDS_BIGENDIAN)
187 #define inl_stint(x,y) *(unsigned short MISALIGNED *)(y) = VB_BSWAP_16((unsigned short)(x));
192 #ifndef WORDS_BIGENDIAN
195 unsigned char *pctemp = (
char *) &ivalue;
196 unsigned char *pctemp2 = (
unsigned char *) pclocation;
198 *(pctemp2 + 0) = *(pctemp + 0 + INTSIZE);
199 *(pctemp2 + 1) = *(pctemp + 1 + INTSIZE);
205 #if defined(ALLOW_MISALIGNED) && !defined(WORDS_BIGENDIAN)
206 #define inl_ldlong(x) (int)(VB_BSWAP_32(*((unsigned short MISALIGNED *)(x))))
211 #ifndef WORDS_BIGENDIAN
216 memcpy((
unsigned char *)&lvalue, (
unsigned char *)pclocation, 4);
222 #if defined(ALLOW_MISALIGNED) && !defined(WORDS_BIGENDIAN)
223 #define inl_stlong(x,y) *(unsigned int MISALIGNED *)(y) = VB_BSWAP_32((unsigned int)(x));
228 #ifndef WORDS_BIGENDIAN
231 memcpy((
unsigned char *)pclocation, (
unsigned char *)&lvalue, 4);
241 #ifndef WORDS_BIGENDIAN
251 memcpy((
unsigned char *)&tvalue, (
unsigned char *)pclocation, 8);
253 memcpy((
unsigned char *)&tvalue, (
unsigned char *)pclocation, 4);
262 #ifndef WORDS_BIGENDIAN
270 memcpy((
unsigned char *)pclocation, (
unsigned char *)&tvalue, 8);
272 memcpy((
unsigned char *)pclocation, (
unsigned char *)&tvalue, 4);
283 #define MAX_NODE_LENGTH 4096
285 #define MAX_NODE_LENGTH 1024
288 #define VB_NODE_MAX 4096
289 #define MAX_ISREC_LENGTH 32511
290 #define MAX_RESERVED_LENGTH 32768
291 #define MAX_BUFFER_LENGTH 65536
302 #define RECOV_VB 0x01
303 #define RECOV_LK 0x02
308 #define VBNEEDFLUSH 2
354 struct VBKEY *pskeylist[256];
468 #define VBL_BUILD ("BU")
469 #define VBL_BEGIN ("BW")
470 #define VBL_CREINDEX ("CI")
471 #define VBL_CLUSTER ("CL")
472 #define VBL_COMMIT ("CW")
473 #define VBL_DELETE ("DE")
474 #define VBL_DELINDEX ("DI")
475 #define VBL_FILEERASE ("ER")
476 #define VBL_FILECLOSE ("FC")
477 #define VBL_FILEOPEN ("FO")
478 #define VBL_INSERT ("IN")
479 #define VBL_RENAME ("RE")
480 #define VBL_ROLLBACK ("RW")
481 #define VBL_SETUNIQUE ("SU")
482 #define VBL_UNIQUEID ("UN")
483 #define VBL_UPDATE ("UP")
503 const int imode,
int irowlength,
const int iisbuild);
507 struct keydesc *pskeydesc,
const int imode);
516 int irowlength,
char *pcrow);
521 const int ioldrowlen,
const int inewrowlen,
526 const off_t trownumber);
530 int *pideletedrow,
const off_t trownumber);
532 int ideletedrow,
const off_t trownumber);
544 char *pcrow_buffer,
unsigned char *pckeyvalue);
546 const int ikeynumber,
int ilength,
547 unsigned char *pckeyvalue, off_t tdupnumber);
550 const int isetcurr,
struct VBKEY **ppskey);
552 unsigned char *pckeyvalue);
554 const int ikeynumber,
unsigned char *pckeyvalue,
555 off_t trownode, off_t tdupnumber,
559 unsigned char *pckey1,
unsigned char *pckey2);
563 const unsigned int ispecial);
567 const off_t trownumber);
573 VB_HIDDEN extern off_t
tvblseek (
const int ihandle, off_t toffset,
const int iwhence);
575 VB_HIDDEN extern ssize_t
tvbread (
const int ihandle,
void *pvbuffer,
const size_t tcount);
576 VB_HIDDEN extern ssize_t
tvbwrite (
const int ihandle,
const void *pvbuffer,
const size_t tcount);
579 const off_t tblocknumber,
char *cbuffer);
581 const off_t tblocknumber,
const char *cbuffer);
583 const off_t tlength,
const int imode);
595 struct VBKEY *pskey);
603 struct VBTREE *pstree,
const off_t tnodenumber,
606 struct VBTREE *pstree,
const off_t tnodenumber,
607 const int imode,
const int iposn);
ssize_t tvbwrite(const int ihandle, const void *pvbuffer, const size_t tcount)
int ivblock(const int ihandle, const off_t toffset, const off_t tlength, const int imode)
int ivbopen(const char *pcfilename, const int iflags, const mode_t tmode)
int ivbforcedataallocate(const int ihandle, const off_t trownumber)
struct VBFILE svbfile[128 *3]
int ivbtranserase(const char *pcfilename)
static int inl_ldint(void *pclocation)
int ivbtransdelete(const int ihandle, off_t trownumber, int irowlength)
struct VBLOCK * psvblockallocate(const int ihandle)
int ivbtranssetunique(const int ihandle, const off_t tuniqueid)
int ivbtransclose(const int ihandle, const char *pcfilename)
struct VBLOCK * pslocktail
int ivbdatafree(const int ihandle, const off_t trownumber)
void vvbkeyvalueset(const int ihigh, struct keydesc *pskeydesc, unsigned char *pckeyvalue)
struct VBTREE * psvbtreeallocate(const int ihandle)
unsigned char iindexchanged
int ivbkeysearch(const int ihandle, const int imode, const int ikeynumber, int ilength, unsigned char *pckeyvalue, off_t tdupnumber)
int ivbblockread(const int ihandle, const int iisindex, const off_t tblocknumber, char *cbuffer)
int ivbcheckkey(const int ihandle, struct keydesc *pskey, const int imode, int irowlength, const int iisbuild)
int ivbtransupdate(const int ihandle, const off_t trownumber, const int ioldrowlen, const int inewrowlen, const char *pcrow)
int ivbkeylocaterow(const int ihandle, const int ikeynumber, off_t trownumber)
struct VBKEY * psvbkeyallocate(const int ihandle, const int ikeynumber)
int ivbkeycompare(const int ihandle, const int ikeynumber, int ilength, unsigned char *pckey1, unsigned char *pckey2)
int ivbdatawrite(const int ihandle, char *pcbuffer, int ideletedrow, const off_t trownumber)
static void inl_stlong(int lvalue, void *pclocation)
int ivbtranscreateindex(const int ihandle, struct keydesc *pskeydesc)
int ivbenter(const int ihandle, const unsigned int imodifying, const unsigned int ispecial)
struct VBLOCK * pslockhead
int ivbkeyload(const int ihandle, const int ikeynumber, const int imode, const int isetcurr, struct VBKEY **ppskey)
int ivbtransrename(char *pcoldname, char *pcnewname)
int ivbtransinsert(const int ihandle, const off_t trownumber, int irowlength, char *pcrow)
const unsigned char * collating_sequence
int ivbnodeload(const int ihandle, const int ikeynumber, struct VBTREE *pstree, const off_t tnodenumber, const int iprevlvl)
void ivbclose3(const int ihandle)
static void inl_stint(int ivalue, void *pclocation)
int ivbtransdeleteindex(const int ihandle, struct keydesc *pskeydesc)
void vvblockfree(struct VBLOCK *pslock)
int ivbkeydelete(const int ihandle, const int ikeynumber)
unsigned char iisdictlocked
off_t tvbdataallocate(const int ihandle)
struct VBKEY * pskeyfree[32]
int ivbdatalock(const int ihandle, const int imode, const off_t trownumber)
void vvbkeyallfree(const int ihandle, const int ikeynumber, struct VBTREE *pstree)
struct VBKEY * pskeycurr[32]
struct DICTNODE sdictnode
int ivbtransuniqueid(const int ihandle, const off_t tuniqueid)
void vvbmakekey(const struct keydesc *pskeydesc, char *pcrow_buffer, unsigned char *pckeyvalue)
int ivbwriterow(const int ihandle, char *pcrow, const off_t trownumber)
int ivbdataread(const int ihandle, char *pcbuffer, int *pideletedrow, const off_t trownumber)
void * pvvbmalloc(const size_t size)
int ivbnodesave(const int ihandle, const int ikeynumber, struct VBTREE *pstree, const off_t tnodenumber, const int imode, const int iposn)
int ivbfileopenlock(const int ihandle, const int imode)
void vvbkeyfree(const int ihandle, const int ikeynumber, struct VBKEY *pskey)
struct DICTINFO * psvbfile[128+1]
off_t tvbnodecountgetnext(const int ihandle)
int ivbtransbuild(const char *pcfilename, const int iminrowlen, const int imaxrowlen, struct keydesc *pskeydesc, const int imode)
unsigned char iisdatalocked
int ivbnodefree(const int ihandle, const off_t tnodenumber)
int ivbclose(const int ihandle)
int ivbkeyinsert(const int ihandle, struct VBTREE *pstree, const int ikeynumber, unsigned char *pckeyvalue, off_t trownode, off_t tdupnumber, struct VBTREE *pschild)
static int inl_ldlong(void *pclocation)
int ivbexit(const int ihandle)
int ivbblockwrite(const int ihandle, const int iisindex, const off_t tblocknumber, const char *cbuffer)
void vvbtreeallfree(const int ihandle, const int ikeynumber, struct VBTREE *pstree)
struct VBKEY * pskeylist[512]
static void inl_stquad(off_t tvalue, void *pclocation)
ssize_t tvbread(const int ihandle, void *pvbuffer, const size_t tcount)
int ivbforceexit(const int ihandle)
struct VBTREE * pstree[32]
unsigned char iisdisjoint
struct VBKEY * pskeyfirst
struct keydesc * pskeydesc[32]
static off_t inl_ldquad(void *pclocation)
off_t tvbnodeallocate(const int ihandle)
int ivbtransopen(const int ihandle, const char *pcfilename)
int ivbtranscluster(void)
void vvbkeyunmalloc(const int ihandle, const int ikeynumber)
int ivbclose2(const int ihandle)
off_t tvblseek(const int ihandle, off_t toffset, const int iwhence)