2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "FlacIOHandle.hxx"
22
#include "util/Error.hxx"
28
FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
30
InputStream *is = (InputStream *)handle;
32
uint8_t *const p0 = (uint8_t *)ptr, *p = p0,
33
*const end = p0 + size * nmemb;
35
/* libFLAC is very picky about short reads, and expects the IO
36
callback to fill the whole buffer (undocumented!) */
40
size_t nbytes = is->LockRead(p, end - p, error);
42
if (!error.IsDefined())
46
if (error.IsDomain(errno_domain))
47
errno = error.GetCode();
49
/* just some random non-zero
58
/* libFLAC expects a clean errno after returning from the IO
59
callbacks (undocumented!) */
61
return (p - p0) / size;
65
FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
67
InputStream *is = (InputStream *)handle;
70
return is->LockSeek(offset, whence, error) ? 0 : -1;
74
FlacIOTell(FLAC__IOHandle handle)
76
InputStream *is = (InputStream *)handle;
82
FlacIOEof(FLAC__IOHandle handle)
84
InputStream *is = (InputStream *)handle;
86
return is->LockIsEOF();
90
FlacIOClose(gcc_unused FLAC__IOHandle handle)
92
/* no-op because the libFLAC caller is repsonsible for closing
98
const FLAC__IOCallbacks flac_io_callbacks = {
107
const FLAC__IOCallbacks flac_io_callbacks_seekable = {