Fix binutils tools so that they can cope with the special /dev/null file when run on Windows systems.

PR 27252
 * bucomm.c (get_file_size): Add code to handle /dev/null on
 Windows systems.
 * elfedit.c (check_file): Likewise.
This commit is contained in:
Eli Zaretskii
2021-01-28 13:32:05 +00:00
committed by Nick Clifton
parent 0318cca493
commit a7ad3cb1ff
3 changed files with 36 additions and 0 deletions

View File

@ -721,6 +721,20 @@ check_file (const char *file_name, struct stat *statbuf_p)
return 1;
}
#if defined (_WIN32) && !defined (__CYGWIN__)
else if (statbuf_p->st_size == 0)
{
/* MS-Windows 'stat' doesn't reports the null device as a
regular file; fix that. */
int fd = open (file_name, O_RDONLY | O_BINARY);
if (isatty (fd))
{
statbuf_p->st_mode &= ~S_IFREG;
statbuf_p->st_mode |= S_IFCHR;
}
}
#endif
if (! S_ISREG (statbuf_p->st_mode))
{
error (_("'%s' is not an ordinary file\n"), file_name);