File: fa.h

package info (click to toggle)
genometools 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 57,988 kB
  • ctags: 45,574
  • sloc: ansic: 475,937; ruby: 24,092; python: 4,519; sh: 3,014; perl: 2,523; makefile: 1,839; java: 158; haskell: 37; xml: 6; sed: 5
file content (180 lines) | stat: -rw-r--r-- 8,531 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
  Copyright (c) 2007-2010 Gordon Gremme <gordon@gremme.org>
  Copyright (c) 2007-2008 Center for Bioinforfatics, University of Hamburg

  Permission to use, copy, modify, and distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
  copyright notice and this permission notice appear in all copies.

  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef FA_H
#define FA_H

#ifndef S_SPLINT_S
#include <bzlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include "core/error_api.h"
#include "core/str.h"

/* the file allocator module */

void    gt_fa_init(void);

/* functions for normal file pointer */
#define gt_fa_fopen(path, mode, err)\
        gt_fa_fopen_func(path, mode, __FILE__, __LINE__, err)
FILE*   gt_fa_fopen_func(const char *path, const char *mode,
                         const char *src_file, int src_line, GtError *err);
#define gt_fa_xfopen(path, mode)\
        gt_fa_xfopen_func(path, mode, __FILE__, __LINE__)
FILE*   gt_fa_xfopen_func(const char *path, const char *mode,
                          const char *src_file, int src_line);
#define gt_fa_fopen_with_suffix(path, suffix, mode, err)\
        gt_fa_fopen_with_suffix_func(path, suffix, mode, __FILE__, __LINE__, \
                                     err)
FILE*   gt_fa_fopen_with_suffix_func(const char *path, const char *suffix,
                                     const char *mode, const char *src_file,
                                     int src_line, GtError *err);
void    gt_fa_fclose(FILE *stream);
void    gt_fa_xfclose(FILE *stream);
void    gt_fa_lock_shared(FILE *stream);
void    gt_fa_lock_exclusive(FILE *stream);
void    gt_fa_unlock(FILE *stream);

/* functions for gzip file pointer */
#define gt_fa_gzopen(path, mode, err)\
        gt_fa_gzopen_func(path, mode, __FILE__, __LINE__, err)
gzFile  gt_fa_gzopen_func(const char *path, const char *mode,
                          const char *src_file, int src_line, GtError *err);
#define gt_fa_xgzopen(path, mode)\
        gt_fa_xgzopen_func(path, mode, __FILE__, __LINE__)
gzFile  gt_fa_xgzopen_func(const char *path, const char *mode,
                           const char *src_file, int src_line);
void    gt_fa_gzclose(gzFile stream);
void    gt_fa_xgzclose(gzFile stream);

/* functions for bzip2 file pointer */
#define gt_fa_bzopen(path, mode, err)\
        gt_fa_bzopen_func(path, mode, __FILE__, __LINE__, err)
BZFILE* gt_fa_bzopen_func(const char *path, const char *mode,
                          const char *src_file, int src_line, GtError *err);
#define gt_fa_xbzopen(path, mode)\
        gt_fa_xbzopen_func(path, mode, __FILE__, __LINE__)
BZFILE* gt_fa_xbzopen_func(const char *path, const char *mode,
                           const char *src_file, int src_line);
void    gt_fa_bzclose(BZFILE *stream);
void    gt_fa_xbzclose(BZFILE *stream);

/* create a tmp file optionally using template analogous to mkstemp(3) */
enum tmpfp_flags
{
  TMPFP_AUTOREMOVE    = 1 << 0, /**< otherwise template holds a valid
                                 * path to (re-)open the temporary
                                 * file created */
  TMPFP_USETEMPLATE   = 1 << 1, /**< if set use string template
                                 * given, otherwise the value of
                                 * template is overwritten with an
                                 * interval default */
  TMPFP_OPENBINARY    = 1 << 2, /**< use stdio mode "w+b", "w+" otherwise */
  TMPFP_DEFAULT_FLAGS = 0,
};
#define gt_xtmpfp_generic(template_code, flags) \
        gt_xtmpfp_generic_func(template_code, TMPFP_DEFAULT_FLAGS, \
                               __FILE__, __LINE__)
FILE*   gt_xtmpfp_generic_func(GtStr *template_code, enum tmpfp_flags flags,
                               const char*, int);
