Fix build and warnings on win32
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 2 Jan 2013 23:35:56 +0000 (17:35 -0600)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 2 Jan 2013 23:35:56 +0000 (17:35 -0600)
src/Makefile.am
src/fcatomic.h
src/fccache.c
src/fccfg.c
src/fcint.h
src/fcmutex.h
src/fcstat.c
src/fcstr.c
src/fcwindows.h [new file with mode: 0644]
src/fcxml.c

index da1358c..c32c6f3 100644 (file)
@@ -148,6 +148,7 @@ libfontconfig_la_SOURCES = \
        fcserialize.c \
        fcstat.c \
        fcstr.c \
+       fcwindows.h \
        fcxml.c \
        ftglue.h \
        ftglue.c
index 71c0491..073809e 100644 (file)
@@ -3,9 +3,7 @@
  *
  * Copyright © 2007  Chris Wilson
  * Copyright © 2009,2010  Red Hat, Inc.
- * Copyright © 2011,2012  Google, Inc.
- *
- *  This is part of HarfBuzz, a text shaping library.
+ * Copyright © 2011,2012,2013  Google, Inc.
  *
  * Permission is hereby granted, without written agreement and without
  * license or royalty fees, to use, copy, modify, and distribute this
@@ -48,8 +46,7 @@
 
 #elif !defined(FC_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__)
 
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include "fcwindows.h"
 
 /* mingw32 does not have MemoryBarrier.
  * MemoryBarrier may be defined as a macro or a function.
@@ -63,7 +60,7 @@ static inline void HBMemoryBarrier (void) {
 }
 #endif
 
-typedef int fc_atomic_int_t;
+typedef LONG fc_atomic_int_t;
 #define fc_atomic_int_add(AI, V)       InterlockedExchangeAdd (&(AI), (V))
 
 #define fc_atomic_ptr_get(P)           (HBMemoryBarrier (), (void *) *(P))
index 2f0f5d7..2f1104f 100644 (file)
@@ -77,7 +77,7 @@ FcCacheIsMmapSafe (int fd)
            status =  use ? MMAP_USE : MMAP_DONT_USE;
        else
            status = MMAP_CHECK_FS;
-       fc_atomic_ptr_cmpexch (&static_status, NULL, (void *) status);
+       (void) fc_atomic_ptr_cmpexch (&static_status, NULL, (void *) status);
     }
 
     if (status == MMAP_CHECK_FS)
index bc408db..877a4f5 100644 (file)
 #include <dirent.h>
 #include <sys/types.h>
 
-#if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
-#define STRICT
-#include <windows.h>
-#undef STRICT
-#endif
-
 #if defined (_WIN32) && !defined (R_OK)
 #define R_OK 4
 #endif
@@ -270,7 +264,7 @@ FcConfigDestroy (FcConfig *config)
     if (FcRefDec (&config->ref) != 1)
        return;
 
-    fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
+    (void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
 
     FcStrSetDestroy (config->configDirs);
     FcStrSetDestroy (config->fontDirs);
@@ -1737,10 +1731,6 @@ FcConfigSubstitute (FcConfig     *config,
 
 #if defined (_WIN32)
 
-#  define WIN32_LEAN_AND_MEAN
-#  define WIN32_EXTRA_LEAN
-#  include <windows.h>
-
 static FcChar8 fontconfig_path[1000] = ""; /* MT-dontcare */
 
 #  if (defined (PIC) || defined (DLL_EXPORT))
