From c483d06ee33be8a2112116c3156411d98ee717fc Mon Sep 17 00:00:00 2001 From: Andrej Kacian Date: Thu, 18 Jun 2015 23:58:51 +0200 Subject: [PATCH] Various small fix ups needed for mingw-w64 build. --- src/common/Makefile.am | 2 +- src/common/w32_dirent.c | 100 ---------------------------------------- src/common/w32_stdio.c | 2 + src/common/w32_stdlib.c | 2 + src/common/w32_string.c | 3 +- src/common/w32_time.c | 2 + src/common/w32lib.h | 33 ++++++++----- src/ldaputil.h | 3 ++ 8 files changed, 33 insertions(+), 114 deletions(-) delete mode 100644 src/common/w32_dirent.c diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 796fae30a..161922652 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -10,7 +10,7 @@ noinst_LTLIBRARIES = libclawscommon.la if OS_WIN32 arch_sources = fnmatch.c \ - w32_dirent.c w32_reg.c w32_signal.c w32_stat.c \ + w32_reg.c w32_signal.c w32_stat.c \ w32_stdio.c w32_stdlib.c w32_string.c w32_time.c \ w32_unistd.c w32_wait.c w32_account.c arch_headers = fnmatch.h w32lib.h diff --git a/src/common/w32_dirent.c b/src/common/w32_dirent.c deleted file mode 100644 index 91539dc82..000000000 --- a/src/common/w32_dirent.c +++ /dev/null @@ -1,100 +0,0 @@ -/* w32_dirent.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib 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 3 of the License, or - * (at your option) any later version. - * - * w32lib 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 program. If not, see . - * - * For more information and a list of changes, see w32lib.h - */ - - -#include -#include -#include -#include - -#include "w32lib.h" - - - -DIR * -opendir ( const char *name ) -{ - DIR *dir; - - dir = calloc (1, sizeof *dir + strlen (name)); - if (!dir) - return NULL; - strcpy (dir->dd_name, name); - return dir; -} - -int -closedir (DIR *dir) -{ - FindClose( (HANDLE)dir->dd_handle ); - free( dir ); - return 0; -} - -struct dirent * -readdir( DIR *dir ) -{ - WIN32_FIND_DATA fInfo; - struct dirent *xdirent; - int ret; - - if ( !dir->dd_handle ) - { - char *dirname; - - if (*dir->dd_name) - { - size_t n = strlen (dir->dd_name); - dirname = malloc (n + 4 + 1); - if (dirname) { - strcpy (dirname, dir->dd_name); - strcpy (dirname + n, "\\*.*"); - } - } - else - dirname = strdup( "\\*.*" ); - if (!dirname) - return NULL; /* Error. */ - - dir->dd_handle = (long)FindFirstFile( dirname, &fInfo ); - free( dirname ); - if ( !dir->dd_handle ) - ret = 0; - else - ret = 1; - } - else if ( dir->dd_handle != -1l ) - { - ret = FindNextFile ((HANDLE)dir->dd_handle, &fInfo); - } - else - ret = 0; - if ( !ret ) - return NULL; - - xdirent = calloc ( 1, sizeof *xdirent); - if (xdirent) - { - strncpy (xdirent->d_name, fInfo.cFileName, FILENAME_MAX -1 ); - xdirent->d_name[FILENAME_MAX-1] = 0; - xdirent->d_namlen = strlen( xdirent->d_name ); - } - return xdirent; -} diff --git a/src/common/w32_stdio.c b/src/common/w32_stdio.c index 50b51c0f7..af6a3ed2c 100644 --- a/src/common/w32_stdio.c +++ b/src/common/w32_stdio.c @@ -23,9 +23,11 @@ #include "w32lib.h" +#if MINGW64_VERSION < 200 FILE *popen( const char *command, const char *type ){ return NULL; } +#endif int pclose( FILE *stream ){ return -1; diff --git a/src/common/w32_stdlib.c b/src/common/w32_stdlib.c index 3aba8f910..a55a17efe 100644 --- a/src/common/w32_stdlib.c +++ b/src/common/w32_stdlib.c @@ -31,6 +31,8 @@ void srandom( unsigned int seed ){ srand( seed ); } +#if MINGW64_VERSION < 200 int truncate( const char *path, off_t length ){ return -1; } +#endif diff --git a/src/common/w32_string.c b/src/common/w32_string.c index 8bc0a1d82..6c238e3b9 100644 --- a/src/common/w32_string.c +++ b/src/common/w32_string.c @@ -24,6 +24,7 @@ #include "w32lib.h" +#if MINGW64_VERSION < 200 int strcasecmp( const char *s1, const char *s2 ){ size_t len1, len2, len; @@ -49,4 +50,4 @@ int strncasecmp( const char *s1, const char *s2, size_t n ){ return 0; } - +#endif /* MINGW64_VERSION < 200 */ diff --git a/src/common/w32_time.c b/src/common/w32_time.c index c7bb43ff7..ef7df8f9c 100644 --- a/src/common/w32_time.c +++ b/src/common/w32_time.c @@ -25,6 +25,7 @@ #include "w32lib.h" #if ! defined (__MINGW32__) || MINGW32_VERSION < 312 +# if MINGW64_VERSION < 200 int gettimeofday( struct timeval *tv, struct timezone *tz ){ struct _timeb tstruct; _ftime( &tstruct ); @@ -32,4 +33,5 @@ int gettimeofday( struct timeval *tv, struct timezone *tz ){ tv->tv_usec = tstruct.millitm; return 1; } +# endif #endif diff --git a/src/common/w32lib.h b/src/common/w32lib.h index fb7b9239e..cfa8e5339 100644 --- a/src/common/w32lib.h +++ b/src/common/w32lib.h @@ -76,13 +76,18 @@ #include #ifdef __MINGW32__ -#include <_mingw.h> -#define MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 100 \ +# include <_mingw.h> +# define MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 100 \ + __MINGW32_MINOR_VERSION) -#include -#include -#include -#endif +# define MINGW64_VERSION (__MINGW64_VERSION_MAJOR * 100 \ + + __MINGW64_VERSION_MINOR) +# include +# include +# include +# if MINGW64_VERSION >= 200 +# include +# endif +#endif /* __MINGW32__ */ #include @@ -125,9 +130,10 @@ typedef unsigned int uid_t; /* functions */ /*** str ***/ +#if MINGW64_VERSION < 200 int strcasecmp( const char *s1, const char *s2 ); - int strncasecmp( const char *s1, const char *s2, size_t n ); +#endif /*** dir ***/ #ifndef __MINGW32__ @@ -163,16 +169,13 @@ typedef struct #endif /* !__MINGW32__ */ - -DIR *opendir( const char *name ); -int closedir( DIR *dir ); -struct dirent *readdir( DIR *dir ); - #if defined (__MINGW32__) && MINGW32_VERSION < 312 +# if MINGW64_VERSION < 200 struct timezone { int tz_minuteswest; int tz_dsttime; }; +# endif #endif /*** stat ***/ @@ -183,7 +186,9 @@ pid_t waitpid( pid_t pid, int *status, int options ); /*** sys/time ***/ #if ! defined (__MINGW32__) || MINGW32_VERSION < 312 +# if MINGW64_VERSION < 200 int gettimeofday( struct timeval *tv, struct timezone *tz ); +# endif #endif /*** unistd ***/ @@ -195,14 +200,18 @@ unsigned int sleep( unsigned int seconds ); /*** stdlib ***/ long int random( void ); void srandom( unsigned int seed ); +#if MINGW64_VERSION < 200 int truncate( const char *path, off_t length ); +#endif /*** signal ***/ int kill( pid_t pid, int sig ); /*** stdio ***/ +#if MINGW64_VERSION < 200 FILE *popen( const char *command, const char *type ); int pclose( FILE *stream ); +#endif /*** w32_account.c ***/ int w32_is_administrator (void); diff --git a/src/ldaputil.h b/src/ldaputil.h index b9eded57e..0c711ca65 100644 --- a/src/ldaputil.h +++ b/src/ldaputil.h @@ -37,6 +37,9 @@ #define ldap_unbind_ext(ld,x,y) ldap_unbind_s(ld) #define LDAP_ADMINLIMIT_EXCEEDED LDAP_ADMIN_LIMIT_EXCEEDED #define timeval l_timeval +#ifndef LDAP_OPT_SUCCESS +# define LDAP_OPT_SUCCESS 0 +#endif #endif /* Function Prototypes */ GList *ldaputil_read_basedn ( const gchar *host, const gint port, -- 2.25.1