THRIFT-302. ruby: Native extension fails to build

A piece of code needed for compilation on Linux was missing; this patch replaces it. Also, there were some compiler warnings and declarations that were missing that are now fixed.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@740366 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/ext/binary_protocol_accelerated.c b/lib/rb/ext/binary_protocol_accelerated.c
index 27567fc..8a6757f 100644
--- a/lib/rb/ext/binary_protocol_accelerated.c
+++ b/lib/rb/ext/binary_protocol_accelerated.c
@@ -1,5 +1,6 @@
 #include <ruby.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <constants.h>
 #include <struct.h>
 
@@ -434,4 +435,4 @@
   
   VALUE method_table_object = Data_Wrap_Struct(rb_cObject, 0, free, npmt);
   rb_const_set(bpa_class, rb_intern("@native_method_table"), method_table_object);
-}
\ No newline at end of file
+}
diff --git a/lib/rb/ext/binary_protocol_accelerated.h b/lib/rb/ext/binary_protocol_accelerated.h
index 4d3517b..6175ff4 100644
--- a/lib/rb/ext/binary_protocol_accelerated.h
+++ b/lib/rb/ext/binary_protocol_accelerated.h
@@ -1,2 +1 @@
-
-void Init_binary_protocol_accelerated();
\ No newline at end of file
+void Init_binary_protocol_accelerated();
diff --git a/lib/rb/ext/constants.h b/lib/rb/ext/constants.h
index f66a3ac..e540234 100644
--- a/lib/rb/ext/constants.h
+++ b/lib/rb/ext/constants.h
@@ -72,4 +72,4 @@
 extern VALUE thrift_module;
 extern VALUE thrift_types_module;
 extern VALUE class_thrift_protocol;
-extern VALUE protocol_exception_class;
\ No newline at end of file
+extern VALUE protocol_exception_class;
diff --git a/lib/rb/ext/memory_buffer.c b/lib/rb/ext/memory_buffer.c
index a607ae2..00545cc 100644
--- a/lib/rb/ext/memory_buffer.c
+++ b/lib/rb/ext/memory_buffer.c
@@ -49,4 +49,4 @@
   slice_method_id = rb_intern("slice");
   
   GARBAGE_BUFFER_SIZE = FIX2INT(rb_const_get(thrift_memory_buffer_class, rb_intern("GARBAGE_BUFFER_SIZE")));
-}
\ No newline at end of file
+}
diff --git a/lib/rb/ext/memory_buffer.h b/lib/rb/ext/memory_buffer.h
index ccc2aed..9e01d13 100644
--- a/lib/rb/ext/memory_buffer.h
+++ b/lib/rb/ext/memory_buffer.h
@@ -1,2 +1 @@
-
-void Init_memory_buffer();
\ No newline at end of file
+void Init_memory_buffer();
diff --git a/lib/rb/ext/protocol.c b/lib/rb/ext/protocol.c
index b548f97..207e78d 100644
--- a/lib/rb/ext/protocol.c
+++ b/lib/rb/ext/protocol.c
@@ -163,4 +163,4 @@
   // 
   // VALUE method_table_object = Data_Wrap_Struct(rb_cObject, 0, free, npmt);
   // rb_const_set(c_protocol, rb_intern("@native_method_table"), method_table_object);
-}
\ No newline at end of file
+}
diff --git a/lib/rb/ext/protocol.h b/lib/rb/ext/protocol.h
index 534c859..b5e066f 100644
--- a/lib/rb/ext/protocol.h
+++ b/lib/rb/ext/protocol.h
@@ -1,2 +1 @@
-
-void Init_protocol();
\ No newline at end of file
+void Init_protocol();
diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c
index 0e7aa1a..b882344 100644
--- a/lib/rb/ext/struct.c
+++ b/lib/rb/ext/struct.c
@@ -1,7 +1,28 @@
-
 #include <struct.h>
 #include <constants.h>
 
+#ifndef HAVE_STRLCPY
+
+static
+size_t
+strlcpy (char *dst, const char *src, size_t dst_sz)
+{
+    size_t n;
+
+    for (n = 0; n < dst_sz; n++) {
+      if ((*dst++ = *src++) == '\0')
+        break;
+    }
+
+    if (n < dst_sz)
+      return n;
+    if (n > 0)
+      *(dst - 1) = '\0';
+    return n + strlen (src);
+}
+
+#endif
+
 static native_proto_method_table *mt;
 
 #define IS_CONTAINER(ttype) ((ttype) == TTYPE_MAP || (ttype) == TTYPE_LIST || (ttype) == TTYPE_SET)
diff --git a/lib/rb/ext/struct.h b/lib/rb/ext/struct.h
index bf2350d..870d24e 100644
--- a/lib/rb/ext/struct.h
+++ b/lib/rb/ext/struct.h
@@ -45,4 +45,4 @@
   
 } native_proto_method_table;
 
-void Init_struct();
\ No newline at end of file
+void Init_struct();
diff --git a/lib/rb/ext/thrift_native.c b/lib/rb/ext/thrift_native.c
index 60d0fc0..89d32c5 100644
--- a/lib/rb/ext/thrift_native.c
+++ b/lib/rb/ext/thrift_native.c
@@ -166,4 +166,4 @@
   Init_struct();
   Init_binary_protocol_accelerated();
   Init_memory_buffer();
-}
\ No newline at end of file
+}