Large patch from Ben Allison fixing the MSVC build.
authorErik de Castro Lopo <erikd@mega-nerd.com>
Wed, 6 Mar 2013 11:17:46 +0000 (22:17 +1100)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Wed, 6 Mar 2013 11:17:51 +0000 (22:17 +1100)
Patch tweaked a little to fix Linux build and clean up minor problems.

examples/cpp/decode/file/main.cpp
examples/cpp/encode/file/main.cpp
include/share/alloc.h
include/share/compat.h
src/flac/analyze.c
src/libFLAC/include/private/bitmath.h
src/libFLAC/lpc.c
src/libFLAC/stream_decoder.c
src/test_libFLAC++/metadata_manip.cpp
src/test_streams/main.c

index b991d68..3ebe89a 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
-
 #include "FLAC++/decoder.h"
+#include "share/compat.h"
 
 static FLAC__uint64 total_samples = 0;
 static unsigned sample_rate = 0;
index a83de05..8661c87 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
-
 #include "FLAC++/metadata.h"
 #include "FLAC++/encoder.h"
+#include "share/compat.h"
 
 #include <cstring>
 
index 7aa17f7..8fc17f7 100644 (file)
 #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
 #endif
 #include <stdlib.h> /* for size_t, malloc(), etc */
+#include "share/compat.h"
 
 #ifndef SIZE_MAX
 # ifndef SIZE_T_MAX
 #  ifdef _MSC_VER
-#   define SIZE_T_MAX UINT_MAX /* What happens on 64 bit windows? */
+#   define SIZE_T_MAX SIZE_MAX
 #  else
 #   error
 #  endif
index 983b045..3bdf61a 100644 (file)
@@ -36,6 +36,9 @@
  * It is assumed that this header will be included after "config.h".
  */
 
+#ifndef FLAC__SHARE__COMPAT_H
+#define FLAC__SHARE__COMPAT_H
+
 #if defined _WIN32 && !defined __CYGWIN__
 /* where MSVC puts unlink() */
 # include <io.h>
@@ -56,6 +59,7 @@
 #endif
 
 #if HAVE_INTTYPES_H
+#define __STDC_FORMAT_MACROS
 #include <inttypes.h>
 #endif
 
 #endif
 
 #if defined(_MSC_VER)
+#if _MSC_VER < 1500
+/* Visual Studio 2008 has restrict. */
 #define restrict __restrict
+#endif
 #define inline __inline
 #endif
 
 #include <utime.h> /* for utime() */
 #include <unistd.h> /* for chown(), unlink() */
 #endif
+
+#if defined _MSC_VER
+#  if _MSC_VER >= 1600
+/* Visual Studio 2010 has decent C99 support */
+#    include <stdint.h>
+#    define PRIu64 "llu"
+#    define PRId64 "lld"
+#    define PRIx64 "llx"
+#  else
+#    include <limits.h>
+#    ifndef UINT32_MAX
+#      define UINT32_MAX _UI32_MAX
+#    endif
+     typedef unsigned __int64 uint64_t;
+     typedef unsigned __int32 uint32_t;
+     typedef unsigned __int16 uint16_t;
+     typedef unsigned __int8 uint8_t;
+     typedef __int64 int64_t;
+     typedef __int32 int32_t;
+     typedef __int16 int16_t;
+     typedef __int8  int8_t;
+#    define PRIu64 "I64u"
+#    define PRId64 "I64d"
+#    define PRIx64 "I64x"
+#  endif
+#endif /* defined _MSC_VER */
+
+#endif /* FLAC__SHARE__COMPAT_H */
index 038ff32..5152293 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <inttypes.h>
+
 #include "FLAC/all.h"
 #include "analyze.h"
 
+#include "share/compat.h"
+
 typedef struct {
        FLAC__int32 residual;
        unsigned count;
index 4e60f78..05daba1 100644 (file)
@@ -36,6 +36,7 @@
 
 /* for CHAR_BIT */
 #include <limits.h>
+#include "share/compat.h"
 
 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
 #include <intrin.h> /* for _BitScanReverse* */
index 66a6899..5f1ff99 100644 (file)
 #endif
 
 #include <math.h>
-#include <inttypes.h>
+
 #include "FLAC/assert.h"
 #include "FLAC/format.h"
+#include "share/compat.h"
 #include "private/bitmath.h"
 #include "private/lpc.h"
 #include "private/macros.h"
index 789db1b..ec36510 100644 (file)
 
 
 /* technically this should be in an "export.c" but this is convenient enough */
+#ifdef FLAC_API_SUPPORTS_OGG_FLAC
 FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = FLAC__HAS_OGG ;
+#else
+FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = 0 ;
+#endif
 
 
 /***********************************************************************
index f278e53..5cb2cf8 100644 (file)
 #include <stdlib.h> /* for malloc() */
 #include <string.h> /* for memcpy()/memset() */
 #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
+#ifdef _MSC_VER
+#include <sys/utime.h>
+#else
 #include <utime.h> /* for utime() */
+#endif
+#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
 #include <unistd.h> /* for chown(), unlink() */
+#endif
 #include <sys/stat.h> /* for stat(), maybe chmod() */
 #include "FLAC/assert.h"
 #include "FLAC++/decoder.h"
index 45d8d21..0c87e7f 100644 (file)
@@ -902,8 +902,11 @@ static FLAC__bool generate_noisy_sine(void)
 
                sample += sin (2.0 * k * M_PI * 1.0 / 32.0);
                sample *= 0.4;
-
+#if !defined _MSC_VER
                write_little_endian_int16(f, lrintf(sample * 32700.0));
+#else
+               write_little_endian_int16(f, (FLAC__int16)(sample * 32700.0));
+#endif
        };
 
        fclose(f);