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