Fix a couple of Windows 2Gig file size issues.
authorErik de Castro Lopo <erikd@mega-nerd.com>
Thu, 14 Mar 2013 07:22:29 +0000 (18:22 +1100)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Thu, 14 Mar 2013 07:22:37 +0000 (18:22 +1100)
Patch submitted by Janne Hyvärinen <cse@sci.fi>.

25 files changed:
include/share/compat.h
include/share/grabbag/file.h
include/test_libs_common/file_utils_flac.h
src/flac/decode.c
src/flac/encode.c
src/flac/encode.h
src/flac/foreign_metadata.c
src/flac/foreign_metadata.h
src/flac/main.c
src/flac/vorbiscomment.c
src/libFLAC/metadata_iterators.c
src/libFLAC/stream_decoder.c
src/libFLAC/stream_encoder.c
src/metaflac/operations_shorthand_vorbiscomment.c
src/share/grabbag/file.c
src/share/grabbag/picture.c
src/test_libFLAC++/decoders.cpp
src/test_libFLAC++/encoders.cpp
src/test_libFLAC++/metadata_manip.cpp
src/test_libFLAC/decoders.c
src/test_libFLAC/encoders.c
src/test_libFLAC/metadata_manip.c
src/test_libs_common/file_utils_flac.c
src/test_seeking/main.c
src/utils/flacdiff/main.cpp

index 279e866..d056b0b 100644 (file)
 
 #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
index 62b2907..98bccfb 100644 (file)
 #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"
index e802fca..c92bac0 100644 (file)
 
 #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
index 4ead48b..2f2c311 100644 (file)
@@ -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;
 
 
index b2ae06a..1b6a4d6 100644 (file)
@@ -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");
index 5a8c1e0..337d5af 100644 (file)
@@ -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
index 980120d..b8e8b46 100644 (file)
@@ -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;
index d3824e2..0afd66d 100644 (file)
@@ -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
index c96f93e..dd03d5b 100644 (file)
@@ -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;
        }
index 86b1dfe..789b183 100644 (file)
@@ -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;
index a679165..d2a229a 100644 (file)
@@ -105,10 +105,10 @@ static unsigned seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IO
 static unsigned seek_to_first_metadata_block_(FILE *f);
 
 static FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append);
-static FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, off_t fixup_is_last_flag_offset, FLAC__bool backup);
+static FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup);
 
-static FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status);
-static FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status);
+static FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status);
+static FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status);
 static FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status);
 static FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status);
 
@@ -329,8 +329,8 @@ struct FLAC__Metadata_SimpleIterator {
        FLAC__bool has_stats;
        FLAC__bool is_writable;
        FLAC__Metadata_SimpleIteratorStatus status;
-       off_t offset[SIMPLE_ITERATOR_MAX_PUSH_DEPTH];
-       off_t first_offset; /* this is the offset to the STREAMINFO block */
+       FLAC__off_t offset[SIMPLE_ITERATOR_MAX_PUSH_DEPTH];
+       FLAC__off_t first_offset; /* this is the offset to the STREAMINFO block */
        unsigned depth;
        /* this is the metadata block header of the current block we are pointing to: */
        FLAC__bool is_last;
@@ -526,7 +526,7 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIte
 
 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator)
 {
-       off_t this_offset;
+       FLAC__off_t this_offset;
 
        FLAC__ASSERT(0 != iterator);
        FLAC__ASSERT(0 != iterator->file);
@@ -543,7 +543,7 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIte
                return false;
 
        /* we ignore any error from ftello() and catch it in fseeko() */
-       while(ftello(iterator->file) + (off_t)iterator->length < iterator->offset[iterator->depth]) {
+       while(ftello(iterator->file) + (FLAC__off_t)iterator->length < iterator->offset[iterator->depth]) {
                if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) {
                        iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
                        return false;
@@ -652,7 +652,7 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Me
 
 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding)
 {
-       FLAC__ASSERT_DECLARATION(off_t debug_target_offset = iterator->offset[iterator->depth];)
+       FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];)
        FLAC__bool ret;
 
        FLAC__ASSERT(0 != iterator);
@@ -679,13 +679,13 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_Simp
                if(use_padding && iterator->length >= FLAC__STREAM_METADATA_HEADER_LENGTH + block->length) {
                        ret = write_metadata_block_stationary_with_padding_(iterator, block, iterator->length - FLAC__STREAM_METADATA_HEADER_LENGTH - block->length, block->is_last);
                        FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
-                       FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                       FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                        return ret;
                }
                else {
                        ret = rewrite_whole_file_(iterator, block, /*append=*/false);
                        FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
-                       FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                       FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                        return ret;
                }
        }
