[easytag/wip/mingw: 3/10] Check for [f]truncate and gethostbyname



commit c7efdf7f8b5173f9668ef7ec1dc779f70f84d1fc
Author: David King <amigadave amigadave com>
Date:   Tue Jan 15 21:51:58 2013 +0000

    Check for [f]truncate and gethostbyname
    
    Check for ftruncate and truncate during configure, and use wrappers on
    Windows. Check for gethostbyname so that the Winsock library (ws2_32) is
    added to LIBS on Windows.

 configure.ac         |   12 ++++++++++-
 src/win32/win32dep.c |   51 +++++++++++++++++++++++++++++++++++++++----------
 src/win32/win32dep.h |   30 ++++++++++++++++++++++++----
 3 files changed, 76 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d4bc5b3..571e90e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -229,6 +229,16 @@ dnl Check the pkg-config dependencies
 GIO_DEPS="gio-2.0 >= 2.32.0" dnl For g_file_new_tmp()
 PKG_CHECK_MODULES([EASYTAG], [$GIO_DEPS $GTK_DEPS $OGG_DEPS $SPEEX_DEPS $FLAC_DEPS $ID3TAG_DEPS $TAGLIB_DEPS $WAVPACK_DEPS])
 
+dnl Check for winsock
+AC_SEARCH_LIBS([gethostbyname], [nsl socket], [],
+    [saved_LIBS=$LIBS
+     LIBS="-lws2_32 $LIBS"
+     AC_MSG_CHECKING([for gethostbyname in ws2_32])
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <winsock2.h>]],
+        [[gethostbyname ("");]])],
+        [have_ws2=yes], [have_ws2=no LIBS=$saved_LIBS])
+     AC_MSG_RESULT([$have_ws2])])
+
 dnl Check that the compiler accepts the given warning flags.
 warning_flags="-Wall -Wstrict-prototypes -Wnested-externs -Werror=missing-prototypes -Werror=implicit-function-declaration -Werror=pointer-arith -Werror=init-self -Werror=format-security -Werror=format=2 -Werror=missing-include-dirs"
 
@@ -273,7 +283,7 @@ dnl -------------------------------
 dnl Checks for library functions.
 dnl -------------------------------
 AC_FUNC_FORK
-AC_CHECK_FUNCS(mkdir strstr strtol mkstemp)
+AC_CHECK_FUNCS([ftruncate gettimeofday mkdir mkstemp strstr strtol truncate])
 AC_SEARCH_LIBS([strerror], [cposix])
 
 
diff --git a/src/win32/win32dep.c b/src/win32/win32dep.c
index 41e2d34..ed62c3c 100644
--- a/src/win32/win32dep.c
+++ b/src/win32/win32dep.c
@@ -60,13 +60,6 @@
 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR);
 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
 
-// Defined also in "#include <shlobj.h>"
-typedef enum
-{
-    SHGFP_TYPE_CURRENT  = 0,   // current value for user, verify it exists
-    SHGFP_TYPE_DEFAULT  = 1,   // default value, may not exist
-} SHGFP_TYPE;
-
 /*
  * LOCALS
  */
@@ -75,6 +68,10 @@ static char *app_data_dir = NULL, *install_dir = NULL,
 
 static HINSTANCE libeasytagdll_hInstance = 0;
 
+/* Prototypes. */
+gboolean weasytag_read_reg_dword (HKEY rootkey, const char *subkey,
+                                  const char *valname, LPDWORD result);
+void str_replace_char (gchar *str, gchar in_char, gchar out_char);
 
 
 /*
@@ -463,7 +460,6 @@ char *weasytag_read_reg_string(HKEY rootkey, const char *subkey, const char *val
 void weasytag_init(void) {
     WORD wVersionRequested;
     WSADATA wsaData;
-	char *newenv;
 
     //Log_Print(_("weasytag_init start..."));
     g_print(_("weasytag_init start..."));
@@ -520,7 +516,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
 
 
 /* this is used by libmp4v2 : what is it doing here you think ? well...search! */
-int gettimeofday (struct timeval *t, void *foo)
+gint
+gettimeofday (struct timeval *t, void *foo)
 {
     struct _timeb temp;
 
@@ -534,7 +531,8 @@ int gettimeofday (struct timeval *t, void *foo)
 
 
 /* emulate the unix function */
-int mkstemp (char *template)
+gint
+et_w32_mkstemp (gchar *template)
 {
     int fd = -1;
 
@@ -547,7 +545,8 @@ int mkstemp (char *template)
     return fd;
 }
 
-void str_replace_char (gchar *str, gchar in_char, gchar out_char)
+void
+str_replace_char (gchar *str, gchar in_char, gchar out_char)
 {
     while(*str)
     {
@@ -617,4 +616,34 @@ char*  ET_Win32_Get_Audio_File_Player (void)
     return player;
 }
 
+gint
+et_w32_truncate (const gchar *path, off_t length)
+{
+    HANDLE h;
+    gint ret;
+
+    h = CreateFile (path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* errno = map_errno (GetLastError ()); */
+        return -1;
+    }
+
+    ret = chsize (h, length);
+    CloseHandle (h);
 
+    return ret;
+}
+
+gint
+et_w32_ftruncate (gint fd, off_t length)
+{
+    HANDLE h;
+
+    h = (HANDLE)_get_osfhandle (fd);
+
+    if (h == (HANDLE) - 1) return -1;
+
+    return chsize (h, length);
+}
diff --git a/src/win32/win32dep.h b/src/win32/win32dep.h
index 5a12ba3..88c9a11 100644
--- a/src/win32/win32dep.h
+++ b/src/win32/win32dep.h
@@ -27,7 +27,9 @@
 #include <winsock2.h>
 #include <process.h>
 #include <gtk/gtk.h>
-#include <gdk/gdkevents.h>
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
 
 #define lstat stat
 #define mkdir(a,b) mkdir(a)
@@ -35,8 +37,6 @@
 #define chmod(a,b)
 
 
-
-
 /*
  *  PROTOS
  */
@@ -69,7 +69,26 @@ extern void  ET_Win32_Path_Remove_Trailing_Backslash (gchar *path);
 extern void  ET_Win32_Path_Replace_Backslashes       (gchar *path);
 extern void  ET_Win32_Path_Replace_Slashes           (gchar *path);
 
-extern int   mkstemp (char *template);
+#ifndef HAVE_MKSTEMP
+#define et_w32_mkstemp mkstemp
+extern gint et_w32_mkstemp (char *template);
+#endif /* HAVE_MKSTEMP */
+
+#ifndef HAVE_GETTIMEOFDAY
+#define et_w32_gettimeofday gettimeofday
+extern gint et_w32_gettimeofday (struct timeval *tv,
+                                 /*struct timezone */ void *tz);
+#endif /* !HAVE_GETTIMEOFDAY */
+
+#ifndef HAVE_FTRUNCATE
+#define et_w32_ftruncate ftruncate
+extern gint et_w32_ftruncate (gint fd, off_t length);
+#endif /* !HAVE_FTRUNCATE */
+
+#ifndef HAVE_TRUNCATE
+#define et_w32_truncate truncate
+extern gint et_w32_truncate (const gchar *path, off_t length);
+#endif /* !HAVE_TRUNCATE */
 
 /*
  *  MACROS
@@ -82,5 +101,6 @@ extern int   mkstemp (char *template);
 #define LIBDIR    weasytag_lib_dir()
 #define LOCALEDIR weasytag_locale_dir()
 
-#endif /* _WIN32DEP_H_ */
+G_END_DECLS
 
+#endif /* _WIN32DEP_H_ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]