summaryrefslogtreecommitdiff
path: root/Build/source/utils/lzma-utils/src/lzma/lzmp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/lzma-utils/src/lzma/lzmp.cpp')
-rw-r--r--Build/source/utils/lzma-utils/src/lzma/lzmp.cpp55
1 files changed, 27 insertions, 28 deletions
diff --git a/Build/source/utils/lzma-utils/src/lzma/lzmp.cpp b/Build/source/utils/lzma-utils/src/lzma/lzmp.cpp
index 7fd0d9e7c2b..50725b56b04 100644
--- a/Build/source/utils/lzma-utils/src/lzma/lzmp.cpp
+++ b/Build/source/utils/lzma-utils/src/lzma/lzmp.cpp
@@ -30,6 +30,7 @@ using std::endl;
#include <cstdio>
#include <cstring>
#include <climits>
+#include <cstdlib>
#include <string>
using std::string;
@@ -517,15 +518,6 @@ int open_outstream(const string outfile,
return outStreamSpec->File.GetHandle();
}
-double get_ratio(int inhandle, int outhandle)
-{
- struct stat in_stats, out_stats;
- fstat(inhandle, &in_stats);
- fstat(outhandle, &out_stats);
-
- return (double)out_stats.st_size / (double)in_stats.st_size;
-}
-
mode_t get_file_mode(string filename)
{
struct stat in_stat;
@@ -595,7 +587,7 @@ string pretty_print_status(string filename, string output_filename,
ret += ":\t ";
if (program_mode == PM_TEST) {
- ret += "decoded succesfully";
+ ret += "decoded successfully";
return ret;
}
@@ -607,7 +599,7 @@ string pretty_print_status(string filename, string output_filename,
if (program_mode == PM_COMPRESS) {
if (keep) {
- ret += "encoded succesfully";
+ ret += "encoded successfully";
return ret;
}
@@ -620,7 +612,7 @@ string pretty_print_status(string filename, string output_filename,
if (program_mode == PM_DECOMPRESS) {
if (keep) {
- ret += "decoded succesfully";
+ ret += "decoded successfully";
return ret;
}
@@ -884,16 +876,19 @@ int main(int argc, char **argv)
delete(decoderSpec);
}
+ struct stat in_stats, out_stats;
+ const bool in_stats_ok = !fstat(inhandle, &in_stats);
+ const bool out_stats_ok = verbosity > 0 ? !fstat(outhandle, &out_stats) : false;
+
/* Set permissions and owners. */
if ( (program_mode == PM_COMPRESS || program_mode == PM_DECOMPRESS )
&& (!stdinput && !stdoutput) ) {
- struct stat file_stats;
- if (!fstat(inhandle, &file_stats)) {
- (void)fchown(outhandle, file_stats.st_uid, -1);
+ if (in_stats_ok) {
+ (void)fchown(outhandle, in_stats.st_uid, -1);
mode_t mode;
- if (fchown(outhandle, -1, file_stats.st_gid)) {
+ if (fchown(outhandle, -1, in_stats.st_gid)) {
// Setting the GID of the file failed.
// We can still safely copy some
// permissions: `group' must be at
@@ -906,21 +901,21 @@ int main(int argc, char **argv)
// bad, because the owner would have
// had permission to chmod the
// original file anyway.
- mode = ((file_stats.st_mode & 0070) >> 3)
- & (file_stats.st_mode & 0007);
- mode = (file_stats.st_mode & 0700) | (mode << 3) | mode;
+ mode = ((in_stats.st_mode & 0070) >> 3)
+ & (in_stats.st_mode & 0007);
+ mode = (in_stats.st_mode & 0700) | (mode << 3) | mode;
} else {
- mode = file_stats.st_mode & 0777;
+ mode = in_stats.st_mode & 0777;
}
(void)fchmod(outhandle, mode);
struct timeval file_times[2];
// Access time
- file_times[0].tv_sec = file_stats.st_atime;
+ file_times[0].tv_sec = in_stats.st_atime;
file_times[0].tv_usec = 0;
// Modification time
- file_times[1].tv_sec = file_stats.st_mtime;
+ file_times[1].tv_sec = in_stats.st_mtime;
file_times[1].tv_usec = 0;
(void)futimes(outhandle, file_times);
@@ -944,19 +939,23 @@ int main(int argc, char **argv)
if (verbosity > 0) {
if (stdoutput) {
cerr << filenames[i] << ":\t ";
- cerr << "decoded succesfully"
+ cerr << (program_mode == PM_DECOMPRESS
+ ? "decoded successfully"
+ : "encoded successfully")
<< endl;
}
- else {
+ else if (in_stats_ok && out_stats_ok) {
char buf[10] = { 0 };
if (program_mode == PM_DECOMPRESS)
- snprintf(buf, 10, "%.2f%%",
- (1 - get_ratio(outhandle, inhandle)) * 100);
+ snprintf(buf, 10, "%.1f%%",
+ (1.0 - (double)in_stats.st_size
+ / (double)out_stats.st_size) * 100.0);
if (program_mode == PM_COMPRESS)
- snprintf(buf, 10, "%.2f%%",
- (1 - get_ratio(inhandle, outhandle)) * 100);
+ snprintf(buf, 10, "%.1f%%",
+ (1.0 - (double)out_stats.st_size
+ / (double)in_stats.st_size) * 100.0);
string ratio = buf;
cerr << pretty_print_status(filenames[i], output_filename,