File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -257,25 +257,24 @@ namespace xlogging_compress__ {
257257
258258 inline bool do_compress_gz (const std::string& infile)
259259 {
260- std::string outfile = infile + LOGGING_GZ_SUFFIX;
260+ FILE* in = fopen (infile.c_str (), " rb" );
261+ if (!in)
262+ return false ;
263+ std::unique_ptr<FILE, closefile_deleter> FILE_closer (in);
261264
265+ std::string outfile = infile + LOGGING_GZ_SUFFIX;
262266 gzFile out = gzopen (outfile.c_str (), " wb6f" );
263267 if (!out)
264268 return false ;
265-
266269 using gzFileType = typename std::remove_pointer<gzFile>::type;
267270 std::unique_ptr<gzFileType, closegz_deleter> gz_closer (out);
268271
269- FILE* in = fopen (infile.c_str (), " rb" );
270- if (!in)
271- return false ;
272-
273- std::unique_ptr<FILE, closefile_deleter> FILE_closer (in);
274- std::unique_ptr<char []> bufs (new char [LOGGING_GZ_BUFLEN]);
272+ auto bufs = std::make_unique_for_overwrite<char []>(LOGGING_GZ_BUFLEN);
275273 char * buf = bufs.get ();
276274 int len;
277275
278- for (;;) {
276+ for (;;)
277+ {
279278 len = (int )fread (buf, 1 , LOGGING_GZ_BUFLEN, in);
280279 if (ferror (in))
281280 return false ;
@@ -285,12 +284,11 @@ namespace xlogging_compress__ {
285284
286285 int total = 0 ;
287286 int ret;
288- while (total < len) {
287+ while (total < len)
288+ {
289289 ret = gzwrite (out, buf + total, (unsigned )len - total);
290- if (ret <= 0 ) {
291- // detail error information see gzerror(out, &ret);
290+ if (ret <= 0 )
292291 return false ;
293- }
294292 total += ret;
295293 }
296294 }
You can’t perform that action at this time.
0 commit comments