From 9e5df27e38e5fa5df32f2a7f382387f4ebc106b9 Mon Sep 17 00:00:00 2001
From: sezero <sezero@users.sourceforge.net>
Date: Sun, 22 Jan 2017 11:15:50 +0300
Subject: [PATCH 5/9] bitreader.c, bitwriter.c: solve the inline issue for
 Watcom.

---
 src/libFLAC/bitreader.c | 18 ++++++++++++++++++
 src/libFLAC/bitwriter.c | 24 ++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c
index 7554385..5271351 100644
--- a/src/libFLAC/bitreader.c
+++ b/src/libFLAC/bitreader.c
@@ -83,6 +83,13 @@ typedef FLAC__uint64 brword;
 
 #endif
 
+#ifdef __WATCOMC__ /* see end of file for inline issue */
+#define FLAC__bitreader_is_consumed_byte_aligned FLAC__bitreader_is_consumed_byte_aligned__inl_
+#define FLAC__bitreader_bits_left_for_byte_alignment FLAC__bitreader_bits_left_for_byte_alignment__inl_
+#define FLAC__bitreader_get_input_bits_unconsumed FLAC__bitreader_get_input_bits_unconsumed__inl_
+#define FLAC__bitreader_read_uint32_little_endian FLAC__bitreader_read_uint32_little_endian__inl_
+#endif
+
 /*
  * This should be at least twice as large as the largest number of words
  * required to represent any 'number' (in any encoding) you are going to
@@ -1081,7 +1088,18 @@ FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *v
  * Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To
  * fix that we add extern declarations here.
  */
+#ifdef __WATCOMC__ /* adding externs doesn't help with Watcom */
+#undef FLAC__bitreader_is_consumed_byte_aligned
+#undef FLAC__bitreader_bits_left_for_byte_alignment
+#undef FLAC__bitreader_get_input_bits_unconsumed
+#undef FLAC__bitreader_read_uint32_little_endian
+FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br) { return FLAC__bitreader_is_consumed_byte_aligned__inl_(br); }
+uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br) { return FLAC__bitreader_bits_left_for_byte_alignment__inl_(br); }
+uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br) { return FLAC__bitreader_get_input_bits_unconsumed__inl_(br); }
+FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val) { return FLAC__bitreader_read_uint32_little_endian__inl_(br, val); }
+#else
 extern FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
 extern uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
 extern uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
 extern FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val);
+#endif
diff --git a/src/libFLAC/bitwriter.c b/src/libFLAC/bitwriter.c
index bfe79b0..251fb53 100644
--- a/src/libFLAC/bitwriter.c
+++ b/src/libFLAC/bitwriter.c
@@ -74,6 +74,15 @@ typedef FLAC__uint64 bwword;
 
 #endif
 
+#ifdef __WATCOMC__ /* see end of file for inline issue */
+#define FLAC__bitwriter_write_zeroes FLAC__bitwriter_write_zeroes__inl_
+#define FLAC__bitwriter_write_raw_uint32 FLAC__bitwriter_write_raw_uint32__inl_
+#define FLAC__bitwriter_write_raw_int32 FLAC__bitwriter_write_raw_int32__inl_
+#define FLAC__bitwriter_write_raw_uint64 FLAC__bitwriter_write_raw_uint64__inl_
+#define FLAC__bitwriter_write_raw_uint32_little_endian FLAC__bitwriter_write_raw_uint32_little_endian__inl_
+#define FLAC__bitwriter_write_byte_block FLAC__bitwriter_write_byte_block__inl_
+#endif
+
 /*
  * The default capacity here doesn't matter too much.  The buffer always grows
  * to hold whatever is written to it.  Usually the encoder will stop adding at
@@ -873,9 +882,24 @@ FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  * Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To
  * fix that we add extern declarations here.
  */
+#ifdef __WATCOMC__ /* adding externs doesn't help with Watcom */
+#undef FLAC__bitwriter_write_zeroes
+#undef FLAC__bitwriter_write_raw_uint32
+#undef FLAC__bitwriter_write_raw_int32
+#undef FLAC__bitwriter_write_raw_uint64
+#undef FLAC__bitwriter_write_raw_uint32_little_endian
+#undef FLAC__bitwriter_write_byte_block
+FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits) { return FLAC__bitwriter_write_zeroes__inl_(bw, bits); }
+FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits) { return FLAC__bitwriter_write_raw_uint32__inl_(bw, val, bits); }
+FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits) { return FLAC__bitwriter_write_raw_int32__inl_(bw, val, bits); }
+FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits) { return FLAC__bitwriter_write_raw_uint64__inl_(bw, val, bits); }
+FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val) { return FLAC__bitwriter_write_raw_uint32_little_endian__inl_(bw, val); }
+FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals) { return FLAC__bitwriter_write_byte_block__inl_(bw, vals, nvals); }
+#else
 extern FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits);
 extern FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits);
 extern FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits);
 extern FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits);
 extern FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val);
 extern FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals);
+#endif
-- 
1.8.5.5

