1
1
2
- /* (C)opyleft 2001-2022 Frank DENIS */
2
+ /* (C)opyleft 2001-2022 Frank DENIS <j at pureftpd dot org> */
3
3
4
4
#include <config.h>
5
5
6
6
#include "puredb_p.h"
7
7
#include "puredb_write.h"
8
8
9
+ #ifndef HAVE_STRDUP
10
+ static char * strdup (const char * str )
11
+ {
12
+ char * newstr ;
13
+ size_t str_len_1 ;
14
+
15
+ if (str == NULL ||
16
+ (str_len_1 = strlen (str ) + (size_t ) 1U ) <= (size_t ) 0U ||
17
+ (newstr = malloc (str_len_1 )) == NULL ) {
18
+ return NULL ;
19
+ }
20
+ memcpy (newstr , str , str_len_1 );
21
+
22
+ return newstr ;
23
+ }
24
+ #endif
25
+
9
26
static puredb_u32_t puredbw_hash (const char * const msg , size_t len )
10
27
{
11
28
puredb_u32_t j = (puredb_u32_t ) 5381U ;
@@ -85,8 +102,8 @@ int puredbw_add(PureDBW * const dbw,
85
102
hash0 -> hash1_list = newpnt ;
86
103
}
87
104
dbw -> offset_first_data += sizeof (puredb_u32_t ) + sizeof (puredb_u32_t );
88
- hash1 = (Hash1 * ) ((unsigned char * ) hash0 -> hash1_list +
89
- hash0 -> hash1_list_size - sizeof (Hash1 ));
105
+ hash1 = (Hash1 * ) (void * ) ( (unsigned char * ) hash0 -> hash1_list +
106
+ hash0 -> hash1_list_size - sizeof (Hash1 ));
90
107
hash1 -> hash = hash ;
91
108
hash1 -> offset_data = dbw -> data_offset_counter ;
92
109
dbw -> data_offset_counter += sizeof (puredb_u32_t ) + sizeof (puredb_u32_t ) +
@@ -125,8 +142,8 @@ int puredbw_add_s(PureDBW * const dbw,
125
142
126
143
static int hash1_cmp_hook (const void * const a , const void * const b )
127
144
{
128
- register puredb_u32_t ha = ((const Hash1 * ) a )-> hash ;
129
- register puredb_u32_t hb = ((const Hash1 * ) b )-> hash ;
145
+ puredb_u32_t ha = ((const Hash1 * ) a )-> hash ;
146
+ puredb_u32_t hb = ((const Hash1 * ) b )-> hash ;
130
147
131
148
if (ha < hb ) {
132
149
return -1 ;
@@ -145,9 +162,9 @@ static int hash1_cmp_hook(const void * const a, const void * const b)
145
162
146
163
static int writekeys (PureDBW * const dbw )
147
164
{
148
- register int hash_cnt = (int )
165
+ int hash_cnt = (int )
149
166
(sizeof dbw -> hash_table0 / sizeof dbw -> hash_table0 [0 ]);
150
- register const Hash0 * hash0 = dbw -> hash_table0 ;
167
+ const Hash0 * hash0 = dbw -> hash_table0 ;
151
168
152
169
puredb_u32_t offset = (puredb_u32_t )
153
170
((1U + sizeof dbw -> hash_table0 / sizeof dbw -> hash_table0 [0 ]) *
@@ -183,8 +200,8 @@ static int writekeys(PureDBW * const dbw)
183
200
hash_cnt = (int ) (sizeof dbw -> hash_table0 / sizeof dbw -> hash_table0 [0 ]);
184
201
hash0 = dbw -> hash_table0 ;
185
202
do {
186
- register Hash1 * hash1 = hash0 -> hash1_list ;
187
- register size_t list_size = hash0 -> hash1_list_size ;
203
+ Hash1 * hash1 = hash0 -> hash1_list ;
204
+ size_t list_size = hash0 -> hash1_list_size ;
188
205
189
206
if (hash1 == NULL ) {
190
207
const puredb_u32_t null_ =
@@ -229,14 +246,12 @@ static int writekeys(PureDBW * const dbw)
229
246
230
247
static int freestructs (PureDBW * const dbw )
231
248
{
232
- register Hash0 * hash0 = dbw -> hash_table0 ;
249
+ Hash0 * hash0 = dbw -> hash_table0 ;
233
250
int hash0_cnt = (int ) (sizeof dbw -> hash_table0 / sizeof dbw -> hash_table0 [0 ]);
234
251
235
252
do {
236
- if (hash0 -> hash1_list != NULL ) {
237
- free (hash0 -> hash1_list );
238
- hash0 -> hash1_list = NULL ;
239
- }
253
+ free (hash0 -> hash1_list );
254
+ hash0 -> hash1_list = NULL ;
240
255
hash0 ++ ;
241
256
hash0_cnt -- ;
242
257
} while (hash0_cnt > 0 );
@@ -246,13 +261,13 @@ static int freestructs(PureDBW * const dbw)
246
261
247
262
static int mergefiles (PureDBW * const dbw )
248
263
{
249
- size_t readen ;
264
+ size_t readnb ;
250
265
char buf [4096 ];
251
266
252
267
rewind (dbw -> fpdata );
253
- while ((readen = fread (buf , (size_t ) 1U , sizeof buf , dbw -> fpdata )) >
268
+ while ((readnb = fread (buf , (size_t ) 1U , sizeof buf , dbw -> fpdata )) >
254
269
(size_t ) 0U ) {
255
- if (fwrite (buf , (size_t ) 1U , readen , dbw -> fpindex ) != readen ) {
270
+ if (fwrite (buf , (size_t ) 1U , readnb , dbw -> fpindex ) != readnb ) {
256
271
return -1 ;
257
272
}
258
273
}
@@ -293,18 +308,12 @@ static void freeall(PureDBW * const dbw)
293
308
fclose (dbw -> fpdata );
294
309
dbw -> fpdata = NULL ;
295
310
}
296
- if (dbw -> file_index != NULL ) {
297
- free (dbw -> file_index );
298
- dbw -> file_index = NULL ;
299
- }
300
- if (dbw -> file_data != NULL ) {
301
- free (dbw -> file_data );
302
- dbw -> file_data = NULL ;
303
- }
304
- if (dbw -> file_final != NULL ) {
305
- free (dbw -> file_final );
306
- dbw -> file_final = NULL ;
307
- }
311
+ free (dbw -> file_index );
312
+ dbw -> file_index = NULL ;
313
+ free (dbw -> file_data );
314
+ dbw -> file_data = NULL ;
315
+ free (dbw -> file_final );
316
+ dbw -> file_final = NULL ;
308
317
}
309
318
310
319
void puredbw_free (PureDBW * const dbw )
0 commit comments