annotate ezBAMQC/src/htslib/hfile_internal.h @ 0:dfa3745e5fd8

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