@@ -1748,6 +1738,11 @@ static FcChar8 fontconfig_path[1000] = ""; /* MT-dontcare */
 BOOL WINAPI
 DllMain (HINSTANCE hinstDLL,
         DWORD     fdwReason,
+        LPVOID    lpvReserved);
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+        DWORD     fdwReason,
         LPVOID    lpvReserved)
 {
   FcChar8 *p;
index 9520be3..38bd9bb 100644 (file)
 #endif
 
 #ifdef _WIN32
-#  ifndef _WIN32_WINNT
-#    define _WIN32_WINNT 0x0500
-#  endif
-#  define WIN32_LEAN_AND_MEAN
-#  define STRICT
-#  include <windows.h>
+#  include "fcwindows.h"
 typedef UINT (WINAPI *pfnGetSystemWindowsDirectory)(LPSTR, UINT);
 typedef HRESULT (WINAPI *pfnSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
 extern pfnGetSystemWindowsDirectory pGetSystemWindowsDirectory;
index b10572c..556a05e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright © 2007  Chris Wilson
  * Copyright © 2009,2010  Red Hat, Inc.
- * Copyright © 2011,2012  Google, Inc.
+ * Copyright © 2011,2012,2013  Google, Inc.
  *
  * Permission is hereby granted, without written agreement and without
  * license or royalty fees, to use, copy, modify, and distribute this
@@ -48,8 +48,7 @@
 
 #elif !defined(FC_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__)
 
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include "fcwindows.h"
 typedef CRITICAL_SECTION fc_mutex_impl_t;
 #define FC_MUTEX_IMPL_INIT     { NULL, 0, 0, NULL, NULL, 0 }
 #define fc_mutex_impl_init(M)  InitializeCriticalSection (M)
index d1730fd..9763c21 100644 (file)
@@ -44,9 +44,6 @@
 #endif
 
 #ifdef _WIN32
-
-#include <windows.h>
-
 #ifdef __GNUC__
 typedef long long INT64;
 #define EPOCH_OFFSET 11644473600ll
index 34093a0..cdab383 100644 (file)
@@ -29,9 +29,6 @@
 #ifdef HAVE_REGEX_H
 #include <regex.h>
 #endif
-#ifdef _WIN32
-#include <windows.h>
-#endif
 
 /* Objects MT-safe for readonly access. */
 
diff --git a/src/fcwindows.h b/src/fcwindows.h
new file mode 100644 (file)
index 0000000..02489d9
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * fontconfig/src/fcwindows.h
+ *
+ * Copyright © 2013  Google, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the author(s) not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  The authors make no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#ifndef _FCWINDOWS_H_
+#define _FCWINDOWS_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef _WIN32
+#  ifndef _WIN32_WINNT
+#    define _WIN32_WINNT 0x0500
+#  endif
+#  define WIN32_LEAN_AND_MEAN
+#  define WIN32_EXTRA_LEAN
+#  define STRICT
+#  include <windows.h>
+#endif
+
+#endif /* _FCWINDOWS_H_ */
index 1f068ce..b234e43 100644 (file)
@@ -1419,7 +1419,7 @@ static void
 FcParseRange (FcConfigParse *parse)
 {
     FcVStack   *vstack;
-    FcRange    r;
+    FcRange    r = {0, 0};
     FcChar32   n;
     int                count = 1;
 
@@ -1961,7 +1961,7 @@ FcParseDir (FcConfigParse *parse)
 #ifdef _WIN32
     if (strcmp ((const char *) data, "CUSTOMFONTDIR") == 0)
     {
-       char *p;
+       FcChar8 *p;
        data = buffer;
        if (!GetModuleFileName (NULL, (LPCH) buffer, sizeof (buffer) - 20))
        {
@@ -1976,11 +1976,11 @@ FcParseDir (FcConfigParse *parse)
         */
        p = _mbsrchr (data, '\\');
        if (p) *p = '\0';
-       strcat (data, "\\fonts");
+       strcat ((char *) data, "\\fonts");
     }
     else if (strcmp ((const char *) data, "APPSHAREFONTDIR") == 0)
     {
-       char *p;
+       FcChar8 *p;
        data = buffer;
        if (!GetModuleFileName (NULL, (LPCH) buffer, sizeof (buffer) - 20))
        {
@@ -1989,7 +1989,7 @@ FcParseDir (FcConfigParse *parse)
        }
        p = _mbsrchr (data, '\\');
        if (p) *p = '\0';
-       strcat (data, "\\..\\share\\fonts");
+       strcat ((char *) data, "\\..\\share\\fonts");
     }
     else if (strcmp ((const char *) data, "WINDOWSFONTDIR") == 0)
     {
@@ -2002,8 +2002,8 @@ FcParseDir (FcConfigParse *parse)
            goto bail;
        }
        if (data [strlen ((const char *) data) - 1] != '\\')
-           strcat (data, "\\");
-       strcat (data, "fonts");
+           strcat ((char *) data, "\\");
+       strcat ((char *) data, "fonts");
     }
 #endif
     if (strlen ((char *) data) == 0)
@@ -2072,8 +2072,8 @@ FcParseCacheDir (FcConfigParse *parse)
            goto bail;
        }
        if (data [strlen ((const char *) data) - 1] != '\\')
-           strcat (data, "\\");
-       strcat (data, "fontconfig\\cache");
+           strcat ((char *) data, "\\");
+       strcat ((char *) data, "fontconfig\\cache");
     }
     else if (strcmp ((const char *) data, "LOCAL_APPDATA_FONTCONFIG_CACHE") == 0)
     {