summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAdam Tkac <atkac@redhat.com>2008-11-14 13:11:31 +0000
committerAdam Tkac <atkac@redhat.com>2008-11-14 13:11:31 +0000
commit247b729032ac7add40daa29a0d981a55e09c4343 (patch)
tree2870d9738e87d6a27f0065c3f93f86ca80460b5f /common
parent49e5ce6cf11d7d0091438112e08ce977bc929f4e (diff)
downloadtigervnc-247b729032ac7add40daa29a0d981a55e09c4343.tar.gz
tigervnc-247b729032ac7add40daa29a0d981a55e09c4343.zip
[Refactoring] Introduced common/os/ directory for platform dependent
implementations and move vsnprintf() declaration there. [Refactoring] Introduced common/common-config.win.h for handling WIN32 platform specifics. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3167 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am2
-rw-r--r--common/common-config.win.h4
-rw-r--r--common/configure.ac1
-rw-r--r--common/os/Makefile.am5
-rw-r--r--common/os/print.c58
-rw-r--r--common/os/print.h37
-rw-r--r--common/rfb/Logger.cxx46
7 files changed, 107 insertions, 46 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 905a2b2d..d8058096 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS =
+SUBDIRS = os
if INCLUDED_ZLIB
SUBDIRS += zlib
diff --git a/common/common-config.win.h b/common/common-config.win.h
new file mode 100644
index 00000000..e68d3724
--- /dev/null
+++ b/common/common-config.win.h
@@ -0,0 +1,4 @@
+/* common-config.win.h - Platform-specific definitions for Windows */
+
+#define HAVE_VSNPRINTF 1
+#define vsnprintf _vsnprintf
diff --git a/common/configure.ac b/common/configure.ac
index fc2f8bf4..fabde362 100644
--- a/common/configure.ac
+++ b/common/configure.ac
@@ -87,6 +87,7 @@ AC_CHECK_TYPES([socklen_t],
AC_CHECK_HEADERS([sys/select.h])
AC_OUTPUT([Makefile
+ os/Makefile
rdr/Makefile
network/Makefile
Xregion/Makefile
diff --git a/common/os/Makefile.am b/common/os/Makefile.am
new file mode 100644
index 00000000..23e4dfb2
--- /dev/null
+++ b/common/os/Makefile.am
@@ -0,0 +1,5 @@
+noinst_LTLIBRARIES = libos.la
+
+HDRS = print.h
+
+libos_la_SOURCES = $(HDRS) print.c
diff --git a/common/os/print.c b/common/os/print.c
new file mode 100644
index 00000000..a38ea2fe
--- /dev/null
+++ b/common/os/print.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2008 TightVNC Team. All Rights Reserved.
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#ifdef HAVE_COMMON_CONFIG_H
+#include <common-config.h>
+#endif
+
+#include <os/print.h>
+#include <stdarg.h>
+
+#ifndef HAVE_VSNPRINTF
+int vsnprintf(char *str, size_t n, const char *format, va_list ap) {
+ static FILE *fp = NULL;
+ va_list ap_new;
+ int len, written;
+
+ if (n < 1)
+ return 0;
+
+ str[0] = '\0';
+ if (fp == NULL) {
+ fp = fopen("/dev/null","w");
+ if (fp == NULL)
+ return 0;
+ }
+
+ va_copy(ap_new, ap);
+ len = vfprintf(fp, format, ap_new);
+ va_end(ap_new);
+
+ if (len <= 0)
+ return 0;
+
+ CharArray s(len+1);
+ vsprintf(s.buf, format, ap);
+
+ written = (len < (n - 1)) ? len : (n - 1);
+ memcpy(str, s.buf, written);
+ str[written] = '\0';
+ return len;
+}
+#endif /* HAVE_VSNPRINTF */
+
diff --git a/common/os/print.h b/common/os/print.h
new file mode 100644
index 00000000..471002cf
--- /dev/null
+++ b/common/os/print.h
@@ -0,0 +1,37 @@
+/* Copyright (C) 2008 TightVNC Team. All Rights Reserved.
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#ifndef OS_PRINT_H
+#define OS_PRINT_H
+
+#ifdef HAVE_COMMON_CONFIG_H
+#include <common-config.h>
+#endif
+
+#ifdef WIN32
+#include <common-config.win32.h>
+#endif
+
+#include <stdarg.h>
+#include <sys/types.h>
+
+#ifndef HAVE_VSNPRINTF
+int vsnprintf(char *str, size_t n, const char *format, va_list ap);
+#endif
+
+#endif /* OS_PRINT_H */
diff --git a/common/rfb/Logger.cxx b/common/rfb/Logger.cxx
index 8c90906c..451cee25 100644
--- a/common/rfb/Logger.cxx
+++ b/common/rfb/Logger.cxx
@@ -18,64 +18,20 @@
// -=- Logger.cxx - support for the Logger and LogWriter classes
-#ifdef HAVE_COMMON_CONFIG_H
-#include <common-config.h>
-#endif
-
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#ifdef WIN32
#define strcasecmp _stricmp
-#define vsnprintf _vsnprintf
-#define HAVE_VSNPRINTF
#endif
+#include <os/print.h>
#include <rfb/Logger.h>
#include <rfb/LogWriter.h>
#include <rfb/util.h>
-#include <rfb/Threading.h>
using namespace rfb;
-#ifndef HAVE_VSNPRINTF
-#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)
-{
- va_list ap_new;
- int len, written;
-
- str[0] = 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;
- }
-
- va_copy(ap_new, ap);
- len = vfprintf(fp, format, ap_new);
- va_end(ap_new);
-
- if (len <= 0) return 0;
-
- CharArray s(len+1);
- vsprintf(s.buf, format, ap);
-
- written = __rfbmin(len, (int)n-1);
- memcpy(str, s.buf, written);
- str[written] = '\0';
- return len;
-}
-#endif
-
-
Logger* Logger::loggers = 0;
Logger::Logger(const char* name) : registered(false), m_name(name), m_next(0) {