Code Coverage Report for src/decode/io.c


Hit Total Coverage
Lines: 21 22 95.4%
Branches: 22 24 91.6%

1 /*
2 * libnogg: a decoder library for Ogg Vorbis streams
3 * Copyright (c) 2014-2019 Andrew Church <achurch@achurch.org>
4 *
5 * This software may be copied and redistributed under certain conditions;
6 * see the file "COPYING" in the source code distribution for details.
7 * NO WARRANTY is provided with this software.
8 */
9
10 #include "include/nogg.h"
11 #include "src/common.h"
12 #include "src/decode/common.h"
13 #include "src/decode/io.h"
14
15 /*************************************************************************/
16 /************************** Interface routines ***************************/
17 /*************************************************************************/
18
19 uint8_t get8(stb_vorbis *handle)
20 {
21 uint8_t byte;
22 (4/4) if (UNLIKELY((*handle->read_callback)(handle->opaque, &byte, 1) != 1)) {
23 handle->eof = true;
24 return 0;
25 }
26 return byte;
27 }
28
29 /*-----------------------------------------------------------------------*/
30
31 bool getn(stb_vorbis *handle, uint8_t *buffer, int count)
32 {
33 (4/4) if (UNLIKELY((*handle->read_callback)(handle->opaque,
34 buffer, count) != count)) {
35 handle->eof = true;
36 return false;
37 }
38 return true;
39 }
40
41 /*-----------------------------------------------------------------------*/
42
43 void skip(stb_vorbis *handle, int count)
44 {
45 (4/4) if (handle->stream_len >= 0) {
46 const int64_t current = (*handle->tell_callback)(handle->opaque);
47 (4/4) if (count > handle->stream_len - current) {
48 count = handle->stream_len - current;
49 handle->eof = true;
50 }
51 (*handle->seek_callback)(handle->opaque, current + count);
52 } else {
53 uint8_t skip_buf[256];
54 (4/4) while (count > 0) {
55 const int skip_count = min(count, (int)sizeof(skip_buf));
56 (2/4) if (!getn(handle, skip_buf, skip_count)) {
57 return;
58 }
59 count -= skip_count;
60 }
61 }
62 }
63
64 /*************************************************************************/
65 /*************************************************************************/