summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch2/Util.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-09-08 13:11:12 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-09-08 13:11:12 +0000
commit933e0b5f00f709ddeca12b2a5e7db22d540cdbe5 (patch)
tree27debf48976c944d380ac143c23b8e5b3d3b81d6 /cpp/src/IcePatch2/Util.cpp
parentadding memory pool to test configuration (diff)
downloadice-933e0b5f00f709ddeca12b2a5e7db22d540cdbe5.tar.bz2
ice-933e0b5f00f709ddeca12b2a5e7db22d540cdbe5.tar.xz
ice-933e0b5f00f709ddeca12b2a5e7db22d540cdbe5.zip
Fixed compress/decompress for Borland
Diffstat (limited to 'cpp/src/IcePatch2/Util.cpp')
-rw-r--r--cpp/src/IcePatch2/Util.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp
index 6959ab8d8d2..d429f3d3768 100644
--- a/cpp/src/IcePatch2/Util.cpp
+++ b/cpp/src/IcePatch2/Util.cpp
@@ -757,6 +757,54 @@ IcePatch2::decompressFile(const string& pa)
throw "cannot open `" + pathBZ2 + "' for reading:\n" + lastError();
}
+#ifdef __BCPLUSPLUS__
+ //
+ // The BZ2_bzReadOpen/BZ2_bzRead/BZ2_bzReadClose functions fail with BCC
+ //
+ OS::structstat buf;
+ if(OS::osstat(pathBZ2, &buf) == -1)
+ {
+ throw "cannot stat `" + pathBZ2 + "':\n" + lastError();
+ }
+
+ ByteSeq compressedBytes(buf.st_size);
+ if(fread(&compressedBytes[0], buf.st_size, 1, stdioFileBZ2) == -1)
+ {
+ throw "cannot read from `" + pathBZ2 + "':\n" + lastError();
+ }
+
+ ByteSeq uncompressedBytes;
+ unsigned int uncompressedLen = buf.st_size * 2;
+ while(true)
+ {
+ uncompressedBytes.resize(uncompressedLen);
+ int bzError = BZ2_bzBuffToBuffDecompress(&uncompressedBytes[0], &uncompressedLen, &compressedBytes[0],
+ buf.st_size, 0, 0);
+ if(bzError == BZ_OK)
+ {
+ break;
+ }
+ else if(bzError == BZ_OUTBUFF_FULL)
+ {
+ uncompressedLen *= 2;
+ continue;
+ }
+ else
+ {
+ string ex = "BZ2_bzBuffToBuffDecompress failed";
+ if(bzError == BZ_IO_ERROR)
+ {
+ ex += string(": ") + lastError();
+ }
+ throw ex;
+ }
+ }
+
+ if(fwrite(&uncompressedBytes[0], uncompressedLen, 1, fp) != 1)
+ {
+ throw "cannot write to `" + path + "':\n" + lastError();
+ }
+#else
bzFile = BZ2_bzReadOpen(&bzError, stdioFileBZ2, 0, 0, 0, 0);
if(bzError != BZ_OK)
{
@@ -810,6 +858,7 @@ IcePatch2::decompressFile(const string& pa)
}
throw ex;
}
+#endif
}
catch(...)
{
@@ -902,6 +951,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
}
else
{
+
OS::structstat buf;
if(OS::osstat(path, &buf) == -1)
{
@@ -983,6 +1033,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
}
ByteSeq bytesSHA(20);
+
if(relPath.size() + buf.st_size == 0)
{
fill(bytesSHA.begin(), bytesSHA.end(), 0);
@@ -998,12 +1049,64 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
if(buf.st_size != 0)
{
+#ifdef __BCPLUSPLUS__
+ //
+ // The BZ2_bzWriteOpen/BZ2_bzWrite/BZ2_bzWriteClose functions fail with BCC
+ //
+ if(doCompress)
+ {
+ int fd = OS::open(path.c_str(), O_BINARY|O_RDONLY);
+ if(fd == -1)
+ {
+ throw "cannot open `" + path + "' for reading:\n" + lastError();
+ }
+
+ ByteSeq uncompressedBytes(buf.st_size);
+
+ if(read(fd, &uncompressedBytes[0], buf.st_size) == -1)
+ {
+ close(fd);
+ throw "cannot read from `" + path + "':\n" + lastError();
+ }
+
+ unsigned int compressedLen = buf.st_size * 1.01 + 600;
+ ByteSeq compressedBytes(compressedLen);
+
+ int bzError = BZ2_bzBuffToBuffCompress(&compressedBytes[0], &compressedLen,
+ &uncompressedBytes[0], buf.st_size, 5, 0, 0);
+ if(bzError != BZ_OK)
+ {
+ string ex = "BZ2_bzBuffToBuffCompress failed";
+ if(bzError == BZ_IO_ERROR)
+ {
+ ex += string(": ") + lastError();
+ }
+ close(fd);
+ throw ex;
+ }
+ close(fd);
+
+ const string pathBZ2Temp = path + ".bz2temp";
+ FILE* stdioFile = OS::fopen(pathBZ2Temp, "wb");
+ if(fwrite(&compressedBytes[0], compressedLen, 1, stdioFile) != 1)
+ {
+ fclose(stdioFile);
+ throw "cannot write to `" + pathBZ2Temp + "':\n" + lastError();
+ }
+ fclose(stdioFile);
+
+ rename(pathBZ2Temp, pathBZ2);
+
+ }
+#endif
+
int fd = OS::open(path.c_str(), O_BINARY|O_RDONLY);
if(fd == -1)
{
throw "cannot open `" + path + "' for reading:\n" + lastError();
}
+#ifndef __BCPLUSPLUS__
const string pathBZ2Temp = path + ".bz2temp";
FILE* stdioFile = 0;
int bzError = 0;
@@ -1030,6 +1133,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
throw ex;
}
}
+#endif
unsigned int bytesLeft = static_cast<unsigned int>(buf.st_size);
while(bytesLeft > 0)
@@ -1037,15 +1141,18 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
ByteSeq bytes(min(bytesLeft, 1024u*1024));
if(read(fd, &bytes[0], static_cast<unsigned int>(bytes.size())) == -1)
{
+#ifndef __BCPLUSPLUS__
if(doCompress)
{
fclose(stdioFile);
}
+#endif
close(fd);
throw "cannot read from `" + path + "':\n" + lastError();
}
bytesLeft -= static_cast<unsigned int>(bytes.size());
+#ifndef __BCPLUSPLUS__
if(doCompress)
{
BZ2_bzWrite(&bzError, bzFile, const_cast<Byte*>(&bytes[0]), static_cast<int>(bytes.size()));
@@ -1062,12 +1169,14 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
throw ex;
}
}
+#endif
SHA1_Update(&ctx, reinterpret_cast<const void*>(&bytes[0]), bytes.size());
}
close(fd);
+#ifndef __BCPLUSPLUS__
if(doCompress)
{
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
@@ -1093,6 +1202,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
info.size = static_cast<Int>(bufBZ2.st_size);
}
+#endif
}
SHA1_Final(reinterpret_cast<unsigned char*>(&bytesSHA[0]), &ctx);