8000910e6b8abf74aaf907a57be5efa7a170bc3b
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 void get_random_string(char *buffer
, size_t size
)
18 char *buffer_ptr
= buffer
;
21 *buffer_ptr
++= ALPHANUMERICS
[random() % ALPHANUMERICS_SIZE
];
22 *buffer_ptr
++= ALPHANUMERICS
[random() % ALPHANUMERICS_SIZE
];
25 void pairs_free(pairs_st
*pairs
)
32 /* We free until we hit the null pair we stores during creation */
33 for (x
= 0; pairs
[x
].key
; x
++)
42 pairs_st
*pairs_generate(uint64_t number_of
, size_t value_length
)
47 pairs
= (pairs_st
*)malloc(sizeof(pairs_st
) * (number_of
+1));
52 memset(pairs
, 0, sizeof(pairs_st
) * (number_of
+1));
54 for (x
= 0; x
< number_of
; x
++)
56 pairs
[x
].key
= (char *)malloc(sizeof(char) * 100);
59 get_random_string(pairs
[x
].key
, 100);
60 pairs
[x
].key_length
= 100;
62 pairs
[x
].value
= (char *)malloc(sizeof(char) * value_length
);
65 get_random_string(pairs
[x
].value
, value_length
);
66 pairs
[x
].value_length
= value_length
;
71 fprintf(stderr
, "Memory Allocation failure in pairs_generate.\n");