[Mingw-users] Shell is stripping curly braces in Git for Windows

Back to archive index

Keith Marshall keith****@users*****
Mon Apr 16 01:19:17 JST 2018


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 15/04/18 16:23, Eli Zaretskii wrote:
>> From: Keith Marshall <keith****@users*****> Date: Sat, 14 Apr 2018
>> 19:42:54 +0100
>> 
>>> Moreover, if I invoke a MinGW program with this argument, it 
>>> receives the literal @{-1} as well in its argv[] array.
>> 
>> ... while that may be true when brace expansion has not been 
>> enabled, (by default, it is not), I do see two bugs in mingwrt's 
>> implementation of glob(3), when the feature is enabled:
>> 
>> $ cmd Microsoft Windows XP [Version 5.1.2600] (C) Copyright
>> 1985-2001 Microsoft Corp.
>> 
>> C:\mingw\msys\1.0\home\keith> showargv @{-1} command: showargv
>> @{-1} argv[00]: showargv argv[01]: @-1
> 
> I tried to reproduce this behavior, but couldn't.  Eventually, I
> came to the conclusion that I don't understand what you meant by
> "feature is enabled".  AFAIK, the default for MinGW is to use MinGW
> globbing (as opposed to the one provided by MSVCRT.DLL), and that
> invokes 'glob' under the hood, no?

Yes.

> Can you tell what exactly does showargv does to "enable the
> feature"?

Sure.  The clues are in the setargv.c code:
https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.1-trunk/mingwrt/setargv.c

and the default CRTglob.c initialization code:
https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.1-trunk/mingwrt/CRTglob.c

The trick is to override the default initialization of _CRT_glob:

  int _CRT_glob = __CRT_GLOB_USE_MINGW__;

I've posted my showargv.c code before, but to save you searching the
old SF archives, it's attached again.  I compile it thus:

  $ mingw32-gcc -O2 -D CRT_GLOB_OPTIONS=0x4432 showargv.c \
      -o showargv.exe

which, you will note, provides an initialization override equivalent to:

  int _CRT_glob = __CRT_GLOB_USE_MINGW__
       | __CRT_GLOB_USE_SINGLE_QUOTE__
       | __CRT_GLOB_BRACKET_GROUPS__
       | GLOB_CASEMATCH
       | GLOB_BRACE
       ;

Thus, the GLOB_BRACE feature becomes enabled, when the MinGW runtime
start-up code calls __mingw_glob() on behalf of showargv.exe

- -- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQIcBAEBAgAGBQJa03uFAAoJEMCtNsY0flo/0ZoP/2OiW4FlVrv0WI5n7F+2HhB+
WhVaiIoiOAnhvE9Fulo/jiGIz0QgMRTjsyLrZ5imktan7CBnpuKFm7+x5gQtv+lo
k3acG/OrrR93dTWrb67nSz2RkDz3jZhUg+vQlMtvOYxo5d+9fmzDXKwG0lGs8w1f
S6VpohEbser6tIUO0um5EdbUmncjYFM4UUWRcKgjIkp2SiRBh5roOnLfc4CIrm0L
Aq3AVRWsBMgQVHr7UjBqmLxRvWf/vFlbICZuCvJSxW9C2h6qLfvTEj6Ucjgb7BBI
NLWcgsDNVHve4FMZ1R4x9D8cACz9G9MgHi7abdEzGOC5rnedaBVdY4capaxnRrxu
E9ozrkmRnBk412vlVNGdm69uwoziREHIHdzQTu1+90dS50+vNvI3kLt0UOoxU6F2
bxk3+wIrNRjfKURbTkzb2sRgoTAU4pKNs720jbc2SrBY88p5qsZDFqrgqAZZ22e8
CRaN1/kvdvlmqR3tCRU43t25R8fksz48J2SpT5osvyKoFkTzo2DONZLHPS+ewL9N
wkJy3jtVOf7fueB9VMimvW7KvfZOijjfsrYc8o3na775xWRd4Lmb1DMqbuUOxTdb
24+Irw0SCt9mR0UwdhDr/WGV0UgV/xH2c8K/6yWiMhsnEXkJKFVzwJXbIh2ufnPC
LPFjqtbMmrlgoPXZnGkU
=zETv
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: showargv.c
Type: text/x-csrc
Size: 337 bytes
Desc: not available
Url : https://lists.osdn.me/mailman/archives/mingw-users/attachments/20180415/43b9ba5a/attachment.c 



More information about the MinGW-Users mailing list
Back to archive index