Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 64ab583f3e
Fetching contributors…

Cannot retrieve contributors at this time

file 68 lines (60 sloc) 2.482 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/*
* testzero - size test for mcdb creation: generate given num of 64K records
*
* Copyright (c) 2010, Glue Logic LLC. All rights reserved. code()gluelogic.com
*
* This file is part of mcdb.
*
* mcdb is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* mcdb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mcdb. If not, see <http://www.gnu.org/licenses/>.
*
*
* mcdb is originally based upon the Public Domain cdb-0.75 by Dan Bernstein
*/

#include "mcdb.h"
#include "mcdb_make.h"
#include "mcdb_error.h"
#include "nointr.h"
#include "uint32.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /* open() */
#include <stdlib.h> /* strtoul() */
#include <unistd.h> /* close() */

/* write keylen,datalen,key,value exactly 64K for convenience troubleshooting
* (4-byte keylen + 4-byte datalen + 4-byte key + 65524 byte data = 65536) */
static const char data[65536-12];

int
main(int argc,char **argv)
{
    struct mcdb_make m;
    uint32_t loop = argc > 1 ? (uint32_t)strtoul(argv[1], NULL, 10) : 0;
    const int fd = argc > 2 ? nointr_open(argv[2], O_RDWR|O_CREAT, 0666) : -1;
    char buf[4];
    /*(avoid gcc warning using key with uint32_strpack_bigendian_aligned_macro:
* dereferencing type-punned pointer will break strict-aliasing rules)*/
    char * const key = buf;

    if (mcdb_make_start(&m,fd,malloc,free) == -1)
        return mcdb_error(MCDB_ERROR_WRITE, "testzero", "");

    while (loop--) {
        uint32_strpack_bigendian_aligned_macro(key,loop);
        if (mcdb_make_add(&m,key,sizeof(uint32_t),data,sizeof(data)) == -1)
            return mcdb_error(MCDB_ERROR_WRITE, "testzero", "");
    }

    if (mcdb_make_finish(&m) == -1 || (fd != -1 && nointr_close(fd) != 0))
        return mcdb_error(MCDB_ERROR_WRITE, "testzero", "");
    /* Note: fdatasync(m.fd) is not called here due to type of usage here.
* See comments in mcdb_make.c:mcdb_mmap_commit() for when to use
* fsync() or fdatasync(). */

    return 0;
}
Something went wrong with that request. Please try again.