Permalink
Browse files

Add compatibility header.

  • Loading branch information...
1 parent 5fb00d0 commit 81ec2f07a7cfed23270590ddad6fc69673b4f19e @Flast Flast committed Oct 4, 2011
Showing with 59 additions and 56 deletions.
  1. +1 −1 Makefile.am
  2. +50 −0 compatibility.h
  3. +2 −1 display/msagent/Makefile.w32
  4. +2 −7 display/msagent/msagent.c
  5. +2 −24 gol.c
  6. +1 −13 plugins/from_url.c
  7. +1 −10 plugins/memfile.c
View
@@ -4,7 +4,7 @@ SUBDIRS = plugins data \
subscribe/tweets subscribe/rhythmbox
bin_PROGRAMS = gol
-gol_SOURCES = gol.c gol.h
+gol_SOURCES = gol.c gol.h compatibility.h
gol_CFLAGS = $(GTK2_CFLAGS) $(OPENSSL_CFLAGS) $(SQLITE3_CFLAGS) -DDATADIR='"$(pkgdatadir)"' -DLIBDIR='"$(pkglibdir)"'
gol_LDADD = $(GTK2_LIBS) $(OPENSSL_LIBS) $(SQLITE3_LIBS)
View
@@ -0,0 +1,50 @@
+#ifndef compatibility_h_
+#define compatibility_h_
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gol.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _WIN32
+
+typedef char sockopt_t;
+typedef int socklen_t;
+
+# ifndef strncasecmp
+# define strncasecmp strnicmp
+# endif
+
+GOL_INLINE char*
+strndup(const char* src, size_t n) {
+ const size_t srclen = strlen(src);
+ n = n < srclen ? n : srclen;
+ char* ptr = (char*) malloc(n + 1);
+ *(ptr + n) = 0;
+ memcpy(ptr, src, n);
+ return ptr;
+}
+
+#else // _WIN32
+
+# define closesocket(x) close(x)
+
+typedef int sockopt_t;
+
+# ifndef SD_BOTH
+# define SD_BOTH SHUT_RDWR
+# endif
+
+#endif // _WIN32
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // compatibility_h_
+
@@ -1,7 +1,8 @@
PACKAGE_VERSION=$(shell cat ../../VERSION)
CFLAGS=-g -Wall -std=c99 -DPACKAGE_VERSION=\"$(PACKAGE_VERSION)\" \
-mms-bitfields -Ic:/gtk/include/gtk-2.0 -Ic:/gtk/lib/gtk-2.0/include -Ic:/gtk/include/atk-1.0 -Ic:/gtk/include/cairo -Ic:/gtk/include/pango-1.0 -Ic:/gtk/include/glib-2.0 -Ic:/gtk/lib/glib-2.0/include -Ic:/gtk/include/freetype2 -Ic:/gtk/include -Ic:/gtk/include/libpng14 -Ic:/gtk/include/libxml2 \
- -Ic:/openssl-win32/include
+ -Ic:/openssl-win32/include \
+ -I../..
LDFLAGS=-Lc:/gtk/lib \
-L../../plugins \
-lgolplug \
@@ -28,17 +28,12 @@
#include <gmodule.h>
#include <glib.h>
//#include <curl/curl.h>
-#include "../../gol.h"
+#include "gol.h"
+#include "compatibility.h"
#include "display_msagent.xpm"
#define REQUEST_TIMEOUT (5)
-#ifdef _WIN32
-# ifndef strncasecmp
-# define strncasecmp(d,s,n) strnicmp(d,s,n)
-# endif
-#endif
-
BSTR
utf8_to_bstr(const char* str) {
DWORD size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
View
26 gol.c
@@ -51,29 +51,7 @@
#include <openssl/des.h>
#include "gol.h"
-
-#ifdef _WIN32
-typedef char sockopt_t;
-typedef int socklen_t;
-# ifndef snprintf
-# define snprintf _snprintf
-# endif
-# ifndef strncasecmp
-# define strncasecmp(d,s,n) strnicmp(d,s,n)
-# endif
-# ifndef srandom
-# define srandom(s) srand(s)
-# endif
-# ifndef random
-# define random() rand()
-# endif
-#else
-# define closesocket(x) close(x)
-typedef int sockopt_t;
-# ifndef SD_BOTH
-# define SD_BOTH SHUT_RDWR
-# endif
-#endif
+#include "compatibility.h"
#define GNTP_OK_STRING_LITERAL(_version, _action) \
"GNTP/" _version " -OK NONE\r\n" \
@@ -495,7 +473,7 @@ set_as_default_clicked(GtkWidget* GOL_UNUSED_ARG(widget), gpointer user_data) {
}
static gboolean
-parameter_focus_out(GtkWidget* widget, GdkEvent* event, gpointer user_data) {
+parameter_focus_out(GtkWidget* GOL_UNUSED_ARG(widget), GdkEvent* GOL_UNUSED_ARG(event), gpointer user_data) {
GtkTreeSelection* selection = (GtkTreeSelection*) user_data;
gchar* name;
if (!get_tree_model_from_selection(&name, selection)) return FALSE;
View
@@ -12,22 +12,10 @@
#include <curl/curl.h>
+#include "compatibility.h"
#include "memfile.h"
#include "from_url.h"
-#ifdef _WIN32
-# ifndef strncasecmp
-# define strncasecmp(d,s,n) strnicmp(d,s,n)
-# endif
-static char*
-strndup(const char* src, size_t n) {
- char* ptr = (char*) malloc(n + 1);
- *(ptr + n) = 0;
- memcpy(ptr, src, n);
- return ptr;
-}
-#endif
-
#define REQUEST_TIMEOUT (5)
CURLcode
View
@@ -2,18 +2,9 @@
#include <stdlib.h>
#include <string.h>
+#include "compatibility.h"
#include "memfile.h"
-#ifdef _WIN32
-static char*
-strndup(const char* src, size_t n) {
- char* ptr = (char*) malloc(n + 1);
- *(ptr + n) = 0;
- memcpy(ptr, src, n);
- return ptr;
-}
-#endif
-
MEMFILE*
memfopen() {
return (MEMFILE*) calloc(1, sizeof(MEMFILE));

0 comments on commit 81ec2f0

Please sign in to comment.