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
)
52 pairs
= (pairs_st
*)calloc((size_t)number_of
+ 1, sizeof(pairs_st
));
57 for (x
= 0; x
< number_of
; x
++)
59 pairs
[x
].key
= (char *)calloc(100, sizeof(char));
62 get_random_string(pairs
[x
].key
, 100);
63 pairs
[x
].key_length
= 100;
65 pairs
[x
].value
= (char *)calloc(value_length
, sizeof(char));
68 get_random_string(pairs
[x
].value
, value_length
);
69 pairs
[x
].value_length
= value_length
;
74 fprintf(stderr
, "Memory Allocation failure in pairs_generate.\n");