Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b08b38a

Browse files
committed
Merge pull request #111 from msysgit/fix-https-prompt
Do not use _wfopen() for DOS device filenames
2 parents bac2422 + 90d18ca commit b08b38a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

compat/mingw.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../strbuf.h"
66
#include "../run-command.h"
77
#include "../cache.h"
8+
#include "../string-list.h"
89

910
static const int delay[] = { 0, 1, 10, 20, 40 };
1011
unsigned int _CRT_fmode = _O_BINARY;
@@ -405,12 +406,60 @@ int mingw_fgetc(FILE *stream)
405406
return ch;
406407
}
407408

409+
static struct string_list_item dos_device_names_items[] = {
410+
{ "AUX", NULL},
411+
{ "CLOCK$", NULL},
412+
{ "COM1", NULL},
413+
{ "COM2", NULL},
414+
{ "COM3", NULL},
415+
{ "COM4", NULL},
416+
{ "CON", NULL},
417+
{ "CONERR$", NULL},
418+
{ "CONIN$", NULL},
419+
{ "CONOUT$", NULL},
420+
{ "LPT1", NULL},
421+
{ "LPT2", NULL},
422+
{ "LPT3", NULL},
423+
{ "NUL", NULL},
424+
{ "PRN", NULL},
425+
{ "aux", NULL},
426+
{ "clock$", NULL},
427+
{ "com1", NULL},
428+
{ "com2", NULL},
429+
{ "com3", NULL},
430+
{ "com4", NULL},
431+
{ "con", NULL},
432+
{ "conerr$", NULL},
433+
{ "conin$", NULL},
434+
{ "conout$", NULL},
435+
{ "lpt1", NULL},
436+
{ "lpt2", NULL},
437+
{ "lpt3", NULL},
438+
{ "nul", NULL},
439+
{ "prn", NULL}
440+
};
441+
442+
static struct string_list dos_device_names = {
443+
&dos_device_names_items[0], ARRAY_SIZE(dos_device_names_items),
444+
0, 0, NULL
445+
};
446+
447+
static int is_dos_device_name(const char *filename)
448+
{
449+
return filename && !strchr(filename, '/') &&
450+
string_list_has_string(&dos_device_names, filename);
451+
}
452+
408453
#undef fopen
409454
FILE *mingw_fopen (const char *filename, const char *otype)
410455
{
411456
int hide = 0;
412457
FILE *file;
413458
wchar_t wfilename[MAX_PATH], wotype[4];
459+
460+
if (is_dos_device_name(filename))
461+
return fopen(filename, otype);
462+
414463
if (hide_dotfiles == HIDE_DOTFILES_TRUE &&
415464
basename((char*)filename)[0] == '.')
416465
hide = access(filename, F_OK);
@@ -425,11 +474,16 @@ FILE *mingw_fopen (const char *filename, const char *otype)
425474
return file;
426475
}
427476

477+
#undef freopen
428478
FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
429479
{
430480
int hide = 0;
431481
FILE *file;
432482
wchar_t wfilename[MAX_PATH], wotype[4];
483+
484+
if (is_dos_device_name(filename))
485+
return freopen(filename, otype, stream);
486+
433487
if (hide_dotfiles == HIDE_DOTFILES_TRUE &&
434488
basename((char*)filename)[0] == '.')
435489
hide = access(filename, F_OK);

0 commit comments

Comments
 (0)