File: cdbget.c

package info (click to toggle)
freecdb 0.61
  • links: PTS
  • area: main
  • in suites: potato
  • size: 116 kB
  • ctags: 90
  • sloc: ansic: 614; makefile: 91; sh: 12
file content (36 lines) | stat: -rw-r--r-- 572 bytes parent folder | download | duplicates (2)
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
#include <stdio.h>
#include "freecdb.h"

int main(argc,argv)
int argc;
char **argv;
{
  uint32_t len;
  int c;

  if (!argv[1]) {
    fputs("cdbget: usage: cdbget key\n",stderr);
    exit(2);
  }

  switch(cdb_seek(0,argv[1],strlen(argv[1]),&len)) {
    case -1:
      perror("cdbget: fatal");
      exit(111);
    case 0:
      exit(1);
  }

  /* We'll use stdio to read the next len bytes from fd 0. */

  while (len--) {
    c = getchar();
    if (c == EOF) {
      fputs("cdbget: fatal: out of data\n",stderr);
      exit(111);
    }
    putchar(c);
  }

  exit(0);
}