1*50988Sbostic /*- 2*50988Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*50988Sbostic * All rights reserved. 4*50988Sbostic * 5*50988Sbostic * This code is derived from software contributed to Berkeley by 6*50988Sbostic * Margo Seltzer. 7*50988Sbostic * 8*50988Sbostic * %sccs.include.redist.c% 9*50988Sbostic */ 10*50988Sbostic 11*50988Sbostic #ifndef lint 12*50988Sbostic char copyright[] = 13*50988Sbostic "@(#) Copyright (c) 1991 The Regents of the University of California.\n\ 14*50988Sbostic All rights reserved.\n"; 15*50988Sbostic #endif /* not lint */ 16*50988Sbostic 17*50988Sbostic #ifndef lint 18*50988Sbostic static char sccsid[] = "@(#)driver2.c 5.1 (Berkeley) 09/04/91"; 19*50988Sbostic #endif /* not lint */ 20*50988Sbostic 21*50988Sbostic /* 22*50988Sbostic * Test driver, to try to tackle the large ugly-split problem. 23*50988Sbostic */ 24*50988Sbostic 25*50988Sbostic #include <sys/file.h> 26*50988Sbostic #include <stdio.h> 27*50988Sbostic #include "ndbm.h" 28*50988Sbostic 29*50988Sbostic int my_hash(key, len) 30*50988Sbostic char *key; 31*50988Sbostic int len; 32*50988Sbostic { 33*50988Sbostic return(17); /* So I'm cruel... */ 34*50988Sbostic } 35*50988Sbostic 36*50988Sbostic main(argc, argv) 37*50988Sbostic int argc; 38*50988Sbostic { 39*50988Sbostic DB *db; 40*50988Sbostic DBT key, content; 41*50988Sbostic char keybuf[2049]; 42*50988Sbostic char contentbuf[2049]; 43*50988Sbostic char buf[256]; 44*50988Sbostic int i; 45*50988Sbostic HASHINFO info; 46*50988Sbostic 47*50988Sbostic info.bsize = 1024; 48*50988Sbostic info.ffactor = 5; 49*50988Sbostic info.nelem = 1; 50*50988Sbostic info.cachesize = NULL; 51*50988Sbostic #ifdef HASH_ID_PROGRAM_SPECIFIED 52*50988Sbostic info.hash_id = HASH_ID_PROGRAM_SPECIFIED; 53*50988Sbostic info.hash_func = my_hash; 54*50988Sbostic #else 55*50988Sbostic info.hash = my_hash; 56*50988Sbostic #endif 57*50988Sbostic info.lorder = 0; 58*50988Sbostic if (!(db = hash_open("bigtest", O_RDWR | O_CREAT, 0644, &info))) { 59*50988Sbostic sprintf(buf, "hash_open failed on file bigtest"); 60*50988Sbostic perror(buf); 61*50988Sbostic exit(1); 62*50988Sbostic } 63*50988Sbostic srandom(17); 64*50988Sbostic key.data = keybuf; 65*50988Sbostic content.data = contentbuf; 66*50988Sbostic bzero(keybuf, sizeof(keybuf)); 67*50988Sbostic bzero(contentbuf, sizeof(contentbuf)); 68*50988Sbostic for (i=1; i <= 500; i++) { 69*50988Sbostic key.size = 128 + (random()&1023); 70*50988Sbostic content.size = 128 + (random()&1023); 71*50988Sbostic /* printf("%d: Key size %d, data size %d\n", i, key.size, 72*50988Sbostic content.size); */ 73*50988Sbostic sprintf(keybuf, "Key #%d", i); 74*50988Sbostic sprintf(contentbuf, "Contents #%d", i); 75*50988Sbostic if ((db->put)(db, &key, &content, R_NOOVERWRITE)) { 76*50988Sbostic sprintf(buf, "dbm_store #%d", i); 77*50988Sbostic perror(buf); 78*50988Sbostic } 79*50988Sbostic } 80*50988Sbostic if ((db->close)(db)) { 81*50988Sbostic perror("closing hash file"); 82*50988Sbostic exit(1); 83*50988Sbostic } 84*50988Sbostic exit(0); 85*50988Sbostic } 86*50988Sbostic 87*50988Sbostic 88*50988Sbostic 89