1 /* $Id: zoom-bug-641.c,v 1.2 2007-01-03 08:42:17 adam Exp $ */
3 /** \file zoom-bug641.c
4 \brief Program to illustrate bug 641
13 #include <yaz/xmalloc.h>
19 int main(int argc, char **argv)
23 const char *errmsg, *addinfo;
26 fprintf(stderr, "Usage:\n%s <target> <file> [<file> ...]\n", argv[0]);
27 fprintf(stderr, " eg. bagel.indexdata.dk/gils foo.xml bar.xml\n");
31 z = ZOOM_connection_create(0);
33 for (i = 2; i < argc; i++) {
34 char *buf, *fn = argv[i];
36 size_t size, offset = 0;
39 ZOOM_connection_connect(z, argv[1], 0);
40 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo))) {
41 fprintf(stderr, "Error: %s (%d) %s\n", errmsg, error, addinfo);
45 if (stat(fn, &statbuf) < 0 ||
46 (fd = open(fn, O_RDONLY)) < 0) {
50 size = statbuf.st_size;
51 printf("size=%lu\n", (unsigned long) size);
52 buf = xmalloc(size+1);
53 while ((n = read(fd, &buf[offset], size)) < size) {
65 ZOOM_package pkg = ZOOM_connection_package(z, 0);
66 ZOOM_package_option_set(pkg, "action", "specialUpdate");
67 ZOOM_package_option_set(pkg, "record", buf);
68 ZOOM_package_send(pkg, "update");
69 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo))) {
70 printf("file '%s': error %d (%s) %s\n",
71 fn, error, errmsg, addinfo);
73 printf("file '%s': ok\n", fn);
78 if (i < argc-1) sleep(2);
81 ZOOM_connection_destroy(z);
87 * indent-tabs-mode: nil
89 * vim: shiftwidth=4 tabstop=8 expandtab