IDZEBRA  2.1.2
tstmfile1.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <errno.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <yaz/test.h>
29 #include "mfile.h"
30 
31 #define BLOCK_SIZE 16
32 
33 void tst1(void)
34 {
35  MFile_area a = mf_init("main", 0 /* spec */, 0 /* base */, 0 /* only sh */);
36  YAZ_CHECK(a);
37  mf_destroy(a);
38 }
39 
40 void tst2(void)
41 {
42  char buf[BLOCK_SIZE];
43  MFile_area a = mf_init("main", 0 /* spec */, 0 /* base */, 0 /* only sh */);
44  MFile f;
45 
46  YAZ_CHECK(a);
47 
48  mf_reset(a, 1);
49 
50  f = mf_open(a, "mymfile", BLOCK_SIZE, 1);
51  YAZ_CHECK(f);
52 
53  YAZ_CHECK_EQ(mf_read(f, 0, 0, 0, buf), 0);
54 
55  memset(buf, 'a', BLOCK_SIZE);
56  YAZ_CHECK_EQ(mf_write(f, 0, 0, 0, buf), 0);
57 
58  YAZ_CHECK_EQ(mf_read(f, 0, 0, 0, buf), 1);
59 
60  mf_close(f);
61 
62  mf_destroy(a);
63 }
64 
65 int main(int argc, char **argv)
66 {
67  YAZ_CHECK_INIT(argc, argv);
68  tst1();
69  tst2();
70  YAZ_CHECK_TERM;
71 }
72 
int main(int argc, char **argv)
Definition: tstmfile1.c:65
MFile_area mf_init(const char *name, const char *spec, const char *base, int only_shadow_files)
creates a metafile area
Definition: mfile.c:195
#define BLOCK_SIZE
Definition: tstmfile1.c:31
int mf_close(MFile mf)
closes metafile
Definition: mfile.c:429
void mf_destroy(MFile_area ma)
destroys metafile area handle
Definition: mfile.c:307
int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
writes block to metafile
Definition: mfile.c:484
void mf_reset(MFile_area ma, int unlink_flag)
reset all files in a metafile area (optionally delete them as well)
Definition: mfile.c:324
void tst2(void)
Definition: tstmfile1.c:40
int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf)
reads block from metafile
Definition: mfile.c:451
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
opens metafile
Definition: mfile.c:351
void tst1(void)
Definition: tstmfile1.c:33