Commit f25b2602 authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

Fix a couple of Windows 2Gig file size issues.

Patch submitted by Janne Hyvärinen <cse@sci.fi>.
parent 6497ce19
......@@ -48,20 +48,13 @@
#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
#include <sys/types.h> /* for off_t */
#if !defined __MINGW32__ /* @@@ [2G limit] */
#ifndef fseeko
#define fseeko fseek
#endif
#ifndef ftello
#define ftello ftell
#define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */
#if !defined __MINGW32__
#define fseeko _fseeki64
#define ftello _ftelli64
#endif
#else
/* MinGW */
#if !defined(HAVE_FSEEKO)
# define fseeko fseeko64
# define ftello ftello64
#endif
#endif
#define FLAC__off_t off_t
#endif
#if HAVE_INTTYPES_H
......
......@@ -31,13 +31,14 @@
#include <sys/types.h> /* for off_t */
#include <stdio.h> /* for FILE */
#include "FLAC/ordinals.h"
#include "share/compat.h"
#ifdef __cplusplus
extern "C" {
#endif
void grabbag__file_copy_metadata(const char *srcpath, const char *destpath);
off_t grabbag__file_get_filesize(const char *srcpath);
FLAC__off_t grabbag__file_get_filesize(const char *srcpath);
const char *grabbag__file_get_basename(const char *srcpath);
/* read_only == false means "make file writable by user"
......
......@@ -26,9 +26,10 @@
#include "FLAC/format.h"
#include <sys/types.h> /* for off_t */
#include "share/compat.h"
extern const long file_utils__ogg_serial_number;
FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata);
FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, FLAC__off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata);
#endif
......@@ -87,7 +87,7 @@ typedef struct {
FILE *fout;
foreign_metadata_t *foreign_metadata; /* NULL unless --keep-foreign-metadata requested */
off_t fm_offset1, fm_offset2, fm_offset3;
FLAC__off_t fm_offset1, fm_offset2, fm_offset3;
} DecoderSession;
......
......@@ -60,7 +60,7 @@ typedef struct {
/* this is the client_data attached to the FLAC decoder when encoding from a FLAC file */
typedef struct {
off_t filesize;
FLAC__off_t filesize;
const FLAC__byte *lookahead;
unsigned lookahead_length;
size_t num_metadata_blocks;
......@@ -124,7 +124,7 @@ static FLAC__int32 *input_[FLAC__MAX_CHANNELS];
/*
* local routines
*/
static FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length);
static FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, FLAC__off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length);
static void EncoderSession_destroy(EncoderSession *e);
static int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata);
static int EncoderSession_finish_error(EncoderSession *e);
......@@ -941,7 +941,7 @@ static FLAC__bool get_sample_info_flac(EncoderSession *e)
/*
* public routines
*/
int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length, encode_options_t options)
int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length, encode_options_t options)
{
EncoderSession encoder_session;
size_t channel_map[FLAC__MAX_CHANNELS];
......@@ -1089,7 +1089,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
/* adjust encoding parameters based on skip and until values */
switch(options.format) {
case FORMAT_RAW:
infilesize -= (off_t)skip * encoder_session.info.bytes_per_wide_sample;
infilesize -= (FLAC__off_t)skip * encoder_session.info.bytes_per_wide_sample;
encoder_session.total_samples_to_encode = total_samples_in_input - skip;
break;
case FORMAT_WAVE:
......@@ -1121,7 +1121,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
FLAC__ASSERT(total_samples_in_input > 0);
FLAC__ASSERT(!options.sector_align);
if(options.format == FORMAT_RAW)
infilesize -= (off_t)trim * encoder_session.info.bytes_per_wide_sample;
infilesize -= (FLAC__off_t)trim * encoder_session.info.bytes_per_wide_sample;
else if(EncoderSession_format_is_iff(&encoder_session))
encoder_session.fmt.iff.data_bytes -= trim * encoder_session.info.bytes_per_wide_sample;
encoder_session.total_samples_to_encode -= trim;
......@@ -1256,7 +1256,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
*options.align_reservoir_samples = align_remainder;
if(options.format == FORMAT_RAW) {
FLAC__ASSERT(infilesize >= 0);
infilesize -= (off_t)((*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample);
infilesize -= (FLAC__off_t)((*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample);
FLAC__ASSERT(infilesize >= 0);
}
else if(EncoderSession_format_is_iff(&encoder_session))
......@@ -1340,7 +1340,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
return EncoderSession_finish_error(&encoder_session);
}
else if(feof(infile)) {
flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %" PRIu64 " samples, got %" PRIu64 " samples\n", encoder_session.inbasefilename, encoder_session.total_samples_to_encode, encoder_session.samples_written);
if(encoder_session.treat_warnings_as_errors)
return EncoderSession_finish_error(&encoder_session);
total_input_bytes_read = max_input_bytes;
......@@ -1384,10 +1384,10 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
}
else if(feof(infile)) {
if(options.ignore_chunk_sizes) {
flac__utils_printf(stderr, 1, "%s: INFO: hit EOF with --ignore-chunk-sizes, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.samples_written);
flac__utils_printf(stderr, 1, "%s: INFO: hit EOF with --ignore-chunk-sizes, got %" PRIu64 " samples\n", encoder_session.inbasefilename, encoder_session.samples_written);
}
else {
flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %" PRIu64 " samples, got %" PRIu64 " samples\n", encoder_session.inbasefilename, encoder_session.total_samples_to_encode, encoder_session.samples_written);
if(encoder_session.treat_warnings_as_errors)
return EncoderSession_finish_error(&encoder_session);
}
......@@ -1467,7 +1467,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
return EncoderSession_finish_error(&encoder_session);
}
else if(bytes_read != (*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample) {
flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)bytes_read, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; read %" PRIu64 " bytes; expected %" PRIu64 " samples, got %" PRIu64 " samples\n", encoder_session.inbasefilename, bytes_read, encoder_session.total_samples_to_encode, encoder_session.samples_written);
if(encoder_session.treat_warnings_as_errors)
return EncoderSession_finish_error(&encoder_session);
}
......@@ -1489,7 +1489,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
);
}
FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length)
FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, FLAC__off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length)
{
unsigned i;
FLAC__uint32 test = 1;
......@@ -2459,7 +2459,7 @@ FLAC__StreamDecoderSeekStatus flac_decoder_seek_callback(const FLAC__StreamDecod
EncoderSession *e = (EncoderSession*)client_data;
(void)decoder;
if(fseeko(e->fin, (off_t)absolute_byte_offset, SEEK_SET) < 0)
if(fseeko(e->fin, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0)
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
else
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
......@@ -2468,7 +2468,7 @@ FLAC__StreamDecoderSeekStatus flac_decoder_seek_callback(const FLAC__StreamDecod
FLAC__StreamDecoderTellStatus flac_decoder_tell_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
EncoderSession *e = (EncoderSession*)client_data;
off_t pos;
FLAC__off_t pos;
(void)decoder;
if((pos = ftello(e->fin)) < 0)
......@@ -2607,10 +2607,10 @@ void print_stats(const EncoderSession *encoder_session)
FLAC__ASSERT(encoder_session->total_samples_to_encode > 0);
if(samples_written == encoder_session->total_samples_to_encode) {
flac__utils_printf(stderr, 2, "\r%s:%s wrote %u bytes, ratio=",
flac__utils_printf(stderr, 2, "\r%s:%s wrote %" PRIu64 " bytes, ratio=",
encoder_session->inbasefilename,
encoder_session->verify? " Verify OK," : "",
(unsigned)encoder_session->bytes_written
encoder_session->bytes_written
);
}
else {
......@@ -2695,7 +2695,7 @@ void print_verify_error(EncoderSession *e)
FLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
flac__utils_printf(stderr, 1, "%s: ERROR: mismatch in decoded data, verify FAILED!\n", e->inbasefilename);
flac__utils_printf(stderr, 1, " Absolute sample=%u, frame=%u, channel=%u, sample=%u, expected %d, got %d\n", (unsigned)absolute_sample, frame_number, channel, sample, expected, got);
flac__utils_printf(stderr, 1, " Absolute sample=%" PRIu64 ", frame=%u, channel=%u, sample=%u, expected %d, got %d\n", absolute_sample, frame_number, channel, sample, expected, got);
flac__utils_printf(stderr, 1, " In all known cases, verify errors are caused by hardware problems,\n");
flac__utils_printf(stderr, 1, " usually overclocking or bad RAM. Delete %s\n", e->outfilename);
flac__utils_printf(stderr, 1, " and repeat the flac command exactly as before. If it does not give a\n");
......
......@@ -26,6 +26,7 @@
#include "FLAC/metadata.h"
#include "foreign_metadata.h"
#include "utils.h"
#include "share/compat.h"
extern const int FLAC_ENCODE__DEFAULT_PADDING;
......@@ -109,6 +110,6 @@ typedef struct {
} debug;
} encode_options_t;
int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length, encode_options_t options);
int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length, encode_options_t options);
#endif
......@@ -72,7 +72,7 @@ static FLAC__bool copy_data_(FILE *fin, FILE *fout, size_t size, const char **er
return true;
}
static FLAC__bool append_block_(foreign_metadata_t *fm, off_t offset, FLAC__uint32 size, const char **error)
static FLAC__bool append_block_(foreign_metadata_t *fm, FLAC__off_t offset, FLAC__uint32 size, const char **error)
{
foreign_block_t *fb = safe_realloc_muladd2_(fm->blocks, sizeof(foreign_block_t), /*times (*/fm->num_blocks, /*+*/1/*)*/);
if(fb) {
......@@ -89,7 +89,7 @@ static FLAC__bool append_block_(foreign_metadata_t *fm, off_t offset, FLAC__uint
static FLAC__bool read_from_aiff_(foreign_metadata_t *fm, FILE *f, const char **error)
{
FLAC__byte buffer[12];
off_t offset, eof_offset;
FLAC__off_t offset, eof_offset;
if((offset = ftello(f)) < 0) {
if(error) *error = "ftello() error (001)";
return false;
......@@ -100,7 +100,7 @@ static FLAC__bool read_from_aiff_(foreign_metadata_t *fm, FILE *f, const char **
}
if(!append_block_(fm, offset, 12, error))
return false;
eof_offset = (off_t)8 + (off_t)unpack32be_(buffer+4);
eof_offset = (FLAC__off_t)8 + (FLAC__off_t)unpack32be_(buffer+4);
while(!feof(f)) {
FLAC__uint32 size;
if((offset = ftello(f)) < 0) {
......@@ -180,7 +180,7 @@ static FLAC__bool read_from_aiff_(foreign_metadata_t *fm, FILE *f, const char **
static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **error)
{
FLAC__byte buffer[12];
off_t offset, eof_offset = -1, ds64_data_size = -1;
FLAC__off_t offset, eof_offset = -1, ds64_data_size = -1;
if((offset = ftello(f)) < 0) {
if(error) *error = "ftello() error (001)";
return false;
......@@ -191,14 +191,14 @@ static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **
}
if(!memcmp(buffer, "RF64", 4))
fm->is_rf64 = true;
if(fm->is_rf64 && sizeof(off_t) < 8) {
if(fm->is_rf64 && sizeof(FLAC__off_t) < 8) {
if(error) *error = "RF64 is not supported on this compile (r00)";
return false;
}
if(!append_block_(fm, offset, 12, error))
return false;
if(!fm->is_rf64 || unpack32le_(buffer+4) != 0xffffffffu)
eof_offset = (off_t)8 + (off_t)unpack32le_(buffer+4);
eof_offset = (FLAC__off_t)8 + (FLAC__off_t)unpack32le_(buffer+4);
while(!feof(f)) {
FLAC__uint32 size;
if((offset = ftello(f)) < 0) {
......@@ -264,8 +264,8 @@ static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **
if(error) *error = "unexpected EOF reading \"ds64\" chunk data in RF64 file (r05)";
return false;
}
ds64_data_size = (off_t)unpack64le_(buffer2+8);
if(ds64_data_size == (off_t)(-1)) {
ds64_data_size = (FLAC__off_t)unpack64le_(buffer2+8);
if(ds64_data_size == (FLAC__off_t)(-1)) {
if(error) *error = "RF64 file has \"ds64\" chunk with data size == -1 (r08)";
return false;
}
......@@ -281,9 +281,9 @@ static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **
if(error) *error = "RF64 file has \"ds64\" chunk with extra size table, which is not currently supported (r06)";
return false;
}
eof_offset = (off_t)8 + (off_t)unpack64le_(buffer2);
eof_offset = (FLAC__off_t)8 + (FLAC__off_t)unpack64le_(buffer2);
/* @@@ [2^63 limit] */
if((off_t)unpack64le_(buffer2) < 0 || eof_offset < 0) {
if((FLAC__off_t)unpack64le_(buffer2) < 0 || eof_offset < 0) {
if(error) *error = "RF64 file too large (r07)";
return false;
}
......@@ -303,7 +303,7 @@ static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **
}
}
}
if(fm->is_rf64 && eof_offset == (off_t)(-1)) {
if(fm->is_rf64 && eof_offset == (FLAC__off_t)(-1)) {
if(error) *error = "invalid RF64 file: all RIFF sizes are -1 (r11)";
return false;
}
......@@ -325,7 +325,7 @@ static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **
static FLAC__bool read_from_wave64_(foreign_metadata_t *fm, FILE *f, const char **error)
{
FLAC__byte buffer[40];
off_t offset, eof_offset = -1;
FLAC__off_t offset, eof_offset = -1;
if((offset = ftello(f)) < 0) {
if(error) *error = "ftello() error (001)";
return false;
......@@ -340,13 +340,13 @@ static FLAC__bool read_from_wave64_(foreign_metadata_t *fm, FILE *f, const char
if(error) *error = "unsupported Wave64 layout (002)";
return false;
}
if(sizeof(off_t) < 8) {
if(sizeof(FLAC__off_t) < 8) {
if(error) *error = "Wave64 is not supported on this compile (r00)";
return false;
}
if(!append_block_(fm, offset, 40, error))
return false;
eof_offset = (off_t)unpack64le_(buffer+16); /*@@@ [2^63 limit] */
eof_offset = (FLAC__off_t)unpack64le_(buffer+16); /*@@@ [2^63 limit] */
while(!feof(f)) {
FLAC__uint64 size;
if((offset = ftello(f)) < 0) {
......@@ -469,7 +469,7 @@ static FLAC__bool write_to_flac_(foreign_metadata_t *fm, FILE *fin, FILE *fout,
static FLAC__bool read_from_flac_(foreign_metadata_t *fm, FILE *f, FLAC__Metadata_SimpleIterator *it, const char **error)
{
FLAC__byte id[4], buffer[12];
off_t offset;
FLAC__off_t offset;
FLAC__bool type_found = false, ds64_found = false;
FLAC__ASSERT(FLAC__STREAM_METADATA_APPLICATION_ID_LEN == sizeof(id)*8);
......@@ -488,7 +488,7 @@ static FLAC__bool read_from_flac_(foreign_metadata_t *fm, FILE *f, FLAC__Metadat
offset += (FLAC__STREAM_METADATA_IS_LAST_LEN + FLAC__STREAM_METADATA_TYPE_LEN + FLAC__STREAM_METADATA_LENGTH_LEN) / 8;
offset += sizeof(id);
/* look for format or audio blocks */
if(fseek(f, offset, SEEK_SET) < 0) {
if(fseeko(f, offset, SEEK_SET) < 0) {
if(error) *error = "seek error (003)";
return false;
}
......@@ -636,7 +636,7 @@ static FLAC__bool read_from_flac_(foreign_metadata_t *fm, FILE *f, FLAC__Metadat
return true;
}
static FLAC__bool write_to_iff_(foreign_metadata_t *fm, FILE *fin, FILE *fout, off_t offset1, off_t offset2, off_t offset3, const char **error)
static FLAC__bool write_to_iff_(foreign_metadata_t *fm, FILE *fin, FILE *fout, FLAC__off_t offset1, FLAC__off_t offset2, FLAC__off_t offset3, const char **error)
{
size_t i;
if(fseeko(fout, offset1, SEEK_SET) < 0) {
......@@ -795,7 +795,7 @@ FLAC__bool flac__foreign_metadata_read_from_flac(foreign_metadata_t *fm, const c
return ok;
}
FLAC__bool flac__foreign_metadata_write_to_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, off_t offset1, off_t offset2, off_t offset3, const char **error)
FLAC__bool flac__foreign_metadata_write_to_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, FLAC__off_t offset1, FLAC__off_t offset2, FLAC__off_t offset3, const char **error)
{
FLAC__bool ok;
FILE *fin, *fout;
......
......@@ -25,6 +25,7 @@
#include "FLAC/metadata.h"
#include "utils.h"
#include "share/compat.h"
/* WATCHOUT: these enums are used to index internal arrays */
typedef enum {
......@@ -36,7 +37,7 @@ typedef enum {
typedef struct {
/* for encoding, this will be the offset in the WAVE/AIFF file of the chunk */
/* for decoding, this will be the offset in the FLAC file of the chunk data inside the APPLICATION block */
off_t offset;
FLAC__off_t offset;
/* size is the actual size in bytes of the chunk to be stored/recreated. */
/* It includes the 8 bytes of chunk type and size, and any padding byte for alignment. */
/* For 'data'/'SSND' chunks, the size does not include the actual sound or padding bytes */
......@@ -67,6 +68,6 @@ FLAC__bool flac__foreign_metadata_read_from_wave64(foreign_metadata_t *fm, const
FLAC__bool flac__foreign_metadata_write_to_flac(foreign_metadata_t *fm, const char *infilename, const char *outfilename, const char **error);
FLAC__bool flac__foreign_metadata_read_from_flac(foreign_metadata_t *fm, const char *filename, const char **error);
FLAC__bool flac__foreign_metadata_write_to_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, off_t offset1, off_t offset2, off_t offset3, const char **error);
FLAC__bool flac__foreign_metadata_write_to_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, FLAC__off_t offset1, FLAC__off_t offset2, FLAC__off_t offset3, const char **error);
#endif
......@@ -263,7 +263,7 @@ static struct {
int format_channels;
int format_bps;
int format_sample_rate;
off_t format_input_size;
FLAC__off_t format_input_size;
char requested_seek_points[5000]; /* bad MAGIC NUMBER but buffer overflow is checked */
int num_requested_seek_points; /* -1 => no -S options were given, 0 => -S- was given */
const char *cuesheet_filename;
......@@ -580,7 +580,7 @@ FLAC__bool init_options(void)
option_values.format_channels = -1;
option_values.format_bps = -1;
option_values.format_sample_rate = -1;
option_values.format_input_size = (off_t)(-1);
option_values.format_input_size = (FLAC__off_t)(-1);
option_values.requested_seek_points[0] = '\0';
option_values.num_requested_seek_points = -1;
option_values.cuesheet_filename = 0;
......@@ -681,8 +681,8 @@ int parse_option(int short_option, const char *long_option, const char *option_a
ix = strtoll(option_argument, &end, 10);
if(0 == strlen(option_argument) || *end)
return usage_error("ERROR: --%s must be a number\n", long_option);
option_values.format_input_size = (off_t)ix;
if(option_values.format_input_size != ix) /* check if off_t is smaller than long long */
option_values.format_input_size = (FLAC__off_t)ix;
if(option_values.format_input_size != ix) /* check if FLAC__off_t is smaller than long long */
return usage_error("ERROR: --%s too large; this build of flac does not support filesizes over 2GB\n", long_option);
if(option_values.format_input_size <= 0)
return usage_error("ERROR: --%s must be > 0\n", long_option);
......@@ -1664,7 +1664,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
unsigned lookahead_length = 0;
FileFormat input_format = FORMAT_RAW;
int retval;
off_t infilesize;
FLAC__off_t infilesize;
encode_options_t encode_options;
const char *outfilename = get_encoded_outfilename(infilename); /* the final name of the encoded file */
/* internal_outfilename is the file we will actually write to; it will be a temporary name if infilename==outfilename */
......@@ -1676,7 +1676,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
}
if(0 == strcmp(infilename, "-")) {
infilesize = (off_t)(-1);
infilesize = (FLAC__off_t)(-1);
encode_infile = grabbag__file_get_binary_stdin();
}
else {
......@@ -1770,7 +1770,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
* Error if output file already exists (and -f not used).
* Use grabbag__file_get_filesize() as a cheap way to check.
*/
if(!option_values.test_only && !option_values.force_file_overwrite && strcmp(outfilename, "-") && grabbag__file_get_filesize(outfilename) != (off_t)(-1)) {
if(!option_values.test_only && !option_values.force_file_overwrite && strcmp(outfilename, "-") && grabbag__file_get_filesize(outfilename) != (FLAC__off_t)(-1)) {
if(input_format == FORMAT_FLAC) {
/* need more detailed error message when re-flac'ing to avoid confusing the user */
flac__utils_printf(stderr, 1,
......@@ -2014,7 +2014,7 @@ int decode_file(const char *infilename)
* Error if output file already exists (and -f not used).
* Use grabbag__file_get_filesize() as a cheap way to check.
*/
if(!option_values.test_only && !option_values.force_file_overwrite && strcmp(outfilename, "-") && grabbag__file_get_filesize(outfilename) != (off_t)(-1)) {
if(!option_values.test_only && !option_values.force_file_overwrite && strcmp(outfilename, "-") && grabbag__file_get_filesize(outfilename) != (FLAC__off_t)(-1)) {
flac__utils_printf(stderr, 1, "ERROR: output file %s already exists, use -f to override\n", outfilename);
return 1;
}
......
......@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "share/compat.h"
/*
......@@ -113,7 +114,7 @@ static FLAC__bool set_vc_field(FLAC__StreamMetadata *block, const Argument_VcFie
/* read the file into 'data' */
FILE *f = 0;
char *data = 0;
const off_t size = grabbag__file_get_filesize(field->field_value);
const FLAC__off_t size = grabbag__file_get_filesize(field->field_value);
if(size < 0) {
*violation = "can't open file for tag value";
return false;
......
This diff is collapsed.
......@@ -3319,7 +3319,7 @@ FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *dec
if(decoder->private_->file == stdin)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
else if(fseeko(decoder->private_->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0)
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
else
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
......@@ -3327,7 +3327,7 @@ FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *dec
FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
off_t pos;
FLAC__off_t pos;
(void)client_data;
if(decoder->private_->file == stdin)
......@@ -3342,12 +3342,20 @@ FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *dec
FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
{
#if defined _MSC_VER || defined __MINGW32__
struct _stat64 filestats;
#else
struct stat filestats;
#endif
(void)client_data;
if(decoder->private_->file == stdin)
return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
#if defined _MSC_VER || defined __MINGW32__
else if(_fstat64(fileno(decoder->private_->file), &filestats) != 0)
#else
else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
#endif
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
else {
*stream_length = (FLAC__uint64)filestats.st_size;
......
......@@ -4240,7 +4240,7 @@ FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *enc
{
(void)client_data;
if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
if(fseeko(encoder->private_->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0)
return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
else
return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
......@@ -4248,7 +4248,7 @@ FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *enc
FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
off_t offset;
FLAC__off_t offset;
(void)client_data;
......
......@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include "operations_shorthand.h"
#include "share/compat.h"
static FLAC__bool remove_vc_all(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write);
static FLAC__bool remove_vc_field(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write);
......@@ -188,7 +189,7 @@ FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const
/* read the file into 'data' */
FILE *f = 0;
char *data = 0;
const off_t size = grabbag__file_get_filesize(field->field_value);
const FLAC__off_t size = grabbag__file_get_filesize(field->field_value);
if(size < 0) {
fprintf(stderr, "%s: ERROR: can't open file '%s' for '%s' tag value\n", filename, field->field_value, field->field_name);
return false;
......
......@@ -61,11 +61,17 @@ void grabbag__file_copy_metadata(const char *srcpath, const char *destpath)
}
}
off_t grabbag__file_get_filesize(const char *srcpath)
FLAC__off_t grabbag__file_get_filesize(const char *srcpath)
{
#if defined _MSC_VER || defined __MINGW32__
struct _stat64 srcstat;
if(0 == _stat64(srcpath, &srcstat))
#else
struct stat srcstat;
if(0 == stat(srcpath, &srcstat))
#endif
return srcstat.st_size;
else
return -1;
......
......@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "share/compat.h"
/* slightly different that strndup(): this always copies 'size' bytes starting from s into a NUL-terminated string. */
static char *local__strndup_(const char *s, size_t size)
......@@ -356,7 +357,7 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con
*error_message = error_messages[3];
}
else { /* regular picture file */
const off_t size = grabbag__file_get_filesize(spec);
const FLAC__off_t size = grabbag__file_get_filesize(spec);
if(size < 0)
*error_message = error_messages[5];
else {
......
......@@ -57,7 +57,7 @@ static const char * const LayerString[] = {
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static ::FLAC__StreamMetadata *expected_metadata_sequence_[9];
static unsigned num_expected_;
static off_t flacfilesize_;
static FLAC__off_t flacfilesize_;
static const char *flacfilename(bool is_ogg)
{
......@@ -229,7 +229,7 @@ public:
if(error_occurred_)
return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
if(fseeko(file_, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
if(fseeko(file_, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) {
error_occurred_ = true;
return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
......@@ -245,7 +245,7 @@ public:
if(error_occurred_)
return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
off_t offset = ftello(file_);
FLAC__off_t offset = ftello(file_);
*absolute_byte_offset = (FLAC__uint64)offset;
if(offset < 0) {
...