Make read/write gzip files on macos works, fixes #1357

This commit is contained in:
Miodrag Milanovic 2019-09-26 19:35:12 +02:00
parent a009314597
commit 435300f930
1 changed files with 11 additions and 3 deletions

View File

@ -48,7 +48,7 @@ using zlib to write gzip-compressed data every time the stream is flushed.
*/ */
class gzip_ostream : public std::ostream { class gzip_ostream : public std::ostream {
public: public:
gzip_ostream() gzip_ostream() : std::ostream(nullptr)
{ {
rdbuf(&outbuf); rdbuf(&outbuf);
} }
@ -71,7 +71,7 @@ private:
str(""); str("");
return 0; return 0;
} }
~gzip_streambuf() virtual ~gzip_streambuf()
{ {
sync(); sync();
gzclose(gzf); gzclose(gzf);
@ -498,7 +498,15 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
if (f != NULL) { if (f != NULL) {
// Check for gzip magic // Check for gzip magic
unsigned char magic[3]; unsigned char magic[3];
int n = readsome(*ff, reinterpret_cast<char*>(magic), 3); int n = 0;
while (n < 3)
{
int c = ff->get();
if (c != EOF) {
magic[n] = (unsigned char) c;
}
n++;
}
if (n == 3 && magic[0] == 0x1f && magic[1] == 0x8b) { if (n == 3 && magic[0] == 0x1f && magic[1] == 0x8b) {
#ifdef YOSYS_ENABLE_ZLIB #ifdef YOSYS_ENABLE_ZLIB
log("Found gzip magic in file `%s', decompressing using zlib.\n", filename.c_str()); log("Found gzip magic in file `%s', decompressing using zlib.\n", filename.c_str());