ECP-VELOC Components
User documentation for all components
kvtree_io.h
Go to the documentation of this file.
1 #ifndef KVTREE_IO_H
2 #define KVTREE_IO_H
3 
4 #include <config.h>
5 #include <stdarg.h>
6 #include <sys/types.h>
7 
8 /* compute crc32 */
9 #include <zlib.h>
10 
11 #ifndef KVTREE_MAX_LINE
12 #define KVTREE_MAX_LINE (1024)
13 #endif
14 
15 /* adds byte swapping routines */
16 #if defined(__APPLE__)
17 #include "machine/endian.h"
18 #else
19 #include "endian.h"
20 #endif
21 
22 #ifdef HAVE_BYTESWAP_H
23 #include "byteswap.h"
24 #else
25 #include "kvtree_byteswap.h"
26 #endif
27 
28 #if __BYTE_ORDER == __LITTLE_ENDIAN
29 #ifdef HAVE_BYTESWAP_H
30 # define kvtree_ntoh16(x) bswap_16(x)
31 # define kvtree_ntoh32(x) bswap_32(x)
32 # define kvtree_ntoh64(x) bswap_64(x)
33 # define kvtree_hton16(x) bswap_16(x)
34 # define kvtree_hton32(x) bswap_32(x)
35 # define kvtree_hton64(x) bswap_64(x)
36 #else
37 # define kvtree_ntoh16(x) kvtree_bswap_16(x)
38 # define kvtree_ntoh32(x) kvtree_bswap_32(x)
39 # define kvtree_ntoh64(x) kvtree_bswap_64(x)
40 # define kvtree_hton16(x) kvtree_bswap_16(x)
41 # define kvtree_hton32(x) kvtree_bswap_32(x)
42 # define kvtree_hton64(x) kvtree_bswap_64(x)
43 #endif
44 #else
45 # define kvtree_ntoh16(x) (x)
46 # define kvtree_ntoh32(x) (x)
47 # define kvtree_ntoh64(x) (x)
48 # define kvtree_hton16(x) (x)
49 # define kvtree_hton32(x) (x)
50 # define kvtree_hton64(x) (x)
51 #endif
52 
53 #define KVTREE_OPEN_TRIES (5)
54 #define KVTREE_OPEN_USLEEP (100)
55 
56 
58 mode_t kvtree_getmode(int read, int write, int execute);
59 
61 int kvtree_open(const char* file, int flags, ...);
62 
64 int kvtree_close(const char* file, int fd);
65 
67 int kvtree_file_lock_write(const char* file, int fd);
68 int kvtree_file_unlock(const char* file, int fd);
69 
72 int kvtree_open_with_lock(const char* file, int flags, mode_t mode, int write);
73 
75 int kvtree_close_with_unlock(const char* file, int fd);
76 
78 int kvtree_lseek(const char* file, int fd, off_t pos, int whence);
79 
81 ssize_t kvtree_read_attempt(const char* file, int fd, void* buf, size_t size);
82 
84 ssize_t kvtree_write_attempt(const char* file, int fd, const void* buf, size_t size);
85 
87 int kvtree_file_is_readable(const char* file);
88 
89 #endif
kvtree_open
int kvtree_open(const char *file, int flags,...)
kvtree_open_with_lock
int kvtree_open_with_lock(const char *file, int flags, mode_t mode, int write)
kvtree_lseek
int kvtree_lseek(const char *file, int fd, off_t pos, int whence)
kvtree_getmode
mode_t kvtree_getmode(int read, int write, int execute)
kvtree_close
int kvtree_close(const char *file, int fd)
kvtree_file_unlock
int kvtree_file_unlock(const char *file, int fd)
kvtree_write_attempt
ssize_t kvtree_write_attempt(const char *file, int fd, const void *buf, size_t size)
kvtree_file_lock_write
int kvtree_file_lock_write(const char *file, int fd)
kvtree_file_is_readable
int kvtree_file_is_readable(const char *file)
kvtree_read_attempt
ssize_t kvtree_read_attempt(const char *file, int fd, void *buf, size_t size)
kvtree_close_with_unlock
int kvtree_close_with_unlock(const char *file, int fd)