5
5
#include "../strbuf.h"
6
6
#include "../run-command.h"
7
7
#include "../cache.h"
8
+ #include "../string-list.h"
8
9
9
10
static const int delay [] = { 0 , 1 , 10 , 20 , 40 };
10
11
unsigned int _CRT_fmode = _O_BINARY ;
@@ -405,12 +406,60 @@ int mingw_fgetc(FILE *stream)
405
406
return ch ;
406
407
}
407
408
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
+
408
453
#undef fopen
409
454
FILE * mingw_fopen (const char * filename , const char * otype )
410
455
{
411
456
int hide = 0 ;
412
457
FILE * file ;
413
458
wchar_t wfilename [MAX_PATH ], wotype [4 ];
459
+
460
+ if (is_dos_device_name (filename ))
461
+ return fopen (filename , otype );
462
+
414
463
if (hide_dotfiles == HIDE_DOTFILES_TRUE &&
415
464
basename ((char * )filename )[0 ] == '.' )
416
465
hide = access (filename , F_OK );
@@ -425,11 +474,16 @@ FILE *mingw_fopen (const char *filename, const char *otype)
425
474
return file ;
426
475
}
427
476
477
+ #undef freopen
428
478
FILE * mingw_freopen (const char * filename , const char * otype , FILE * stream )
429
479
{
430
480
int hide = 0 ;
431
481
FILE * file ;
432
482
wchar_t wfilename [MAX_PATH ], wotype [4 ];
483
+
484
+ if (is_dos_device_name (filename ))
485
+ return freopen (filename , otype , stream );
486
+
433
487
if (hide_dotfiles == HIDE_DOTFILES_TRUE &&
434
488
basename ((char * )filename )[0 ] == '.' )
435
489
hide = access (filename , F_OK );
0 commit comments