Commit 0a618777 authored by Max Kellermann's avatar Max Kellermann

input_stream: convert offset and size to the off_t data type

size_t and long aren't 64 bit safe (i.e. files larger than 2 GB on a 32 bit OS). Use off_t instead, which is a 64 bit integer if compiled with large file support.
parent 016d9961
...@@ -673,7 +673,7 @@ static int decodeFirstFrame(mp3DecodeData * data, ...@@ -673,7 +673,7 @@ static int decodeFirstFrame(mp3DecodeData * data,
* Attempt to calulcate the length of the song from filesize * Attempt to calulcate the length of the song from filesize
*/ */
{ {
size_t offset = data->inStream->offset; off_t offset = data->inStream->offset;
mad_timer_t duration = data->frame.header.duration; mad_timer_t duration = data->frame.header.duration;
float frameTime = ((float)mad_timer_count(duration, float frameTime = ((float)mad_timer_count(duration,
MAD_UNITS_MILLISECONDS)) / 1000; MAD_UNITS_MILLISECONDS)) / 1000;
......
...@@ -414,8 +414,7 @@ input_curl_send_request(struct input_curl *c) ...@@ -414,8 +414,7 @@ input_curl_send_request(struct input_curl *c)
} }
static bool static bool
input_curl_seek(struct input_stream *is, mpd_unused long offset, input_curl_seek(struct input_stream *is, off_t offset, int whence)
mpd_unused int whence)
{ {
struct input_curl *c = is->data; struct input_curl *c = is->data;
bool ret; bool ret;
...@@ -427,15 +426,15 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset, ...@@ -427,15 +426,15 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset,
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
is->offset = (off_t)offset; is->offset = offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
is->offset += (off_t)offset; is->offset += offset;
break; break;
case SEEK_END: case SEEK_END:
is->offset = (off_t)is->size + (off_t)offset; is->offset = is->size + offset;
break; break;
default: default:
...@@ -456,7 +455,7 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset, ...@@ -456,7 +455,7 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset,
/* send the "Range" header */ /* send the "Range" header */
if (is->offset > 0) { if (is->offset > 0) {
c->range = g_strdup_printf("%ld-", is->offset); /* XXX 64 bit safety */ c->range = g_strdup_printf("%lld-", (long long)is->offset);
curl_easy_setopt(c->easy, CURLOPT_RANGE, c->range); curl_easy_setopt(c->easy, CURLOPT_RANGE, c->range);
} }
......
...@@ -52,7 +52,7 @@ input_file_open(struct input_stream *is, const char *filename) ...@@ -52,7 +52,7 @@ input_file_open(struct input_stream *is, const char *filename)
} }
static bool static bool
input_file_seek(struct input_stream *is, long offset, int whence) input_file_seek(struct input_stream *is, off_t offset, int whence)
{ {
if (fseek((FILE *) is->data, offset, whence) == 0) { if (fseek((FILE *) is->data, offset, whence) == 0) {
is->offset = ftell((FILE *) is->data); is->offset = ftell((FILE *) is->data);
......
...@@ -76,7 +76,7 @@ input_stream_open(struct input_stream *is, char *url) ...@@ -76,7 +76,7 @@ input_stream_open(struct input_stream *is, char *url)
} }
bool bool
input_stream_seek(struct input_stream *is, long offset, int whence) input_stream_seek(struct input_stream *is, off_t offset, int whence)
{ {
return is->plugin->seek(is, offset, whence); return is->plugin->seek(is, offset, whence);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <sys/types.h>
struct input_stream; struct input_stream;
...@@ -31,7 +32,7 @@ struct input_plugin { ...@@ -31,7 +32,7 @@ struct input_plugin {
int (*buffer)(struct input_stream *is); int (*buffer)(struct input_stream *is);
size_t (*read)(struct input_stream *is, void *ptr, size_t size); size_t (*read)(struct input_stream *is, void *ptr, size_t size);
bool (*eof)(struct input_stream *is); bool (*eof)(struct input_stream *is);
bool (*seek)(struct input_stream *is, long offset, int whence); bool (*seek)(struct input_stream *is, off_t offset, int whence);
}; };
struct input_stream { struct input_stream {
...@@ -41,8 +42,7 @@ struct input_stream { ...@@ -41,8 +42,7 @@ struct input_stream {
bool ready; bool ready;
int error; int error;
long offset; off_t size, offset;
size_t size;
char *mime; char *mime;
void *data; void *data;
...@@ -60,7 +60,7 @@ bool ...@@ -60,7 +60,7 @@ bool
input_stream_open(struct input_stream *is, char *url); input_stream_open(struct input_stream *is, char *url);
bool bool
input_stream_seek(struct input_stream *is, long offset, int whence); input_stream_seek(struct input_stream *is, off_t offset, int whence);
void input_stream_close(struct input_stream *is); void input_stream_close(struct input_stream *is);
bool input_stream_eof(struct input_stream *is); bool input_stream_eof(struct input_stream *is);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment