* $Id$
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2011-2014, MinGW.org Project.
+ * Copyright (C) 2011-2014, 2017, MinGW.org Project.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
return ++p;
}
+GLOB_INLINE int glob_case_match( int flags, int check, int match )
+{
+ /* Local helper function, used to facilitate the case insensitive
+ * glob character matching appropriate for MS-Windows systems.
+ */
+ return (flags & GLOB_CASEMATCH) ? check - match
+ : tolower( check ) - tolower( match );
+}
+
static const char *glob_in_set( const char *set, int test, int flags )
{
/* Check if the single character "test" is present in the set
/* ...in incremental collating sequence order, to the next
* character following the '-'...
*/
- if( lastc++ == test )
+ if( glob_case_match( flags, lastc++, test ) == 0 )
/*
* ...returning immediately on a successful match...
*/
* range may have been specified in decrementing collating
* sequence order...
*/
- if( lastc-- == test )
+ if( glob_case_match( flags, lastc--, test ) == 0 )
/*
* ...once again, return immediately on a successful match.
*/
*/
return NULL;
- if( c == test )
+ if( glob_case_match( flags, c, test ) == 0 )
/*
* We found the test character within the set; adjust the pattern
* reference, to resume after the end of the set, and return the
return NULL;
}
-GLOB_INLINE int glob_case_match( int flags, int check, int match )
-{
- /* Local helper function, used to facilitate the case insensitive
- * glob character matching appropriate for MS-Windows systems.
- */
- return (flags & GLOB_CASEMATCH) ? check - match
- : tolower( check ) - tolower( match );
-}
-
static int glob_strcmp( const char *pattern, const char *text, int flags )
{
/* Compare "text" to a specified globbing "pattern" using semantics
/* Module entry point for the glob() function.
*/
int status;
+
/* First, consult the glob "registry", to ensure that the
* glob data structure passed by the caller, has been properly
- * initialised.
+ * initialised. (Note that this implementation gratuitously uses
+ * gl_data->gl_offs, irrespective of specification of GLOB_DOOFFS
+ * in the flags; while the user must accept responsibility for the
+ * initialisation of gl_data->gl_offs when specifying GLOB_DOOFFS,
+ * this is not the case when GLOB_DOOFFS is not specified; in the
+ * latter case, WE must assume the responsibility, ensuring that
+ * the required zero value is assigned BEFORE registration).
+ */
+ if( (gl_data != NULL) && ((flags & GLOB_DOOFFS) == 0) )
+ gl_data->gl_offs = 0;
+
+ /* With this pre-registration requirement satisfied, we may now
+ * proceed to register the provided gl_data structure.
*/
gl_data = glob_registry( GLOB_INIT, gl_data );