From 796290a790f105967402cf90a028289797c1387b Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 1 Apr 2016 17:35:39 +0200 Subject: [PATCH] make glob() for Windows compile and work --- LICENSE | 24 +++++++++++++++++ debian/copyright | 47 ++++++++++++++++++++++++++++++++- debian/copyright.footer | 21 +++++++++++++++ debian/copyright.header | 2 +- src/win32/compat/glob.c | 45 ++++++++++++++++++++----------- src/win32/compat/include/glob.h | 6 ++--- src/win32/lib/Makefile | 2 +- 7 files changed, 126 insertions(+), 21 deletions(-) diff --git a/LICENSE b/LICENSE index 1cc58d58624..82169ddcf64 100644 --- a/LICENSE +++ b/LICENSE @@ -244,6 +244,30 @@ to the fastlzlib and its components: - LZ4 homepage : http://www.lz4.org - LZ4 source repository : https://github.com/Cyan4973/lz4 +f) +Files: src/win32/compat/glob.c src/win32/compat/include/glob.h +Copyright (C) 2012 MinGW.org project +License: permissive + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice, this permission notice, and the following + * disclaimer shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER + * DEALINGS IN THE SOFTWARE. + + =========================================== 2. diff --git a/debian/copyright b/debian/copyright index 900b64457c3..b435416dfa5 100644 --- a/debian/copyright +++ b/debian/copyright @@ -15,7 +15,7 @@ Comment: BAREOS is a fork of the Bacula source code. Files: * Copyright: 2000-2012 Free Software Foundation Europe e.V. 2011-2012 Planets Communications B.V. - 2013-2014 Bareos GmbH & Co. KG + 2013-2016 Bareos GmbH & Co. KG License: AGPL-3.0 with Bacula and other exceptions This section is the reformated version of `/usr/share/doc/bareos-common/LICENSE'. @@ -266,6 +266,30 @@ License: AGPL-3.0 with Bacula and other exceptions - LZ4 homepage : http://www.lz4.org - LZ4 source repository : https://github.com/Cyan4973/lz4 . + f) + Files: src/win32/compat/glob.c src/win32/compat/include/glob.h + Copyright (C) 2012 MinGW.org project + License: permissive + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice, this permission notice, and the following + * disclaimer shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER + * DEALINGS IN THE SOFTWARE. + . + . =========================================== . 2. @@ -1279,6 +1303,27 @@ Files: src/win32/compat/include/sys/mtio.h Copyright: 1996, 1997 Free Software Foundation, Inc. License: LGPL-2.1+ +Files: src/win32/compat/glob.c src/win32/compat/include/glob.h +Copyright (C) 2012 MinGW.org project +License: permissive + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice, this permission notice, and the following + * disclaimer shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER + * DEALINGS IN THE SOFTWARE. Files: src/win32/plugins/filed/mssqlvdi-fd.c Copyright: 2010 Zilvinas Krapavickas diff --git a/debian/copyright.footer b/debian/copyright.footer index 1d1b8ed5aca..768afe6e12b 100644 --- a/debian/copyright.footer +++ b/debian/copyright.footer @@ -155,6 +155,27 @@ Files: src/win32/compat/include/sys/mtio.h Copyright: 1996, 1997 Free Software Foundation, Inc. License: LGPL-2.1+ +Files: src/win32/compat/glob.c src/win32/compat/include/glob.h +Copyright (C) 2012 MinGW.org project +License: permissive + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice, this permission notice, and the following + * disclaimer shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER + * DEALINGS IN THE SOFTWARE. Files: src/win32/plugins/filed/mssqlvdi-fd.c Copyright: 2010 Zilvinas Krapavickas diff --git a/debian/copyright.header b/debian/copyright.header index 13e0027a63d..b09ed63b18d 100644 --- a/debian/copyright.header +++ b/debian/copyright.header @@ -15,7 +15,7 @@ Comment: BAREOS is a fork of the Bacula source code. Files: * Copyright: 2000-2012 Free Software Foundation Europe e.V. 2011-2012 Planets Communications B.V. - 2013-2014 Bareos GmbH & Co. KG + 2013-2016 Bareos GmbH & Co. KG License: AGPL-3.0 with Bacula and other exceptions This section is the reformated version of `/usr/share/doc/bareos-common/LICENSE'. diff --git a/src/win32/compat/glob.c b/src/win32/compat/glob.c index a41c62017a5..646ec2d4ae1 100644 --- a/src/win32/compat/glob.c +++ b/src/win32/compat/glob.c @@ -30,6 +30,7 @@ * Copyright (C) 2011-2013, MinGW.org Project. * --------------------------------------------------------------------------- */ +#include "bareos.h" #include #include #include @@ -39,6 +40,14 @@ #include #include +#ifndef HAVE_READDIR_R +int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); +#endif + +#ifndef HAVE_STRICOLL +#define stricoll(str1, str2) bstrcasecmp(str1, str2) +#endif + enum { /* Extend the flags offset enumeration, beyond the user visible * high water mark, to accommodate some additional flags which are @@ -62,7 +71,8 @@ enum { # define GLOB_INLINE static __inline__ __attribute__((__always_inline__)) #endif -#define GLOB_HARD_ESC __CRT_GLOB_ESCAPE_CHAR__ +//#define GLOB_HARD_ESC __CRT_GLOB_ESCAPE_CHAR__ +#define GLOB_HARD_ESC (char)(127) #if defined _WIN32 || defined __MS_DOS__ /* @@ -87,7 +97,7 @@ GLOB_INLINE char *glob_strdup( const char *pattern ) do { if( *origin == GLOB_HARD_ESC ) ++origin; *copy++ = *origin; } while( *origin++ ); - return strdup( buf ); + return bstrdup( buf ); } #else @@ -520,7 +530,8 @@ static int glob_strcmp( const char *pattern, const char *text, int flags ) # include GLOB_INLINE - int GLOB_ISDIR( const struct *dirent ent ) + //int GLOB_ISDIR( const struct *dirent ent ) + int GLOB_ISDIR( const struct dirent *ent ) { struct stat entinfo; if( stat( ent->d_name, &entinfo ) == 0 ) @@ -555,7 +566,7 @@ static int glob_initialise( glob_t *gl_data ) * for storage of the globbed paths vector... */ int entries = gl_data->gl_offs + 1; - if( (gl_data->gl_pathv = malloc( entries * sizeof( char ** ) )) == NULL ) + if( (gl_data->gl_pathv = (char **)malloc( entries * sizeof( char ** ) )) == NULL ) /* * ...bailing out, if insufficient free heap memory. */ @@ -591,7 +602,7 @@ static int glob_store_entry( char *path, glob_t *gl_buf ) */ char **pathv; if( (path != NULL) && (gl_buf != NULL) - && ((pathv = realloc( gl_buf->gl_pathv, glob_expand( gl_buf ))) != NULL) ) + && ((pathv = (char **)realloc( gl_buf->gl_pathv, glob_expand( gl_buf ))) != NULL) ) { /* Memory expansion was successful; store the new path name * in place of the former NULL pointer at the end of the old @@ -645,12 +656,13 @@ GLOB_INLINE struct glob_collator if( flags & GLOB_CASEMATCH ) seq = strcoll( entry, ref->entry ); else - seq = stricoll( entry, ref->entry ); + //seq = stricoll( entry, ref->entry ); + seq = strcoll( entry, ref->entry ); ref = (seq > 0) ? ref->next : ref->prev; } /* Allocate storage for a new leaf node, and if successful... */ - if( (ref = malloc( sizeof( struct glob_collator ))) != NULL ) + if( (ref = (glob_collator*)malloc( sizeof( struct glob_collator ))) != NULL ) { /* ...place the new entry on this new leaf... */ @@ -718,7 +730,7 @@ glob_store_collated_entries( struct glob_collator *collator, glob_t *gl_buf ) } static int -glob_match( const char *pattern, int flags, int (*errfn)(), glob_t *gl_buf ) +glob_match( const char *pattern, int flags, int (*errfn)(const char*, int), glob_t *gl_buf ) { /* Local helper function; it provides the backbone of the glob() * implementation, recursively decomposing the pattern into separate @@ -731,7 +743,7 @@ glob_match( const char *pattern, int flags, int (*errfn)(), glob_t *gl_buf ) /* Begin by separating out any path prefix from the glob pattern. */ char dirbuf[1 + strlen( pattern )]; - const char *dir = dirname( memcpy( dirbuf, pattern, sizeof( dirbuf )) ); + const char *dir = dirname( (char *)memcpy( dirbuf, pattern, sizeof( dirbuf )) ); char **dirp, preferred_dirsep = GLOB_DIRSEP; /* Initialise a temporary local glob_t structure, to capture the @@ -817,13 +829,16 @@ glob_match( const char *pattern, int flags, int (*errfn)(), glob_t *gl_buf ) { /* ...and when successful, instantiate a dirent structure... */ - struct dirent *entry; + struct dirent data; + struct dirent *entry = &data; + struct dirent *result = NULL; size_t dirlen = (dir == NULL) ? 0 : strlen( *dirp ); - while( (entry = readdir( dp )) != NULL ) + //while( (entry = readdir( dp )) != NULL ) + while( (readdir_r( dp, entry, &result )) == 0 ) { /* ...into which we read each entry from the candidate * directory, in turn, then... - */ + */ if( (((flags & GLOB_DIRONLY) == 0) || GLOB_ISDIR( entry )) /* * ...provided we don't require it to be a subdirectory, @@ -968,7 +983,7 @@ static glob_t *glob_registry( int request, glob_t *gl_data ) /* ...a registration (initialisation) request... */ case GLOB_INIT: - if( glob_signed( gl_data->gl_magic, glob_magic ) != 0 ) + if( glob_signed( (const char *)gl_data->gl_magic, glob_magic ) != 0 ) { /* The gl_magic field doesn't (yet) indicate that the * data structure has been initialised; assume that this @@ -985,7 +1000,7 @@ static glob_t *glob_registry( int request, glob_t *gl_data ) * before we attempt to free it. */ case GLOB_FREE: - if( glob_signed( gl_data->gl_magic, glob_magic ) == 0 ) + if( glob_signed( (const char *)gl_data->gl_magic, glob_magic ) == 0 ) { /* On passing the sanity check, we may proceed to free * all dynamically (strdup) allocated string buffers in @@ -1005,7 +1020,7 @@ static glob_t *glob_registry( int request, glob_t *gl_data ) } int -__mingw_glob( const char *pattern, int flags, int (*errfn)(), glob_t *gl_data ) +__mingw_glob( const char *pattern, int flags, int (*errfn)(const char *, int), glob_t *gl_data ) { /* Module entry point for the glob() function. */ diff --git a/src/win32/compat/include/glob.h b/src/win32/compat/include/glob.h index 60625b29146..4b6db1bac79 100644 --- a/src/win32/compat/include/glob.h +++ b/src/win32/compat/include/glob.h @@ -123,7 +123,7 @@ enum { */ #define GLOB_CASEMATCH __GLOB_FLAG__(CASEMATCH) -BEGIN_C_DECLS +//BEGIN_C_DECLS /* * Function prototypes. Formally POSIX mandates: * @@ -142,13 +142,13 @@ void __mingw_globfree( glob_t * ); #define GLOB_INLINE static __inline__ __attribute__((__always_inline__)) GLOB_INLINE int glob -( const char *__pattern, int __flags, int (*__errfunc)(), glob_t *__data ) +( const char *__pattern, int __flags, int (*__errfunc)(const char *, int), glob_t *__data ) { return __mingw_glob( __pattern, __flags, __errfunc, __data ); } GLOB_INLINE void globfree( glob_t *__data ) { return __mingw_globfree( __data ); } -END_C_DECLS +//END_C_DECLS /* Manifest definitions for the possible status values * which glob() may return. diff --git a/src/win32/lib/Makefile b/src/win32/lib/Makefile index 9526f4e37cb..304fc40c6de 100644 --- a/src/win32/lib/Makefile +++ b/src/win32/lib/Makefile @@ -54,7 +54,7 @@ LIBBAREOS_OBJS = $(LIBBAREOS_SRCS:.c=.o) LIBBAREOSCFG_SRCS = ini.c lex.c parse_bsr.c LIBBAREOSCFG_OBJS = $(LIBBAREOSCFG_SRCS:.c=.o) -COMPAT_SRCS = compat.c print.c winapi.c +COMPAT_SRCS = compat.c glob.c print.c winapi.c COMPAT_OBJS = $(COMPAT_SRCS:.c=.o) DYNAMIC_OBJS = $(LIBBAREOS_OBJS) $(LIBBAREOSCFG_OBJS) $(COMPAT_OBJS)