diff -ur mingwrt-3.22.4/include/ctype.h mingwrt-3.22.4-1/include/ctype.h --- mingwrt-3.22.4/include/ctype.h 2016-08-26 06:32:00 +1000 +++ mingwrt-3.22.4-1/include/ctype.h 2017-01-10 22:08:41 +1000 @@ -42,17 +42,21 @@ * properly declared here, this file should also declare elements of the * wide classification API, which is properly declared in * - * To avoid the burden of maintaining duplicate declarations, in two + * To avoid the burden of maintaining duplicate declarations in two * locations, we keep the wide character declarations where ISO-C and * POSIX say they belong, in , while accommodating Microsoft * compatibility by providing for selective inclusion of the relevant * elements of it here. (Note that we must do this early, because to * avoid duplication, we delegate the definition of common character * classification macros, with the exception of _LEADBYTE, which is - * not required in both headers, to ). + * not required in both headers, to ; we use the quoted + * form of inclusion here, to ensure that we get our own "wctype.h", + * and not any predecessor which may have been insinuated into the + * system include path, and which may interfere with our mechanism + * for partial inclusion of shared header content). */ #define __CTYPE_H_SOURCED__ -#include +#include "wctype.h" /* This is the one character classification macro, for which definition * is NOT delegated to diff -ur mingwrt-3.22.4/include/glob.h mingwrt-3.22.4-1/include/glob.h --- mingwrt-3.22.4/include/glob.h 2016-08-26 06:32:00 +1000 +++ mingwrt-3.22.4-1/include/glob.h 2017-01-05 09:33:49 +1000 @@ -94,10 +94,7 @@ * but to better support the MS-Windows * file system, the MinGW implementation * of glob() performs a CASE INSENSITIVE - * character match by default, (except - * when matching within character group - * patterns, which are ALWAYS assumed to - * require CASE SENSITIVE matching). + * character match by default. */ __GLOB_CASEMATCH_OFFSET, /* diff -ur mingwrt-3.22.4/include/string.h mingwrt-3.22.4-1/include/string.h --- mingwrt-3.22.4/include/string.h 2016-10-14 23:21:59 +1000 +++ mingwrt-3.22.4-1/include/string.h 2017-01-10 22:08:41 +1000 @@ -160,9 +160,13 @@ * scope, will selectively expose the required function prototypes; * however, strictly ISO-C conforming applications should include * directly; they should not rely on this MSVC specific - * anomalous behaviour. + * anomalous behaviour. (We use the quoted form of inclusion here, + * to ensure that we get our own "wchar.h", and not any predecessor + * which may have been insinuated into the system include path, and + * so could interfere with our mechanism for partial inclusion of + * shared header content). */ -#include +#include "wchar.h" #endif /* ! __STRICT_ANSI__ */ diff -ur mingwrt-3.22.4/include/time.h mingwrt-3.22.4-1/include/time.h --- mingwrt-3.22.4/include/time.h 2016-10-18 03:56:03 +1000 +++ mingwrt-3.22.4-1/include/time.h 2016-10-18 03:56:03 +1000 @@ -42,7 +42,7 @@ */ #undef __need_time_h #define __need_time_t 1 -#include +#include "sys/types.h" #ifndef _TIME_H /* To support selective partial inclusion, we do not immediately define diff -ur mingwrt-3.22.4/mingwex/dirent.c mingwrt-3.22.4-1/mingwex/dirent.c --- mingwrt-3.22.4/mingwex/dirent.c 2016-08-26 06:32:00 +1000 +++ mingwrt-3.22.4-1/mingwex/dirent.c 2017-01-09 16:37:37 +1000 @@ -1,24 +1,46 @@ /* * dirent.c * - * This file has no copyright assigned and is placed in the Public Domain. + * $Id$ + * + * Provides emulation of POSIX "directory stream" manipulation functions, + * in terms of the MS-Windows FindFile API. * - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. * * Derived from DIRLIB.C by Matt J. Weinstein - * This note appears in the DIRLIB.H + * This note appears in the associated DIRLIB.H header file: * DIRLIB.H by M. J. Weinstein Released to public domain 1-Jan-89 * * Updated by Jeremy Bettis * Significantly revised and rewinddir, seekdir and telldir added * by Colin Peters + * * Further significantly revised for improved memory utilisation, * efficiency in operation, and better POSIX standards compliance * by Keith Marshall + * Copyright (C) 1997, 2001-2006, 2014, 2017, MinGW.org Project + * + * + * 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. * */ -#include #include #include #include @@ -28,23 +50,6 @@ #include #include -#ifdef _UNICODE - /* In a Unicode build, the path name within the _wdirent struct is - * represented by a wchar_t string; we use the snwprintf() function - * to simultaneously assign the d_name and d_namlen fields, copying - * from a temporary WIN32_FIND_DATA struct on the stack... - */ -# include -# define DIRENT_ASSIGN_NAME snwprintf - -#else - /* ...while for a non-Unicode build, the corresponding data within - * the dirent structure is represented by a normal char string, and - * the assignments are made by the snprintf() function. - */ -# define DIRENT_ASSIGN_NAME snprintf -#endif - /* This implementation applies a "__mingw_" pseudo-namespace prefix to * the standard POSIX function names, for each each function it defines; * the following pair of macros facilitates this. @@ -150,16 +155,33 @@ */ #define DT_VALID_BITS ~(DT_IGNORED | 0x0080) +/* For convenience, we identify the NUL "character" which terminates any + * file or directory name, appropriately typed, using this macro: + */ +#define NUL ((_TCHAR)(0)) + static void dirent_update( struct _tdirent *dd, WIN32_FIND_DATA *fd ) { /* Helper function, used by dirent_findfirst() and dirent_findnext(), * to transfer all relevant data from their respective WIN32_FIND_DATA - * buffers to the specified dirent structure. + * buffers to the specified dirent structure; in the case of the d_name + * field, we want the effect of a snprintf() string transfer, but to + * avoid the (perceptually significant) overhead of format parsing, + * we simulate it with an inline character-by-character counted + * string copy loop... + */ + _TCHAR *d_name = dd->d_name; + for( dd->d_namlen = 0; (*d_name = fd->cFileName[dd->d_namlen]) != NUL; ) + /* + * ...continuing to count input characters, until the terminal NUL, + * but declining to store any character beyond the physical end of + * the d_name field buffer. + */ + if( ++dd->d_namlen < FILENAME_MAX ) ++d_name; + + /* Store only those file attribute bits which are valid for d_type. */ - dd->d_namlen = DIRENT_ASSIGN_NAME( dd->d_name, FILENAME_MAX, - _T("%s"), fd->cFileName - ); if( (dd->d_type = fd->dwFileAttributes & DT_VALID_BITS) > DT_DIR ) dd->d_type = DT_UNKNOWN; } diff -ur mingwrt-3.22.4/mingwex/glob.c mingwrt-3.22.4-1/mingwex/glob.c --- mingwrt-3.22.4/mingwex/glob.c 2016-08-26 06:32:00 +1000 +++ mingwrt-3.22.4-1/mingwex/glob.c 2017-01-04 17:47:35 +1000 @@ -227,6 +227,15 @@ 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 @@ -283,7 +292,7 @@ /* ...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... */ @@ -295,7 +304,7 @@ * 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. */ @@ -316,7 +325,7 @@ */ 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 @@ -337,15 +346,6 @@ 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 diff -ur mingwrt-3.22.4/setargv.c mingwrt-3.22.4-1/setargv.c --- mingwrt-3.22.4/setargv.c 2016-08-26 06:32:00 +1000 +++ mingwrt-3.22.4-1/setargv.c 2017-01-04 17:51:53 +1000 @@ -35,11 +35,12 @@ */ #include #include -#include #define WIN32_LEAN_AND_MEAN #include +#define ISSPACE(a) (a == ' ' || a == '\t') + /* Access to a standard 'main'-like argument count and list. */ extern int _argc; @@ -121,12 +122,17 @@ * need special handling. */ case '\\': - /* We don't (yet) know if this is a literal backslash, - * (directory separator), or an escape for a following - * quote character; just note its presence, until we - * have looked far enough ahead to decide. - */ - ++bslash; + if( quoted == '\'' ) + /* Backslashes within single quotes are always literal. + */ + *argptr++ = '\\'; + else + /* We don't (yet) know if this is a literal backslash, + * (directory separator), or an escape for a following + * quote character; just note its presence, until we + * have looked far enough ahead to decide. + */ + ++bslash; break; case '[': @@ -181,7 +187,7 @@ * literally, after flushing out any pending backslashes. */ argptr = backslash( bslash, argptr ); - if( (quoted == 0) && isspace( c ) ) + if( (quoted == 0) && ISSPACE( c ) ) { /* The one exception is any white space character, * when it is not contained within quotes; this acts