Skip to content

Commit

Permalink
make glob() for Windows compile and work
Browse files Browse the repository at this point in the history
  • Loading branch information
joergsteffens committed Apr 7, 2016
1 parent 0767a0e commit 796290a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 21 deletions.
24 changes: 24 additions & 0 deletions LICENSE
Expand Up @@ -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.
Expand Down
47 changes: 46 additions & 1 deletion debian/copyright
Expand Up @@ -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'.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 <zkrapavickas@gmail.com>
Expand Down
21 changes: 21 additions & 0 deletions debian/copyright.footer
Expand Up @@ -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 <zkrapavickas@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion debian/copyright.header
Expand Up @@ -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'.
Expand Down
45 changes: 30 additions & 15 deletions src/win32/compat/glob.c
Expand Up @@ -30,6 +30,7 @@
* Copyright (C) 2011-2013, MinGW.org Project.
* ---------------------------------------------------------------------------
*/
#include "bareos.h"
#include <glob.h>
#include <ctype.h>
#include <stdlib.h>
Expand All @@ -39,6 +40,14 @@
#include <dirent.h>
#include <errno.h>

#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
Expand All @@ -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__
/*
Expand All @@ -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
Expand Down Expand Up @@ -520,7 +530,8 @@ static int glob_strcmp( const char *pattern, const char *text, int flags )
# include <sys/stat.h>

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 )
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...
*/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/win32/compat/include/glob.h
Expand Up @@ -123,7 +123,7 @@ enum {
*/
#define GLOB_CASEMATCH __GLOB_FLAG__(CASEMATCH)

BEGIN_C_DECLS
//BEGIN_C_DECLS
/*
* Function prototypes. Formally POSIX mandates:
*
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/win32/lib/Makefile
Expand Up @@ -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)
Expand Down

0 comments on commit 796290a

Please sign in to comment.