Movatterモバイル変換


[0]ホーム

URL:


Skip to content

C/C++

Expanding wildcard arguments

For making your program accept wildcard arguments, the official MSVC way is tolink [w]setargv.obj to your program. By default it is not enabled. For moredetails seehttps://learn.microsoft.com/en-us/cpp/c-language/expanding-wildcard-arguments

Note that enabling wildcard expansion can have usability and securityimplications:

  • The program might transform the arguments you passed in, depending on the current directory, leading to user confusion.
  • The program might leak information about the existence and names of files on the filesystem.
  • Input validation might be bypassed if wildcard expansions is not taken into account.

With mingw-w64, there are three ways wildcard expansion can be configured:

  1. You can set_dowildcard in your source code to either0 or-1 to disable or enable wildcard expansion.

    // To force-enable wildcard expansionint_dowildcard=-1;// To force-disable wildcard expansionint_dowildcard=0;
  2. You can link inCRT_noglob.o orCRT_glob.o to disable or enable wildcard expansion, respectively. This will error out if_dowildcard is already set in the source.

    # To force-enable wildcard expansionccmain.c"$(cc-print-file-name=CRT_glob.o)"# To force-disable wildcard expansionccmain.c"$(cc-print-file-name=CRT_noglob.o)"
  3. mingw-w64 can be configured at build time to either enable or disable wildcard expansion by default via the--enable-wildcard configure flags. This can to be overridden on a per .exe basis by the user.

    Wildcard expansion is disabled by default in MSYS2.

Changelog

  • Starting with 2024-11-03 we have changed mingw-w64 to to disable wildcardhandling by default. You can still enable it on a per application basis asdescribed above. For more info on the change seethe newsentry.

[8]ページ先頭

©2009-2025 Movatter.jp