@@ -728,21 +728,21 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_Simp
                        if(padding_leftover == 0) {
                                ret = write_metadata_block_stationary_(iterator, block);
                                FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
-                               FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                               FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                                return ret;
                        }
                        else {
                                FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH);
                                ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last);
                                FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
-                               FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                               FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                                return ret;
                        }
                }
                else {
                        ret = rewrite_whole_file_(iterator, block, /*append=*/false);
                        FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
-                       FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                       FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                        return ret;
                }
        }
@@ -753,7 +753,7 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Meta
        unsigned padding_leftover = 0;
        FLAC__bool padding_is_last = false;
 
-       FLAC__ASSERT_DECLARATION(off_t debug_target_offset = iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length;)
+       FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length;)
        FLAC__bool ret;
 
        FLAC__ASSERT(0 != iterator);
@@ -808,28 +808,28 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Meta
                if(padding_leftover == 0) {
                        ret = write_metadata_block_stationary_(iterator, block);
                        FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset);
-                       FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                       FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                        return ret;
                }
                else {
                        FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH);
                        ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last);
                        FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset);
-                       FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+                       FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                        return ret;
                }
        }
        else {
                ret = rewrite_whole_file_(iterator, block, /*append=*/true);
                FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset);
-               FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+               FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
                return ret;
        }
 }
 
 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding)
 {
-       FLAC__ASSERT_DECLARATION(off_t debug_target_offset = iterator->offset[iterator->depth];)
+       FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];)
        FLAC__bool ret;
 
        if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO) {
@@ -851,14 +851,14 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_S
                FLAC__metadata_object_delete(padding);
                if(!FLAC__metadata_simple_iterator_prev(iterator))
                        return false;
-               FLAC__ASSERT(iterator->offset[iterator->depth] + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (off_t)iterator->length == debug_target_offset);
-               FLAC__ASSERT(ftello(iterator->file) + (off_t)iterator->length == debug_target_offset);
+               FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset);
+               FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset);
                return true;
        }
        else {
                ret = rewrite_whole_file_(iterator, 0, /*append=*/false);
-               FLAC__ASSERT(iterator->offset[iterator->depth] + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (off_t)iterator->length == debug_target_offset);
-               FLAC__ASSERT(ftello(iterator->file) + (off_t)iterator->length == debug_target_offset);
+               FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset);
+               FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset);
                return ret;
        }
 }
@@ -884,13 +884,13 @@ struct FLAC__Metadata_Chain {
        FLAC__Metadata_Node *tail;
        unsigned nodes;
        FLAC__Metadata_ChainStatus status;
-       off_t first_offset, last_offset;
+       FLAC__off_t first_offset, last_offset;
        /*
         * This is the length of the chain initially read from the FLAC file.
         * it is used to compare against the current length to decide whether
         * or not the whole file has to be rewritten.
         */
-       off_t initial_length;
+       FLAC__off_t initial_length;
        /* @@@ hacky, these are currently only needed by ogg reader */
        FLAC__IOHandle handle;
        FLAC__IOCallback_Read read_cb;
@@ -1014,10 +1014,10 @@ static void chain_delete_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node
        node_delete_(node);
 }
 
-static off_t chain_calculate_length_(FLAC__Metadata_Chain *chain)
+static FLAC__off_t chain_calculate_length_(FLAC__Metadata_Chain *chain)
 {
        const FLAC__Metadata_Node *node;
-       off_t length = 0;
+       FLAC__off_t length = 0;
        for(node = chain->head; node; node = node->next)
                length += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length);
        return length;
@@ -1096,20 +1096,20 @@ static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLA
 /* WATCHOUT: Make sure to also update the logic in
  * FLAC__metadata_chain_check_if_tempfile_needed() if the logic here changes.
  */
