This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
New perldelta for 5.37.8
[perl5.git] / win32 / perlglob.c
CommitLineData
0a753a76 1/*
2 * Globbing for NT. Relies on the expansion done by the library
8f550399 3 * startup code (provided by Visual C++ by linking in setargv.obj).
0a753a76 4 */
5
8f550399
SH
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
0a753a76 20#include <stdio.h>
21#include <io.h>
22#include <fcntl.h>
34667d08
DD
23#include <assert.h>
24#include <limits.h>
0a753a76 25#include <string.h>
26#include <windows.h>
27
28int
29main(int argc, char *argv[])
30{
31 int i;
c623ac67 32 size_t len;
0a753a76 33 char root[MAX_PATH];
34 char *dummy;
35 char volname[MAX_PATH];
36 DWORD serial, maxname, flags;
37 BOOL downcase = TRUE;
34667d08 38 int fd;
0a753a76 39
40 /* check out the file system characteristics */
0a753a76 41 if (GetFullPathName(".", MAX_PATH, root, &dummy)) {
161b471a 42 dummy = strchr(root,'\\');
1604cfb0
MS
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 }
0a753a76 49 }
50
34667d08
DD
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);
0a753a76 58 for (i = 1; i < argc; i++) {
1604cfb0
MS
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);
0a753a76 64 }
65 return 0;
66}
161b471a 67