input_stream: use "goffset" instead of "off_t"
The "off_t" type may change when you enable or disable large file support on 32 bit platforms. This caused severe ABI problems within MPD when we enabled LFS for the first time: two sources included config.h and sys/types.h in different order, and had different off_t sizes - leading to memory corruption because of ABI incompatibility. This patch attempts to get rid of all public "off_t" uses: it removes "off_t" from the input_stream ABI/API, and switches to GLib's 64 bit "goffset" type. This may hurt 32 bit embedded platforms a tiny bit, but that's not even measurable.
This commit is contained in:
parent
71f881d5cb
commit
727c301fbc
@ -157,7 +157,7 @@ zip_is_eof(struct input_stream *is)
|
||||
|
||||
static bool
|
||||
zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
|
||||
G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
|
||||
G_GNUC_UNUSED goffset offset, G_GNUC_UNUSED int whence)
|
||||
{
|
||||
zip_context *context = (zip_context *) is->data;
|
||||
zzip_off_t ofs = zzip_seek(context->file, offset, whence);
|
||||
|
@ -779,10 +779,10 @@ mp3_frame_duration(const struct mad_frame *frame)
|
||||
MAD_UNITS_MILLISECONDS) / 1000.0;
|
||||
}
|
||||
|
||||
static off_t
|
||||
static goffset
|
||||
mp3_this_frame_offset(const struct mp3_data *data)
|
||||
{
|
||||
off_t offset = data->input_stream->offset;
|
||||
goffset offset = data->input_stream->offset;
|
||||
|
||||
if (data->stream.this_frame != NULL)
|
||||
offset -= data->stream.bufend - data->stream.this_frame;
|
||||
@ -792,7 +792,7 @@ mp3_this_frame_offset(const struct mp3_data *data)
|
||||
return offset;
|
||||
}
|
||||
|
||||
static off_t
|
||||
static goffset
|
||||
mp3_rest_including_this_frame(const struct mp3_data *data)
|
||||
{
|
||||
return data->input_stream->size - mp3_this_frame_offset(data);
|
||||
@ -804,7 +804,7 @@ mp3_rest_including_this_frame(const struct mp3_data *data)
|
||||
static void
|
||||
mp3_filesize_to_song_length(struct mp3_data *data)
|
||||
{
|
||||
off_t rest = mp3_rest_including_this_frame(data);
|
||||
goffset rest = mp3_rest_including_this_frame(data);
|
||||
|
||||
if (rest > 0) {
|
||||
float frame_duration = mp3_frame_duration(&data->frame);
|
||||
|
@ -17,6 +17,7 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h" /* must be first for large file support */
|
||||
#include "decoder_api.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
@ -42,7 +42,7 @@
|
||||
#define G_LOG_DOMAIN "input_curl"
|
||||
|
||||
/** rewinding is possible after up to 64 kB */
|
||||
static const off_t max_rewind_size = 64 * 1024;
|
||||
static const goffset max_rewind_size = 64 * 1024;
|
||||
|
||||
/**
|
||||
* Buffers created by input_curl_writefunction().
|
||||
@ -425,7 +425,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
|
||||
#ifndef NDEBUG
|
||||
if (c->rewind != NULL &&
|
||||
(!g_queue_is_empty(c->rewind) || is->offset == 0)) {
|
||||
off_t offset = 0;
|
||||
goffset offset = 0;
|
||||
struct buffer *buffer;
|
||||
|
||||
for (GList *list = g_queue_peek_head_link(c->rewind);
|
||||
@ -474,11 +474,11 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
|
||||
if (icy_defined(&c->icy_metadata))
|
||||
copy_icy_tag(c);
|
||||
|
||||
is->offset += (off_t)nbytes;
|
||||
is->offset += (goffset)nbytes;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (rewind_buffers != NULL) {
|
||||
off_t offset = 0;
|
||||
goffset offset = 0;
|
||||
struct buffer *buffer;
|
||||
|
||||
for (GList *list = g_queue_peek_head_link(c->rewind);
|
||||
@ -772,7 +772,7 @@ input_curl_can_rewind(struct input_stream *is)
|
||||
/* rewind is possible if this is the very first buffer of the
|
||||
resource */
|
||||
buffer = (struct buffer*)g_queue_peek_head(c->buffers);
|
||||
return (off_t)buffer->consumed == is->offset;
|
||||
return (goffset)buffer->consumed == is->offset;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -780,7 +780,7 @@ input_curl_rewind(struct input_stream *is)
|
||||
{
|
||||
struct input_curl *c = is->data;
|
||||
#ifndef NDEBUG
|
||||
off_t offset = 0;
|
||||
goffset offset = 0;
|
||||
#endif
|
||||
|
||||
assert(c->rewind != NULL);
|
||||
@ -818,7 +818,7 @@ input_curl_rewind(struct input_stream *is)
|
||||
}
|
||||
|
||||
static bool
|
||||
input_curl_seek(struct input_stream *is, off_t offset, int whence)
|
||||
input_curl_seek(struct input_stream *is, goffset offset, int whence)
|
||||
{
|
||||
struct input_curl *c = is->data;
|
||||
bool ret;
|
||||
@ -884,7 +884,7 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
|
||||
buffer = (struct buffer *)g_queue_pop_head(c->buffers);
|
||||
|
||||
length = buffer->size - buffer->consumed;
|
||||
if (offset - is->offset < (off_t)length)
|
||||
if (offset - is->offset < (goffset)length)
|
||||
length = offset - is->offset;
|
||||
|
||||
buffer = consume_buffer(buffer, length, rewind_buffers);
|
||||
|
@ -17,6 +17,7 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h" /* must be first for large file support */
|
||||
#include "input/file_input_plugin.h"
|
||||
#include "input_plugin.h"
|
||||
|
||||
@ -92,11 +93,11 @@ input_file_open(struct input_stream *is, const char *filename)
|
||||
}
|
||||
|
||||
static bool
|
||||
input_file_seek(struct input_stream *is, off_t offset, int whence)
|
||||
input_file_seek(struct input_stream *is, goffset offset, int whence)
|
||||
{
|
||||
int fd = GPOINTER_TO_INT(is->data);
|
||||
|
||||
offset = lseek(fd, offset, whence);
|
||||
offset = (goffset)lseek(fd, (off_t)offset, whence);
|
||||
if (offset < 0) {
|
||||
is->error = errno;
|
||||
return false;
|
||||
|
@ -285,7 +285,7 @@ lastfm_input_eof_wrap(struct input_stream *is)
|
||||
}
|
||||
|
||||
static bool
|
||||
lastfm_input_seek_wrap(struct input_stream *is, off_t offset, int whence)
|
||||
lastfm_input_seek_wrap(struct input_stream *is, goffset offset, int whence)
|
||||
{
|
||||
bool ret;
|
||||
struct lastfm_input *d = is->data;
|
||||
|
@ -110,7 +110,7 @@ input_mms_buffer(G_GNUC_UNUSED struct input_stream *is)
|
||||
|
||||
static bool
|
||||
input_mms_seek(G_GNUC_UNUSED struct input_stream *is,
|
||||
G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
|
||||
G_GNUC_UNUSED goffset offset, G_GNUC_UNUSED int whence)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ struct input_plugin {
|
||||
int (*buffer)(struct input_stream *is);
|
||||
size_t (*read)(struct input_stream *is, void *ptr, size_t size);
|
||||
bool (*eof)(struct input_stream *is);
|
||||
bool (*seek)(struct input_stream *is, off_t offset, int whence);
|
||||
bool (*seek)(struct input_stream *is, goffset offset, int whence);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -139,7 +139,7 @@ input_stream_open(struct input_stream *is, const char *url)
|
||||
}
|
||||
|
||||
bool
|
||||
input_stream_seek(struct input_stream *is, off_t offset, int whence)
|
||||
input_stream_seek(struct input_stream *is, goffset offset, int whence)
|
||||
{
|
||||
if (is->plugin->seek == NULL)
|
||||
return false;
|
||||
|
@ -20,14 +20,12 @@
|
||||
#ifndef MPD_INPUT_STREAM_H
|
||||
#define MPD_INPUT_STREAM_H
|
||||
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct input_stream;
|
||||
|
||||
struct input_stream {
|
||||
/**
|
||||
* the plugin which implements this input stream
|
||||
@ -58,12 +56,12 @@ struct input_stream {
|
||||
/**
|
||||
* the size of the resource, or -1 if unknown
|
||||
*/
|
||||
off_t size;
|
||||
goffset size;
|
||||
|
||||
/**
|
||||
* the current offset within the stream
|
||||
*/
|
||||
off_t offset;
|
||||
goffset offset;
|
||||
|
||||
/**
|
||||
* the MIME content type of the resource, or NULL if unknown
|
||||
@ -108,7 +106,7 @@ input_stream_close(struct input_stream *is);
|
||||
* @param whence the base of the seek, one of SEEK_SET, SEEK_CUR, SEEK_END
|
||||
*/
|
||||
bool
|
||||
input_stream_seek(struct input_stream *is, off_t offset, int whence);
|
||||
input_stream_seek(struct input_stream *is, goffset offset, int whence);
|
||||
|
||||
/**
|
||||
* Returns true if the stream has reached end-of-file.
|
||||
|
Loading…
Reference in New Issue
Block a user