-static off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
+static FLAC__off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
 {
-       off_t current_length = chain_calculate_length_(chain);
+       FLAC__off_t current_length = chain_calculate_length_(chain);
 
        if(use_padding) {
                /* if the metadata shrank and the last block is padding, we just extend the last padding block */
                if(current_length < chain->initial_length && chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) {
-                       const off_t delta = chain->initial_length - current_length;
+                       const FLAC__off_t delta = chain->initial_length - current_length;
                        chain->tail->data->length += delta;
                        current_length += delta;
                        FLAC__ASSERT(current_length == chain->initial_length);
                }
                /* if the metadata shrank more than 4 bytes then there's room to add another padding block */
-               else if(current_length + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) {
+               else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) {
                        FLAC__StreamMetadata *padding;
                        FLAC__Metadata_Node *node;
                        if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) {
@@ -1129,16 +1129,16 @@ static off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool us
                }
                /* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */
                else if(current_length > chain->initial_length) {
-                       const off_t delta = current_length - chain->initial_length;
+                       const FLAC__off_t delta = current_length - chain->initial_length;
                        if(chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) {
                                /* if the delta is exactly the size of the last padding block, remove the padding block */
-                               if((off_t)chain->tail->data->length + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) {
+                               if((FLAC__off_t)chain->tail->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) {
                                        chain_delete_node_(chain, chain->tail);
                                        current_length = chain_calculate_length_(chain);
                                        FLAC__ASSERT(current_length == chain->initial_length);
                                }
                                /* if there is at least 'delta' bytes of padding, trim the padding down */
-                               else if((off_t)chain->tail->data->length >= delta) {
+                               else if((FLAC__off_t)chain->tail->data->length >= delta) {
                                        chain->tail->data->length -= delta;
                                        current_length -= delta;
                                        FLAC__ASSERT(current_length == chain->initial_length);
@@ -1181,7 +1181,7 @@ static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle han
                        chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
                        return false;
                }
-               chain->first_offset = (off_t)pos;
+               chain->first_offset = (FLAC__off_t)pos;
        }
 
        {
@@ -1227,7 +1227,7 @@ static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle han
                        chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
                        return false;
                }
-               chain->last_offset = (off_t)pos;
+               chain->last_offset = (FLAC__off_t)pos;
        }
 
        chain->initial_length = chain_calculate_length_(chain);
@@ -1598,7 +1598,7 @@ FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata
         * but doesn't actually alter the chain.  Make sure to update the logic
         * here if chain_prepare_for_write_() changes.
         */
-       const off_t current_length = chain_calculate_length_(chain);
+       const FLAC__off_t current_length = chain_calculate_length_(chain);
 
        FLAC__ASSERT(0 != chain);
 
@@ -1607,17 +1607,17 @@ FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata
                if(current_length < chain->initial_length && chain->tail->data->type == FLAC__METADATA_TYPE_PADDING)
                        return false;
                /* if the metadata shrank more than 4 bytes then there's room to add another padding block */
-               else if(current_length + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length)
+               else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length)
                        return false;
                /* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */
                else if(current_length > chain->initial_length) {
-                       const off_t delta = current_length - chain->initial_length;
+                       const FLAC__off_t delta = current_length - chain->initial_length;
                        if(chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) {
                                /* if the delta is exactly the size of the last padding block, remove the padding block */
-                               if((off_t)chain->tail->data->length + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta)
+                               if((FLAC__off_t)chain->tail->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta)
                                        return false;
                                /* if there is at least 'delta' bytes of padding, trim the padding down */
-                               else if((off_t)chain->tail->data->length >= delta)
+                               else if((FLAC__off_t)chain->tail->data->length >= delta)
                                        return false;
                        }
                }
@@ -1630,7 +1630,7 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC
 {
        struct stat stats;
        const char *tempfile_path_prefix = 0;
-       off_t current_length;
+       FLAC__off_t current_length;
 
        FLAC__ASSERT(0 != chain);
 
@@ -1679,7 +1679,7 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC
 
 FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
 {
-       off_t current_length;
+       FLAC__off_t current_length;
 
        FLAC__ASSERT(0 != chain);
 
@@ -1716,7 +1716,7 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Cha
 
 FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks)
 {
-       off_t current_length;
+       FLAC__off_t current_length;
 
        FLAC__ASSERT(0 != chain);
 
@@ -2885,7 +2885,7 @@ FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__St
        FILE *tempfile = NULL;
        char *tempfilename = NULL;
        int fixup_is_last_code = 0; /* 0 => no need to change any is_last flags */
-       off_t fixup_is_last_flag_offset = -1;
+       FLAC__off_t fixup_is_last_flag_offset = -1;
 
        FLAC__ASSERT(0 != block || append == false);
 
@@ -3013,7 +3013,7 @@ unsigned seek_to_first_metadata_block_(FILE *f)
 
 FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append)
 {
-       const off_t offset_end = append? iterator->offset[iterator->depth] + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (off_t)iterator->length : iterator->offset[iterator->depth];
+       const FLAC__off_t offset_end = append? iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length : iterator->offset[iterator->depth];
 
        if(0 != fseeko(iterator->file, 0, SEEK_SET)) {
                iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
@@ -3031,12 +3031,12 @@ FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iter
        return true;
 }
 
-FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, off_t fixup_is_last_flag_offset, FLAC__bool backup)
+FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup)
 {
-       off_t save_offset = iterator->offset[iterator->depth];
+       FLAC__off_t save_offset = iterator->offset[iterator->depth];
        FLAC__ASSERT(0 != *tempfile);
 
-       if(0 != fseeko(iterator->file, save_offset + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (off_t)iterator->length, SEEK_SET)) {
+       if(0 != fseeko(iterator->file, save_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length, SEEK_SET)) {
                cleanup_tempfile_(tempfile, tempfilename);
                iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
                return false;
@@ -3096,7 +3096,7 @@ FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *ite
        if(!simple_iterator_prime_input_(iterator, !iterator->is_writable))
                return false;
        if(backup) {
-               while(iterator->offset[iterator->depth] + (off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (off_t)iterator->length < save_offset)
+               while(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length < save_offset)
                        if(!FLAC__metadata_simple_iterator_next(iterator))
                                return false;
                return true;
@@ -3110,7 +3110,7 @@ FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *ite
        }
 }
 
-FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status)
+FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status)
 {
        FLAC__byte buffer[8192];
        size_t n;
@@ -3132,7 +3132,7 @@ FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, off_t bytes, FLAC
        return true;
 }
 
-FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status)
+FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status)
 {
        FLAC__byte buffer[8192];
        size_t n;
@@ -3303,7 +3303,7 @@ void set_file_stats_(const char *filename, struct stat *stats)
 
 int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
 {
-       return fseeko((FILE*)handle, (off_t)offset, whence);
+       return fseeko((FILE*)handle, (FLAC__off_t)offset, whence);
 }
 
 FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle)
index ec36510..320baa8 100644 (file)
@@ -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;
index 83849d4..f51ba74 100644 (file)
@@ -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;
 
index a8d5cd1..610e972 100644 (file)
@@ -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;
index a95cd3f..04e3aad 100644 (file)
@@ -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;
index c65e804..965a7b3 100644 (file)
@@ -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 {
index 938c60b..f5b1d0b 100644 (file)
@@ -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) {
index 32cf513..daa12f3 100644 (file)
@@ -28,6 +28,7 @@ extern "C" {
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "share/compat.h"
 
 typedef enum {
        LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */
@@ -131,7 +132,7 @@ public:
 {
        if(layer_==LAYER_STREAM)
                return ::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
-       else if(fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0)
+       else if(fseeko(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;
@@ -139,10 +140,10 @@ public:
 
 ::FLAC__StreamEncoderTellStatus StreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
 {
-       long pos;
+       FLAC__off_t pos;
        if(layer_==LAYER_STREAM)
                return ::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
-       else if((pos = ftell(file_)) < 0)
+       else if((pos = ftello(file_)) < 0)
                return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
        else {
                *absolute_byte_offset = (FLAC__uint64)pos;
@@ -478,11 +479,7 @@ static bool test_stream_encoder(Layer layer, bool is_ogg)
 
        printf("testing get_total_samples_estimate()... ");
        if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
-#ifdef _MSC_VER
-               printf("FAILED, expected %I64u, got %I64u\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
-#else
-               printf("FAILED, expected %llu, got %llu\n", (unsigned long long)streaminfo_.data.stream_info.total_samples, (unsigned long long)encoder->get_total_samples_estimate());
-#endif
+               printf("FAILED, expected %" PRIu64 ", got %" PRIu64 "\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
                return false;
        }
        printf("OK\n");
index 5cb2cf8..ff02416 100644 (file)
@@ -295,7 +295,7 @@ static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, ::FLAC
 
 static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence)
 {
-       off_t o = (off_t)offset;
+       FLAC__off_t o = (FLAC__off_t)offset;
        FLAC__ASSERT(offset == o);
        return fseeko((FILE*)handle, o, whence);
 }
index d913f0a..c9d2cdf 100644 (file)
@@ -57,7 +57,7 @@ typedef struct {
 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(FLAC__bool is_ogg)
 {
@@ -164,7 +164,7 @@ static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__S
        if(dcd->error_occurred)
                return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
 
-       if(fseeko(dcd->file, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
+       if(fseeko(dcd->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) {
                dcd->error_occurred = true;
                return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
        }
@@ -175,7 +175,7 @@ static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__S
 static FLAC__StreamDecoderTellStatus stream_decoder_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
 {
        StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
-       off_t offset;
+       FLAC__off_t offset;
 
        (void)decoder;
 
index d05c674..8ed55f6 100644 (file)
@@ -120,7 +120,7 @@ static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__S
 {
        FILE *f = (FILE*)client_data;
        (void)encoder;
-       if(fseek(f, (long)absolute_byte_offset, SEEK_SET) < 0)
+       if(fseeko(f, (long)absolute_byte_offset, SEEK_SET) < 0)
                return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
        else
                return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
@@ -129,9 +129,9 @@ static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__S
 static FLAC__StreamEncoderTellStatus stream_encoder_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
 {
        FILE *f = (FILE*)client_data;
-       long pos;
+       FLAC__off_t pos;
        (void)encoder;
-       if((pos = ftell(f)) < 0)
+       if((pos = ftello(f)) < 0)
                return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
        else {
                *absolute_byte_offset = (FLAC__uint64)pos;
index e720056..ea51d17 100644 (file)
@@ -279,7 +279,7 @@ static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, FLAC__
 
 static int chain_seek_cb_(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
 {
-       off_t o = (off_t)offset;
+       FLAC__off_t o = (FLAC__off_t)offset;
        FLAC__ASSERT(offset == o);
        return fseeko((FILE*)handle, o, whence);
 }
index 4c5fcf8..0de9e9c 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h> /* for stat() */
+#include "share/compat.h"
 
 #ifdef min
 #undef min
@@ -67,7 +68,7 @@ static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const
        (void)encoder, (void)metadata, (void)client_data;
 }
 
-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)
 {
        FLAC__int32 samples[1024];
        FLAC__StreamEncoder *encoder;
@@ -141,9 +142,15 @@ FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_f
        FLAC__stream_encoder_delete(encoder);
 
        if(0 != output_filesize) {
+#if defined _MSC_VER || defined __MINGW32__
+               struct _stat64 filestats;
+
+               if(_stat64(output_filename, &filestats) != 0)
+#else
                struct stat filestats;
 
                if(stat(output_filename, &filestats) != 0)
+#endif
                        return false;
                else
                        *output_filesize = filestats.st_size;
index c9f9567..318bce8 100644 (file)
@@ -91,11 +91,17 @@ static unsigned local_rand_(void)
 #undef RNDFUNC
 }
 
-static off_t get_filesize_(const char *srcpath)
+static FLAC__off_t 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;
@@ -106,7 +112,7 @@ static FLAC__bool read_pcm_(FLAC__int32 *pcm[], const char *rawfilename, const c
        FILE *f;
        unsigned channels = 0, bps = 0, samples, i, j;
 
-       off_t rawfilesize = get_filesize_(rawfilename);
+       FLAC__off_t rawfilesize = get_filesize_(rawfilename);
        if (rawfilesize < 0) {
                fprintf(stderr, "ERROR: can't determine filesize for %s\n", rawfilename);
                return false;
@@ -262,7 +268,7 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
  * 1 - read 2 frames
  * 2 - read until end
  */
-static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count, FLAC__int64 total_samples, unsigned read_mode, FLAC__int32 **pcm)
+static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, FLAC__off_t filesize, unsigned count, FLAC__int64 total_samples, unsigned read_mode, FLAC__int32 **pcm)
 {
        FLAC__StreamDecoder *decoder;
        DecoderClientData decoder_client_data;
@@ -411,7 +417,7 @@ int main(int argc, char *argv[])
        const char *flacfilename, *rawfilename = 0;
        unsigned count = 0, read_mode;
        FLAC__int64 samples = -1;
-       off_t flacfilesize;
+       FLAC__off_t flacfilesize;
        FLAC__int32 *pcm[2] = { 0, 0 };
        FLAC__bool ok = true;
 
index 5e7c49d..d4c8f06 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include "FLAC++/decoder.h"
-#if defined _MSC_VER || defined __MINGW32__
-#if _MSC_VER <= 1600 /* @@@ [2G limit] */
-#define fseeko fseek
-#define ftello ftell
-#endif
-#endif
+#include "share/compat.h"
 
 #ifdef _MSC_VER
 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
@@ -53,7 +48,7 @@ private:
 
 class Decoder: public FLAC::Decoder::Stream {
 public:
-       Decoder(AutoFILE &f, off_t tgt): tgtpos_((FLAC__uint64)tgt), curpos_(0), go_(true), err_(false), frame_(), f_(f) { memset(&frame_, 0, sizeof(::FLAC__Frame)); }
+       Decoder(AutoFILE &f, FLAC__off_t tgt): tgtpos_((FLAC__uint64)tgt), curpos_(0), go_(true), err_(false), frame_(), f_(f) { memset(&frame_, 0, sizeof(::FLAC__Frame)); }
        FLAC__uint64 tgtpos_, curpos_;
        bool go_, err_;
        ::FLAC__Frame frame_;
@@ -73,7 +68,7 @@ protected:
 
        virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset)
        {
-               off_t off = ftello(f_);
+               FLAC__off_t off = ftello(f_);
                if(off < 0)
                        return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
                *absolute_byte_offset = off;
@@ -110,7 +105,7 @@ protected:
        }
 };
 
-static bool show_diff(AutoFILE &f1, AutoFILE &f2, off_t off)
+static bool show_diff(AutoFILE &f1, AutoFILE &f2, FLAC__off_t off)
 {
        Decoder d1(f1, off), d2(f2, off);
        if(!d1) {
@@ -160,15 +155,15 @@ static bool show_diff(AutoFILE &f1, AutoFILE &f2, off_t off)
                fprintf(stderr, "ERROR: d1.go_(%s) != d2.go_(%s)\n", d1.go_?"true":"false", d2.go_?"true":"false");
                return false;
        }
-       fprintf(stdout, "pos1 = %llu  blocksize=%u sample#%llu frame#%llu\n", d1.curpos_, d1.frame_.header.blocksize, d1.frame_.header.number.sample_number, d1.frame_.header.number.sample_number / d1.frame_.header.blocksize);
-       fprintf(stdout, "pos2 = %llu  blocksize=%u sample#%llu frame#%llu\n", d2.curpos_, d2.frame_.header.blocksize, d2.frame_.header.number.sample_number, d2.frame_.header.number.sample_number / d2.frame_.header.blocksize);
+       fprintf(stdout, "pos1 = %" PRIu64 "  blocksize=%u sample#%" PRIu64 " frame#%" PRIu64 "\n", d1.curpos_, d1.frame_.header.blocksize, d1.frame_.header.number.sample_number, d1.frame_.header.number.sample_number / d1.frame_.header.blocksize);
+       fprintf(stdout, "pos2 = %" PRIu64 "  blocksize=%u sample#%" PRIu64 " frame#%" PRIu64 "\n", d2.curpos_, d2.frame_.header.blocksize, d2.frame_.header.number.sample_number, d2.frame_.header.number.sample_number / d2.frame_.header.blocksize);
 
        return true;
 }
 
-static off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2)
+static FLAC__off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2)
 {
-       off_t off = 0;
+       FLAC__off_t off = 0;
        while(1) {
                if(feof((FILE*)f1) && feof((FILE*)f1)) {
                        fprintf(stderr, "ERROR: files are identical\n");
@@ -190,7 +185,7 @@ static off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2)
 
 static bool run(const char *fn1, const char *fn2)
 {
-       off_t off;
+       FLAC__off_t off;
        AutoFILE f1(fn1, "rb"), f2(fn2, "rb");
 
        if(!f1) {
@@ -205,7 +200,7 @@ static bool run(const char *fn1, const char *fn2)
        if((off = get_diff_offset(f1, f2)) < 0)
                return false;
 
-       fprintf(stdout, "got diff offset = %u\n", (unsigned)off); //@@@ 4G limit (what is % modifier for off_t?)
+       fprintf(stdout, "got diff offset = %" PRId64 "\n", off);
 
        return show_diff(f1, f2, off);
 }