Rename _flac_stat to flac_stat_s.
[platform/upstream/flac.git] / src / libFLAC / stream_decoder.c
index 5b3c3cd..29e4469 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 <stdio.h>
 #include <stdlib.h> /* for malloc() */
 #include <string.h> /* for memset/memcpy() */
 #include "private/memory.h"
 #include "private/macros.h"
 
-/* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
-#ifdef _MSC_VER
-#define FLAC__U64L(x) x
-#else
-#define FLAC__U64L(x) x##LLU
-#endif
-
 
 /* technically this should be in an "export.c" but this is convenient enough */
-FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
-#if FLAC__HAS_OGG
-       1
+#ifdef FLAC_API_SUPPORTS_OGG_FLAC
+FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = FLAC__HAS_OGG ;
 #else
-       0
+FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = 0 ;
 #endif
-;
 
 
 /***********************************************************************
@@ -332,7 +315,9 @@ FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
 {
        unsigned i;
 
-       FLAC__ASSERT(0 != decoder);
+       if (decoder == NULL)
+               return ;
+
        FLAC__ASSERT(0 != decoder->protected_);
        FLAC__ASSERT(0 != decoder->private_);
        FLAC__ASSERT(0 != decoder->private_->input);
@@ -619,7 +604,7 @@ static FLAC__StreamDecoderInitStatus init_file_internal_(
        if(0 == write_callback || 0 == error_callback)
                return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
 
-       file = filename? fopen(filename, "rb") : stdin;
+       file = filename? flac_fopen(filename, "rb") : stdin;
 
        if(0 == file)
                return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
@@ -1727,7 +1712,7 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre
 
        /* read comments */
        if(obj->num_comments > 0) {
-               if(0 == (obj->comments = safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
+               if(0 == (obj->comments = safe_malloc_mul_2op_p(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
                        decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
                        return false;
                }
@@ -3334,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;
@@ -3342,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)
@@ -3357,12 +3342,12 @@ 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)
 {
-       struct stat filestats;
+       struct flac_stat_s filestats;
        (void)client_data;
 
        if(decoder->private_->file == stdin)
                return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
-       else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
+       else if(flac_fstat(fileno(decoder->private_->file), &filestats) != 0)
                return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
        else {
                *stream_length = (FLAC__uint64)filestats.st_size;