File: samp1.cc

package info (click to toggle)
gdbm173 1.7.3-28
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 540 kB
  • ctags: 343
  • sloc: ansic: 3,527; makefile: 218; sh: 81; cpp: 25
file content (36 lines) | stat: -rw-r--r-- 921 bytes parent folder | download | duplicates (8)
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
// small c++ to open store then close a gdbm file 
// by Mike MacFaden 4/93  mike@premisys.com
// tested with gdbm 1.5 and gnu v2.2 c++ compiler

#include "iostream.h"
#include "gdbm.h"

extern int errno;		/* C runtime library */

int main(int argc, char *argv[])
{
	cout << "Sample C++ program create a gdbm file ./tgdbm " << endl;

	GDBM_FILE pfile = gdbm_open("tstgdbm", 512, GDBM_WRCREAT, 00664, 0);
	if (!pfile)
      {
      cout << "main:gdbm_open " << gdbm_errno << errno << endl;
      return -1;
      }

   datum key = {"foo", strlen("foo")+1};
   datum val = {"bar", strlen("bar")+1};

	cout << "key is  : " << key.dptr << endl;
	cout << "data is : " << val.dptr << endl;

   if (gdbm_store(pfile, key, val, GDBM_INSERT) != 0)
      {
      cout << "main:gdbm_store " << gdbm_errno << errno << endl;
      return -1;
      }
	gdbm_close(pfile);

	cout << "Sample C++ program complete" << endl;
	return 0;		
}