Sha256: f1d6e437b923c86594a42b58766a2837a37d2b487f5e8cc8c5f8f579459292fe

Contents?: true

Size: 1.55 KB

Versions: 27

Compression:

Stored size: 1.55 KB

Contents

#include "libmemcached/common.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include "generator.h"

/* Use this for string generation */
static const char ALPHANUMERICS[]=
  "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";

#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)

static size_t get_alpha_num(void)
{
  return (size_t)random() % ALPHANUMERICS_SIZE;
}

static void get_random_string(char *buffer, size_t size)
{
  char *buffer_ptr= buffer;

  while (--size)
    *buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
  *buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
}

void pairs_free(pairs_st *pairs)
{
  uint32_t x;

  if (!pairs)
    return;

  /* We free until we hit the null pair we stores during creation */
  for (x= 0; pairs[x].key; x++)
  {
    free(pairs[x].key);
    free(pairs[x].value);
  }

  free(pairs);
}

pairs_st *pairs_generate(uint64_t number_of, size_t value_length)
{
  unsigned int x;
  pairs_st *pairs= calloc((size_t)(number_of + 1), sizeof(pairs_st));

  if (!pairs)
    goto error;

  for (x= 0; x < number_of; x++)
  {
    pairs[x].key= (char *)calloc(100, sizeof(char));
    if (!pairs[x].key)
      goto error;
    get_random_string(pairs[x].key, 100);
    pairs[x].key_length= 100;

    pairs[x].value= (char *)calloc(value_length, sizeof(char));
    if (!pairs[x].value)
      goto error;
    get_random_string(pairs[x].value, value_length);
    pairs[x].value_length= value_length;
  }

  return pairs;
error:
    fprintf(stderr, "Memory Allocation failure in pairs_generate.\n");
    exit(0);
}

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
vinted-memcached-1.8.5 vendor/libmemcached-0.32/clients/generator.c
vinted-memcached-1.8.4 ext/libmemcached-0.32/clients/generator.c
vinted-memcached-1.8.3 ext/libmemcached-0.32/clients/generator.c
vinted-memcached-1.8.2 ext/libmemcached-0.32/clients/generator.c
vinted-memcached-1.8.0 ext/libmemcached-0.32/clients/generator.c
dalli_memcached-1.8.0 ext/libmemcached-0.32/clients/generator.c
memcached-1.8.0 ext/libmemcached-0.32/clients/generator.c
memcached-1.7.2 ext/libmemcached-0.32/clients/generator.c
memcached-1.7.0 ext/libmemcached-0.32/clients/generator.c
memcached-1.6.1 ext/libmemcached-0.32/clients/generator.c
memcached-1.6.0 ext/libmemcached-0.32/clients/generator.c
memcached-1.5.1 ext/libmemcached-0.32/clients/generator.c
memcached-1.5.0 ext/libmemcached-0.32/clients/generator.c
boourns-memcached-1.4.6 ext/libmemcached-0.32/clients/generator.c
memcached-1.4.6 ext/libmemcached-0.32/clients/generator.c
memcached-1.4.5 ext/libmemcached-0.32/clients/generator.c
memcached-1.4.3 ext/libmemcached-0.32/clients/generator.c
memcached-1.4.2 ext/libmemcached-0.32/clients/generator.c
memcached-1.4.1 ext/libmemcached-0.32/clients/generator.c
memcached-1.3.7 ext/libmemcached-0.32/clients/generator.c