1 /* 2 * Globbing for NT. Relies on the expansion done by the library 3 * startup code (provided by Visual C++ by linking in setargv.obj). 4 */ 5 6 /* Enable wildcard expansion for gcc's C-runtime library if not enabled by 7 * default (currently necessary with the automated build of the mingw-w64 8 * cross-compiler, but there's no harm in making sure for others too). */ 9 #ifdef __MINGW32__ 10 #include <_mingw.h> 11 #if defined(__MINGW64_VERSION_MAJOR) && defined(__MINGW64_VERSION_MINOR) 12 // MinGW-w64 13 int _dowildcard = -1; 14 #else 15 // MinGW 16 int _CRT_glob = -1; 17 #endif 18 #endif 19 20 #include <stdio.h> 21 #include <io.h> 22 #include <fcntl.h> 23 #include <assert.h> 24 #include <limits.h> 25 #include <string.h> 26 #include <windows.h> 27 28 int 29 main(int argc, char *argv[]) 30 { 31 int i; 32 size_t len; 33 char root[MAX_PATH]; 34 char *dummy; 35 char volname[MAX_PATH]; 36 DWORD serial, maxname, flags; 37 BOOL downcase = TRUE; 38 int fd; 39 40 /* check out the file system characteristics */ 41 if (GetFullPathName(".", MAX_PATH, root, &dummy)) { 42 dummy = strchr(root,'\\'); 43 if (dummy) 44 *++dummy = '\0'; 45 if (GetVolumeInformation(root, volname, MAX_PATH, 46 &serial, &maxname, &flags, 0, 0)) { 47 downcase = !(flags & FS_CASE_IS_PRESERVED); 48 } 49 } 50 51 fd = fileno(stdout); 52 /* rare VC linker bug causes uninit global FILE *s 53 fileno() implementation in VC 2003 is 2 blind pointer derefs so it will 54 never return -1 error as POSIX says, to be compliant fail for -1 and 55 for absurdly high FDs which are actually pointers */ 56 assert(fd >= 0 && fd < SHRT_MAX); 57 setmode(fd, O_BINARY); 58 for (i = 1; i < argc; i++) { 59 len = strlen(argv[i]); 60 if (downcase) 61 strlwr(argv[i]); 62 if (i > 1) fwrite("\0", sizeof(char), 1, stdout); 63 fwrite(argv[i], sizeof(char), len, stdout); 64 } 65 return 0; 66 } 67 68