Applied the rest of useful changes from VNC 4.1.2 (version number changes were not applied). Now we can claim the source is based on VNC 4.1.2.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@581 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/rfb/Logger.cxx b/rfb/Logger.cxx
index 8b3c6ee..52d3308 100644
--- a/rfb/Logger.cxx
+++ b/rfb/Logger.cxx
@@ -30,25 +30,36 @@
 #include <rfb/Logger.h>
 #include <rfb/LogWriter.h>
 #include <rfb/util.h>
+#include <rfb/Threading.h>
 
 using namespace rfb;
 
 #ifndef HAVE_VSNPRINTF
-static int vsnprintf(char *str, size_t n, const char *format, va_list ap)
+#ifdef __RFB_THREADING_IMPL
+static Mutex fpLock;
+#endif
+static FILE* fp = 0;
+int vsnprintf(char *str, size_t n, const char *format, va_list ap)
 {
   str[0] = 0;
-  FILE* fp = fopen("/dev/null","w");
-  if (!fp) return 0;
+  if (!fp) {
+    // Safely create a FILE* for /dev/null if there isn't already one
+#ifdef __RFB_THREADING_IMPL
+    Lock l(fpLock);
+#endif
+    if (!fp)
+      fp = fopen("/dev/null","w");
+    if (!fp) return 0;
+  }
   int len = vfprintf(fp, format, ap);
   if (len <= 0) return 0;
-  fclose(fp);
 
   CharArray s(len+1);
   vsprintf(s.buf, format, ap);
 
-  if (len > (int)n-1) len = n-1;
-  memcpy(str, s.buf, len);
-  str[len] = 0;
+  int written = __rfbmin(len, (int)n-1);
+  memcpy(str, s.buf, written);
+  str[written] = 0;
   return len;
 }
 #endif
diff --git a/xc/programs/Xserver/vnc/module/Imakefile b/xc/programs/Xserver/vnc/module/Imakefile
index 7b31743..f279649 100644
--- a/xc/programs/Xserver/vnc/module/Imakefile
+++ b/xc/programs/Xserver/vnc/module/Imakefile
@@ -26,6 +26,12 @@
  InstallLibraryModule(vnc,$(MODULEDIR),extensions)
 */
 
+/* *** The imake rules don't define a ModuleCplusplusObjectRule so
+       for now we just assume that NormalCplusplusObjectRule will
+       do the job.
+   NB: If we don't do this then make will assume CC is the C++ compiler!
+*/
+NormalCplusplusObjectRule()
 
 /*
  * CplusplusDynamicModuleTarget - build a module to be dynamically loaded