213246ba2206a3d84916c8503c43c089bc26e975
1 #include "libmemcached/common.h"
10 /* Use this for string generation */
11 static const char ALPHANUMERICS
[]=
12 "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
14 #define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
16 static size_t get_alpha_num(void)
18 return (size_t)random() % ALPHANUMERICS_SIZE
;
21 static void get_random_string(char *buffer
, size_t size
)
23 char *buffer_ptr
= buffer
;
26 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
27 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
30 void pairs_free(pairs_st
*pairs
)
37 /* We free until we hit the null pair we stores during creation */
38 for (x
= 0; pairs
[x
].key
; x
++)
47 pairs_st
*pairs_generate(uint64_t number_of
, size_t value_length
)
50 pairs_st
*pairs
= calloc((size_t)(number_of
+ 1), sizeof(pairs_st
));
55 for (x
= 0; x
< number_of
; x
++)
57 pairs
[x
].key
= (char *)calloc(100, sizeof(char));
60 get_random_string(pairs
[x
].key
, 100);
61 pairs
[x
].key_length
= 100;
63 pairs
[x
].value
= (char *)calloc(value_length
, sizeof(char));
66 get_random_string(pairs
[x
].value
, value_length
);
67 pairs
[x
].value_length
= value_length
;
72 fprintf(stderr
, "Memory Allocation failure in pairs_generate.\n");