File: example.c

package info (click to toggle)
dnprogs 2.43.2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,936 kB
  • ctags: 3,872
  • sloc: ansic: 24,686; cpp: 10,608; makefile: 769; sh: 551; awk: 13
file content (59 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (4)
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
/* Example librms program using the RAB/FAB functions.

   This program is in the public domain
*/

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include "rms.h"

int main(int argc, char *argv[])
{
    /* Open the file. Keep the RMSHANDLE returned */
    RMSHANDLE h;

    h = rms_open("ford::index.dat", O_RDWR, NULL);

    if (h)
    {
        char b[10240];
	int got;
	struct RAB rab;

	/* Clear out the rab */
	memset(&rab, 0, sizeof(rab));

	/* Look for the record with my name in it. */
	rab.rab$b_rac = RAB$C_KEY;
	rab.rab$l_kbf = "PATRICK";
	
	got = rms_read(h, b, sizeof(b), &rab);
	if (got > 0)
	{
	    b[got] = '\0';
	    printf("Got %d bytes: %s\n", got, b);
	}
	else
	{
	    fprintf(stderr, "%s\n", rms_lasterror(h));
	}

        /* Update it */
	memcpy(b+8, "????", 4);
	if (rms_update(h, b, got, NULL) == -1)
	{
	    fprintf(stderr, "%s\n", rms_lasterror(h));
	}
	
	rms_close(h);
    }
    else
    {
	fprintf(stderr, "connect: %s\n", rms_openerror());
    }

    return 0;
}