Code Coverage Report for src/decode/io.c
|
Hit |
Total |
Coverage |
Lines: |
22 |
22 |
100.0% |
Branches: |
90 |
90 |
100.0% |
1 /*
2 * libnogg: a decoder library for Ogg Vorbis streams
3 * Copyright (c) 2014-2024 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 (18/18) if (UNLIKELY((*handle->read_callback)(handle->io_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 (18/18) if (UNLIKELY((*handle->read_callback)(handle->io_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 (18/18) if (handle->stream_len >= 0) {
46 const int64_t current = (*handle->tell_callback)(handle->io_opaque);
47 (18/18) if (count > handle->stream_len - current) {
48 count = (int)(handle->stream_len - current);
49 handle->eof = true;
50 }
51 (*handle->seek_callback)(handle->io_opaque, current + count);
52 } else {
53 uint8_t skip_buf[256];
54 (18/18) while (count > 0) {
55 const int skip_count = min(count, (int)sizeof(skip_buf));
56 /* We ignore the result of getn() here because this function
57 * is never called in a context where it can read past the end
58 * of the stream, and even if a read fails for other reasons,
59 * ignoring the error here is harmless because handle->eof will
60 * be set anyway (and we expect the caller to check handle->eof
61 * since we do not return success or failure ourselves). */
62 (void) getn(handle, skip_buf, skip_count);
63 count -= skip_count;
64 }
65 }
66 }
67
68 /*************************************************************************/
69 /*************************************************************************/