Fix a couple of Windows 2Gig file size issues.
[platform/upstream/flac.git] / src / libFLAC / stream_encoder.c
index ce0c8da..f51ba74 100644 (file)
 #  include <config.h>
 #endif
 
-#if defined _MSC_VER || defined __MINGW32__
-#include <io.h> /* for _setmode() */
-#include <fcntl.h> /* for _O_BINARY */
-#endif
-#if defined __CYGWIN__ || defined __EMX__
-#include <io.h> /* for setmode(), O_BINARY */
-#include <fcntl.h> /* for _O_BINARY */
-#endif
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h> /* for malloc() */
@@ -48,8 +40,6 @@
 #include <sys/types.h> /* for off_t */
 #include "FLAC/assert.h"
 #include "FLAC/stream_decoder.h"
-#include "share/alloc.h"
-#include "share/compat.h"
 #include "protected/stream_encoder.h"
 #include "private/bitwriter.h"
 #include "private/bitmath.h"
 #endif
 #include "private/stream_encoder_framing.h"
 #include "private/window.h"
+#include "share/alloc.h"
+#include "share/compat.h"
+#include "share/private.h"
 
-#ifndef FLaC__INLINE
-#define FLaC__INLINE
-#endif
 
 /* Exact Rice codeword length calculation is off by default.  The simple
  * (and fast) estimation (of how many bits a residual value will be
@@ -463,7 +453,7 @@ FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
        "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
 };
 
-FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
+FLAC_API const char * const FLAC__StreamEncoderReadStatusString[] = {
        "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
        "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
        "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
@@ -581,7 +571,9 @@ FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
 {
        unsigned i;
 
-       FLAC__ASSERT(0 != encoder);
+       if (encoder == NULL)
+               return ;
+
        FLAC__ASSERT(0 != encoder->protected_);
        FLAC__ASSERT(0 != encoder->private_);
        FLAC__ASSERT(0 != encoder->private_->frame);
@@ -747,12 +739,12 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
 #if FLAC__HAS_OGG
        /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */
        if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
-               unsigned i;
-               for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
-                       if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
-                               FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
-                               for( ; i > 0; i--)
-                                       encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
+               unsigned i1;
+               for(i1 = 1; i1 < encoder->protected_->num_metadata_blocks; i1++) {
+                       if(0 != encoder->protected_->metadata[i1] && encoder->protected_->metadata[i1]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
+                               FLAC__StreamMetadata *vc = encoder->protected_->metadata[i1];
+                               for( ; i1 > 0; i1--)
+                                       encoder->protected_->metadata[i1] = encoder->protected_->metadata[i1-1];
                                encoder->protected_->metadata[0] = vc;
                                break;
                        }
@@ -761,10 +753,10 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
 #endif
        /* keep track of any SEEKTABLE block */
        if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
-               unsigned i;
-               for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
-                       if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
-                               encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
+               unsigned i2;
+               for(i2 = 0; i2 < encoder->protected_->num_metadata_blocks; i2++) {
+                       if(0 != encoder->protected_->metadata[i2] && encoder->protected_->metadata[i2]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
+                               encoder->private_->seek_table = &encoder->protected_->metadata[i2]->data.seek_table;
                                break; /* take only the first one */
                        }
                }
@@ -967,7 +959,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
                 */
                encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
                for(i = 0; i < encoder->protected_->channels; i++) {
-                       if(0 == (encoder->private_->verify.input_fifo.data[i] = safe_malloc_mul_2op_(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) {
+                       if(0 == (encoder->private_->verify.input_fifo.data[i] = safe_malloc_mul_2op_p(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) {
                                encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
                                return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
                        }
@@ -1708,7 +1700,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encod
        }
        if(num_blocks) {
                FLAC__StreamMetadata **m;
-               if(0 == (m = safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
+               if(0 == (m = safe_malloc_mul_2op_p(sizeof(m[0]), /*times*/num_blocks)))
                        return false;
                memcpy(m, metadata, sizeof(m[0]) * num_blocks);
                encoder->protected_->metadata = m;
@@ -3886,7 +3878,7 @@ void precompute_partition_info_escapes_(
 }
 
 #ifdef EXACT_RICE_BITS_CALCULATION
-static FLaC__INLINE unsigned count_rice_bits_in_partition_(
+static inline unsigned count_rice_bits_in_partition_(
        const unsigned rice_parameter,
        const unsigned partition_samples,
        const FLAC__int32 *residual
@@ -3901,7 +3893,7 @@ static FLaC__INLINE unsigned count_rice_bits_in_partition_(
        return partition_bits;
 }
 #else
-static FLaC__INLINE unsigned count_rice_bits_in_partition_(
+static inline unsigned count_rice_bits_in_partition_(
        const unsigned rice_parameter,
        const unsigned partition_samples,
        const FLAC__uint64 abs_residual_partition_sum
@@ -4248,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;
@@ -4256,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;