#define gt_xtmpfp(template_code)\
        gt_xtmpfp_generic(template_code, TMPFP_DEFAULT_FLAGS)

#define gt_fa_heap_read(PATH,LENPTR,ERR)\
        gt_fa_heap_read_func(PATH,LENPTR,__FILE__,__LINE__,ERR)

void *gt_fa_heap_read_func(const char *path, size_t *len,
                           const char *src_file, int src_line, GtError *err);
/* memory map functions */
#define gt_fa_mmap_read(path, len, err)\
        gt_fa_mmap_read_func(path, len, __FILE__, __LINE__, err)
void*   gt_fa_mmap_read_func(const char *path, size_t *len,
                             const char *src_file, int src_line, GtError *err);

#define gt_fa_mmap_read_range(path, len, offset, err)\
        gt_fa_mmap_read_func_range(path, len, offset, __FILE__, __LINE__, err)
void*   gt_fa_mmap_read_func_range(const char *path, size_t len, size_t offset,
                             const char *src_file, int src_line, GtError *err);

#define gt_fa_mmap_write(path, len, err)\
        gt_fa_mmap_write_func(path, len, __FILE__, __LINE__, err)
void*   gt_fa_mmap_write_func(const char *path, size_t *len,
                              const char *src_file, int src_line, GtError *err);

#define gt_fa_mmap_write_range(path, len, offset, err)\
        gt_fa_mmap_write_func_range(path, len, offset, __FILE__, __LINE__, err)
void*   gt_fa_mmap_write_func_range(const char *path, size_t len, size_t offset,
                                    const char *src_file, int src_line,
                                    GtError *err);

#define gt_fa_xmmap_read(path, len)\
        gt_fa_xmmap_read_func(path, len, __FILE__, __LINE__)
void*   gt_fa_xmmap_read_func(const char *path, size_t *len,
                              const char *src_file, int src_line);

#define gt_fa_xmmap_read_range(path, len, offset)\
        gt_fa_xmmap_read_func_range(path, len, offset, __FILE__, __LINE__)
void*   gt_fa_xmmap_read_func_range(const char *path, size_t len, size_t offset,
                                    const char *src_file, int src_line);

#define gt_fa_xmmap_write(path, len)\
        gt_fa_xmmap_write_func(path, len, __FILE__, __LINE__)
void*   gt_fa_xmmap_write_func(const char *path, size_t *len,
                               const char *src_file, int src_line);

#define gt_fa_xmmap_write_range(path, len, offset)\
        gt_fa_xmmap_write_func_range(path, len, offset, __FILE__, __LINE__)
void*   gt_fa_xmmap_write_func_range(const char *path, size_t len,
                                     size_t offset,
                                     const char *src_file, int src_line);

void    gt_fa_xmunmap(void *addr);

#define gt_fa_mmap_generic_fd(fd, filename_to_map, len, offset, mapwritable, \
                              hard_fail, err) \
        gt_fa_mmap_generic_fd_func(fd, filename_to_map, len, offset, \
                                   mapwritable, hard_fail, __FILE__, __LINE__, \
                                   err)
void*   gt_fa_mmap_generic_fd_func(int fd, const char *filename, size_t len,
                                   size_t offset, bool mapwritable,
                                   bool hard_fail, const char *src_file,
                                   int src_line, GtError *err);

#define gt_fa_mmap_read_with_suffix(path, suffix, len, err)\
        gt_fa_mmap_read_with_suffix_func(path, suffix, len,__FILE__, __LINE__, \
                                      err)
void*   gt_fa_mmap_read_with_suffix_func(const char *path, const char *suffix,
                                         size_t *len, const char *src_file,
                                         int src_line, GtError *err);
void*   gt_fa_mmap_check_size_with_suffix(const char *path, const char *suffix,
                                          GtUword expectedunits,
                                          size_t sizeofunit, GtError *err);

/* check if all allocated file pointer have been released, prints to stderr */
int     gt_fa_check_fptr_leak(void);
/* check if all allocated memory maps have been freed, prints to stderr */
int     gt_fa_check_mmap_leak(void);
void    gt_fa_enable_global_spacepeak(void);
GtUword gt_fa_get_space_peak(void);
GtUword gt_fa_get_space_current(void);
void    gt_fa_show_space_peak(FILE*);
void    gt_fa_clean(void);

#endif
#endif