X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fread-marc.c;h=5f0f79ef0a589387759aade7114057197d585452;hp=850b7060322fb541dbcf8368e9fb3f7c8fa29274;hb=c82f99e98f3b27c06d68eac02871a9b92486a89d;hpb=905df6869e5ad8ab9f34590cce771fe50c444473 diff --git a/ztest/read-marc.c b/ztest/read-marc.c index 850b706..5f0f79e 100644 --- a/ztest/read-marc.c +++ b/ztest/read-marc.c @@ -1,18 +1,19 @@ -/* - * Copyright (c) 2002, Index Data. +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: read-marc.c,v 1.5 2004-12-30 00:18:04 adam Exp $ */ -/* - * Little toy-thing to read a MARC records from a fixed array. +/** \file + * \brief Little toy-thing to read MARC records from a file or fixed array. */ + #include #include #include #include +#include "ztest.h" + char *marc_records[] = { "\x30\x30\x33\x36\x36\x6E\x61\x6D\x20\x20\x32\x32\x30\x30\x31\x36" @@ -1574,12 +1575,6 @@ char *dummy_marc_record (int num, ODR odr) FILE *inf; char *buf = 0; - if (num == 98) - { /* this will generate a very bad MARC record (testing only) */ - buf = (char*) odr_malloc(odr, 2101); - memset(buf, '7', 2100); - buf[2100] = '\0'; - } inf = fopen ("dummy-records", "r"); if (!inf) { /* file not there. Get them from fixed array */ @@ -1602,8 +1597,8 @@ char *dummy_marc_record (int num, ODR odr) char *dummy_xml_record (int num, ODR odr) { yaz_marc_t mt = yaz_marc_create(); - char *result; - int rlen; + const char *result; + size_t rlen; char *rec = dummy_marc_record (num, odr); int len; @@ -1613,7 +1608,20 @@ char *dummy_xml_record (int num, ODR odr) yaz_marc_xml(mt, YAZ_MARC_MARCXML); len = yaz_marc_decode_buf (mt, rec, -1, &result, &rlen); if (len > 1) - rec = (char *) odr_strdup(odr, result); + { + rec = (char *) odr_malloc(odr, rlen+1); + memcpy(rec, result, rlen); + rec[rlen] = '\0'; + } yaz_marc_destroy(mt); return rec; } +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +