0
|
1 /* hfile_internal.h -- internal parts of low-level input/output streams.
|
|
2
|
|
3 Copyright (C) 2013-2015 Genome Research Ltd.
|
|
4
|
|
5 Author: John Marshall <jm18@sanger.ac.uk>
|
|
6
|
|
7 Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 of this software and associated documentation files (the "Software"), to deal
|
|
9 in the Software without restriction, including without limitation the rights
|
|
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11 copies of the Software, and to permit persons to whom the Software is
|
|
12 furnished to do so, subject to the following conditions:
|
|
13
|
|
14 The above copyright notice and this permission notice shall be included in
|
|
15 all copies or substantial portions of the Software.
|
|
16
|
|
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
23 DEALINGS IN THE SOFTWARE. */
|
|
24
|
|
25 #ifndef HFILE_INTERNAL_H
|
|
26 #define HFILE_INTERNAL_H
|
|
27
|
|
28 #include "htslib/hfile.h"
|
|
29
|
|
30 struct hFILE_backend {
|
|
31 /* As per read(2), returning the number of bytes read (possibly 0) or
|
|
32 negative (and setting errno) on errors. Front-end code will call this
|
|
33 repeatedly if necessary to attempt to get the desired byte count. */
|
|
34 ssize_t (*read)(hFILE *fp, void *buffer, size_t nbytes) HTS_RESULT_USED;
|
|
35
|
|
36 /* As per write(2), returning the number of bytes written or negative (and
|
|
37 setting errno) on errors. Front-end code will call this repeatedly if
|
|
38 necessary until the desired block is written or an error occurs. */
|
|
39 ssize_t (*write)(hFILE *fp, const void *buffer, size_t nbytes)
|
|
40 HTS_RESULT_USED;
|
|
41
|
|
42 /* As per lseek(2), returning the resulting offset within the stream or
|
|
43 negative (and setting errno) on errors. */
|
|
44 off_t (*seek)(hFILE *fp, off_t offset, int whence) HTS_RESULT_USED;
|
|
45
|
|
46 /* Performs low-level flushing, if any, e.g., fsync(2); for writing streams
|
|
47 only. Returns 0 for success or negative (and sets errno) on errors. */
|
|
48 int (*flush)(hFILE *fp) HTS_RESULT_USED;
|
|
49
|
|
50 /* Closes the underlying stream (for output streams, the buffer will
|
|
51 already have been flushed), returning 0 for success or negative (and
|
|
52 setting errno) on errors, as per close(2). */
|
|
53 int (*close)(hFILE *fp) HTS_RESULT_USED;
|
|
54 };
|
|
55
|
|
56 /* These are called from the hopen() dispatcher, and should call hfile_init()
|
|
57 to malloc a struct "derived" from hFILE and initialise it appropriately,
|
|
58 including setting base.backend to their own backend vector. */
|
|
59 hFILE *hopen_irods(const char *filename, const char *mode);
|
|
60 hFILE *hopen_net(const char *filename, const char *mode);
|
|
61
|
|
62 /* May be called by hopen_*() functions to decode a fopen()-style mode into
|
|
63 open(2)-style flags. */
|
|
64 int hfile_oflags(const char *mode);
|
|
65
|
|
66 /* Must be called by hopen_*() functions to allocate the hFILE struct and set
|
|
67 up its base. Capacity is a suggested buffer size (e.g., via fstat(2))
|
|
68 or 0 for a default-sized buffer. */
|
|
69 hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity);
|
|
70
|
|
71 /* May be called by hopen_*() functions to undo the effects of hfile_init()
|
|
72 in the event opening the stream subsequently fails. (This is safe to use
|
|
73 even if fp is NULL. This takes care to preserve errno.) */
|
|
74 void hfile_destroy(hFILE *fp);
|
|
75
|
|
76 #endif
|