1 2 /*************************************************************************** 3 4 Disk Based Hash library DBH 5 6 * Copyright (C) 2002-2016 Edscott Wilson Garcia 7 * EMail: edscott@imp.mc 8 * 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 3 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation. 23 24 25 ************************************************************************* 26 27 - bigendian machines should have -DTURN for binary file compatibility. 28 if this is not needed, increased speed comes from *not* using -DTURN 29 30 For compilers: 31 32 DBH version 1.0 had 32 bit filepointers. This is incompatible with 33 DBH version 2.0 which has 64 bit filepointers. 34 35 Type FILEPOINTER determined by configure script to 64 bits. 36 DBH version 2 requires size_t to be at least 64 bits to compile. 37 38 If sizeof(size_t) is less than 64 bits, DBH version 2.0 will not compile 39 ****************************************************************************/ 40 #ifdef HAVE_CONFIG_H 41 # include "config.h" 42 #endif 43 44 #include "debug.h" 45 #include <stdio.h> 46 #include <time.h> 47 #include <stdlib.h> 48 #include <math.h> 49 #include <string.h> 50 #include <unistd.h> 51 #include <fcntl.h> 52 #include <errno.h> 53 54 #ifdef HAVE_LIBPTHREAD 55 # include <pthread.h> 56 #endif 57 #ifdef HAVE_SYS_WAIT_H 58 # include <sys/wait.h> 59 #endif 60 61 #include <sys/types.h> 62 #include <sys/stat.h> 63 64 // for shm and parallel protection 65 #ifdef HAVE_SYS_MMAN_H 66 # ifdef PARALLEL_SAFE 67 # include <sys/mman.h> 68 # endif 69 #endif 70 71 // 72 73 #ifdef HAVE_MACHINE_LIMITS_H 74 # include <machine/limits.h> 75 #else 76 # include <limits.h> 77 #endif 78 79 80 #include "dbh.h" 81 #include "dbh_private.h" 82 #include "dbh_functions2.h" 83 #ifndef COPYRIGHT 84 # define COPYRIGHT "DBH copyright 2000-2010 LGPL, Edscott Wilson Garcia. See http://dbh.sourceforge.net/ for source code" 85 #endif 86 87 #ifndef DBH_VERSION 88 # error "DBH_VERSION NOT DEFINED" 89 #endif 90 91 /* with 19 keys out of the 256 key length maximum 92 we have the full 256^8 records! thus 93 no need to grow further. And this is using a decimal 94 based key. 95 for article, need comparisons with other databases or ways to 96 solve the big dataset access problem... 97 */ 98 99 #define NEW 1 100 #define OLD 0 101 102 #define DEFAULT_DBH_DATASIZE 1024 103 104 #define READ 0 105 #define WRITE 1 106 #define DOWN 0 107 #define UP 1 108 109 #define WRITEBRANCHES 1 110 #define DONTWRITEBRANCHES 0 111 112 #define PRESENTE 0 113 #define PRESENTE_MENOR_BOF 0 114 #define PRESENTE_MENOR 1 115 #define PRESENTE_MAYORIGUAL 2 116 #define ARCHIVO_VACIO 3 117 #define NO_PRESENTE 4 118 119 #define PARALLEL_UNSAFE 0x01 120 #define THREAD_UNSAFE 0x02 121 122 #define ERASED (dbh->flag&0x01) 123 #define TOGGLE_ERASE (dbh->flag ^= 0x01) 124 #define SET_UNERASED (dbh->flag &= (0xff ^ 0x01)) 125 #define SET_ERASED (dbh->flag |= 0x01) 126 #define EZIP_NUMERO_MAXIMO 16777215 127 128 129 #ifdef HAVE_WINDOWS_H 130 # include <windows.h> 131 #endif 132 133 /* static: 134 * This includes object symbols which will not be exported during link.*/ 135 #include "dbh_static.i" 136 137 /* global: 138 * This includes object symbols which will be exported during link. 139 * Functions in this file should be defined in dbh.h (generated from 140 * dbh.h.in when configure script is run). Function definitions 141 * should include comments in gtk-doc format for html documentation 142 * generation.*/ 143 #include "dbh_exported.i" 144