dd10b4fd868cd178c02ebff81005f2259c974b9b
[idzebra-moved-to-github.git] / bfile / bfile.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: bfile.c,v $
7  * Revision 1.8  1994-08-23 15:03:34  quinn
8  * *** empty log message ***
9  *
10  * Revision 1.7  1994/08/23  14:25:45  quinn
11  * Added O_CREAT because some geek wanted it. Sheesh.
12  *
13  * Revision 1.6  1994/08/23  14:21:38  quinn
14  * Fixed call to log
15  *
16  * Revision 1.5  1994/08/18  08:10:08  quinn
17  * Minimal changes
18  *
19  * Revision 1.4  1994/08/17  14:27:32  quinn
20  * last mods
21  *
22  * Revision 1.2  1994/08/17  14:09:32  quinn
23  * Compiles cleanly (still only dummy).
24  *
25  * Revision 1.1  1994/08/17  13:55:08  quinn
26  * New blocksystem. dummy only
27  *
28  */
29
30 #include <util.h>
31 #include <bfile.h>
32 #include <sys/types.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <stdlib.h>
36
37 int bf_close (BFile bf)
38 {
39     close(bf->fd);
40     xfree(bf);
41     return(0);
42 }
43
44 BFile bf_open (const char *name, int block_size, int wflag)
45 {
46     BFile tmp = xmalloc(sizeof(BFile_struct));
47
48     if ((tmp->fd = open(name, wflag ? O_RDWR|O_CREAT : O_RDONLY, 0666)) < 0)
49     {
50         log(LOG_FATAL|LOG_ERRNO, "open %s", name); 
51         return(0);
52     }
53     tmp->block_size = block_size;
54     return(tmp);
55 }
56
57 int bf_read (BFile bf, int no, int offset, int num, void *buf)
58 {
59     lseek(bf->fd, no * bf->block_size + offset, 0);
60     return(read(bf->fd, buf, num ? num : bf->block_size));
61 }
62
63 int bf_write (BFile bf, int no, int offset, int num, const void *buf)
64 {
65     lseek(bf->fd, no * bf->block_size + offset, 0);
66     return(write(bf->fd, buf, num ? num : bf->block_size));
67 }