Merge pull request #47 from sergiud/master
[platform/upstream/glog.git] / src / signalhandler_unittest.cc
index 05a5b96..8dae5f5 100644 (file)
 #include <string>
 #include "glog/logging.h"
 
+#ifdef HAVE_LIB_GFLAGS
+#include <gflags/gflags.h>
+using namespace gflags;
+#endif
+
 using namespace GOOGLE_NAMESPACE;
 
 void* DieInThread(void*) {
-  fprintf(stderr, "0x%lx is dying\n", pthread_self());
+  // We assume pthread_t is an integral number or a pointer, rather
+  // than a complex struct.  In some environments, pthread_self()
+  // returns an uint64 but in some other environments pthread_self()
+  // returns a pointer.  Hence we use C-style cast here, rather than
+  // reinterpret/static_cast, to support both types of environments.
+  fprintf(stderr, "0x%lx is dying\n", (long)pthread_self());
   // Use volatile to prevent from these to be optimized away.
   volatile int a = 0;
   volatile int b = 1 / a;
@@ -53,7 +63,9 @@ void* DieInThread(void*) {
 }
 
 void WriteToStdout(const char* data, int size) {
-  write(STDOUT_FILENO, data, size);
+  if (write(STDOUT_FILENO, data, size) < 0) {
+    // Ignore errors.
+  }
 }
 
 int main(int argc, char **argv) {