File: perlglob.c

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (67 lines) | stat: -rw-r--r-- 1,919 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Globbing for NT.  Relies on the expansion done by the library
 * startup code (provided by Visual C++ by linking in setargv.obj).
 */

/* Enable wildcard expansion for gcc's C-runtime library if not enabled by
 * default (currently necessary with the automated build of the mingw-w64
 * cross-compiler, but there's no harm in making sure for others too). */
#ifdef __MINGW32__
#include <_mingw.h>
#if defined(__MINGW64_VERSION_MAJOR) && defined(__MINGW64_VERSION_MINOR)
    // MinGW-w64
    int _dowildcard = -1;
#else
    // MinGW
    int _CRT_glob = -1;
#endif
#endif

#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <assert.h>
#include <limits.h>
#include <string.h>
#include <windows.h>

int
main(int argc, char *argv[])
{
    int i;
    size_t len;
    char root[MAX_PATH];
    char *dummy;
    char volname[MAX_PATH];
    DWORD serial, maxname, flags;
    BOOL downcase = TRUE;
    int fd;

    /* check out the file system characteristics */
    if (GetFullPathName(".", MAX_PATH, root, &dummy)) {
        dummy = strchr(root,'\\'); 
        if (dummy)
            *++dummy = '\0';
        if (GetVolumeInformation(root, volname, MAX_PATH, 
                                 &serial, &maxname, &flags, 0, 0)) {
            downcase = !(flags & FS_CASE_IS_PRESERVED);
        }
    }

    fd = fileno(stdout);
    /* rare VC linker bug causes uninit global FILE *s
       fileno() implementation in VC 2003 is 2 blind pointer derefs so it will
       never return -1 error as POSIX says, to be compliant fail for -1 and
       for absurdly high FDs which are actually pointers */
    assert(fd >= 0 && fd < SHRT_MAX);
    setmode(fd, O_BINARY);
    for (i = 1; i < argc; i++) {
        len = strlen(argv[i]);
        if (downcase)
            strlwr(argv[i]);
        if (i > 1) fwrite("\0", sizeof(char), 1, stdout);
        fwrite(argv[i], sizeof(char), len, stdout);
    }
    return 0;
}