Fix case when file does not exist

This commit is contained in:
Miodrag Milanovic 2019-07-29 12:29:13 +02:00
parent 6538671c84
commit 3e4307c104
1 changed files with 21 additions and 19 deletions

View File

@ -456,25 +456,27 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
delete ff; delete ff;
else else
f = ff; f = ff;
// Check for gzip magic if (f != NULL) {
unsigned char magic[3]; // Check for gzip magic
int n = readsome(*ff, reinterpret_cast<char*>(magic), 3); unsigned char magic[3];
if (n == 3 && magic[0] == 0x1f && magic[1] == 0x8b) { int n = readsome(*ff, reinterpret_cast<char*>(magic), 3);
#ifdef YOSYS_ENABLE_ZLIB if (n == 3 && magic[0] == 0x1f && magic[1] == 0x8b) {
log("Found gzip magic in file `%s', decompressing using zlib.\n", filename.c_str()); #ifdef YOSYS_ENABLE_ZLIB
if (magic[2] != 8) log("Found gzip magic in file `%s', decompressing using zlib.\n", filename.c_str());
log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n", if (magic[2] != 8)
filename.c_str(), unsigned(magic[2])); log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n",
delete ff; filename.c_str(), unsigned(magic[2]));
std::stringstream *df = new std::stringstream(); delete ff;
decompress_gzip(filename, *df); std::stringstream *df = new std::stringstream();
f = df; decompress_gzip(filename, *df);
#else f = df;
log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str()); #else
#endif log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
} else { #endif
ff->clear(); } else {
ff->seekg(0, std::ios::beg); ff->clear();
ff->seekg(0, std::ios::beg);
}
} }
} }
if (f == NULL) if (f == NULL)