SYNOPSIS


int sdbmopen(char *filename, int readonly);

The sdbmopen() function creates or opens an existing DBM file for basic database operations.

RETURN VALUES

Returns a dbm object handle for additional operations.

EXAMPLES

dbm = sdbmopen("./test.dbm", 0);
sdbminsert(dbm, "key0", "This is insert test 0");
sdbminsert(dbm, "key1", "This is insert test 1");
sdbminsert(dbm, "key2", "This is insert test 2");
sdbminsert(dbm, "key3", "This is insert test 3");
sdbminsert(dbm, "key4", "This is insert test 4");
sdbminsert(dbm, "key5", "This is insert test 5");
sdbminsert(dbm, "key6", "This is insert test 6");

val = sdbmfetch(dbm, "key1");
if (val != "This is insert test 1")
    printf("key1 did not return the correct result.\n");

sdbmreplace(dbm, "key2", "Replacement text for test 2");
val = sdbmfetch(dbm, "key2");
if (val != "Replacement text for test 2")
    printf("key2 did not return the correct result.\n");

sdbmdelete(dbm, "key0");
sdbmdelete(dbm, "key6");

i = 0;
val = sdbmfirstkey(dbm);
while (val)
{
    val = sdbmnextkey(dbm);
    i++;
}

if (i != 5)
    printf("Expected 5 keys in DBM database, only found %d\n", i);

printf("Found all %d keys in DBM database\n", i);

sdbmclose(dbm);

// Delete the DBM files created.
rm("./test.dbm.dir");
rm("./test.dbm.pag");