os_fs.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00024 //----------------------------------------------------------------------
00025 #include "icl_core/os_fs.h"
00026 
00027 #include <iostream>
00028 
00029 #include "icl_core/BaseTypes.h"
00030 
00031 #ifdef _IC_BUILDER_ZLIB_
00032 # include <zlib.h>
00033 #endif
00034 
00035 namespace icl_core {
00036 namespace os {
00037 
00038 #ifdef _IC_BUILDER_ZLIB_
00039 bool zipFile(const char *filename, const char *additional_extension)
00040 {
00041   bool ret = true;
00042   icl_core::String gzip_file_name = icl_core::String(filename) + additional_extension + ".gz";
00043   char big_buffer[0x1000];
00044   int bytes_read = 0;
00045   gzFile unzipped_file = gzopen(filename, "rb");
00046   gzFile zipped_file = gzopen(gzip_file_name.c_str(), "wb");
00047 
00048   if (unzipped_file != NULL && zipped_file != NULL)
00049   {
00050     bytes_read = gzread(unzipped_file, big_buffer, 0x1000);
00051     while (bytes_read > 0)
00052     {
00053       if (gzwrite(zipped_file, big_buffer, bytes_read) != bytes_read)
00054       {
00055         std::cerr << "ZipFile(" << filename << "->" << gzip_file_name << ") Error on writing." << std::endl;
00056         ret = false;
00057         break;
00058       }
00059 
00060       bytes_read = gzread(unzipped_file, big_buffer, 0x1000);
00061     }
00062   }
00063 
00064   if (unzipped_file != NULL)
00065   {
00066     gzclose(unzipped_file);
00067   }
00068   if (zipped_file != NULL)
00069   {
00070     gzclose(zipped_file);
00071   }
00072 
00073   return ret;
00074 }
00075 
00077 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00078 
00079 bool ZipFile(const char *filename, const char *additional_extension)
00080 {
00081   return zipFile(filename, additional_extension);
00082 }
00083 
00084 #endif
00085 
00086 
00087 #endif
00088 
00089 }
00090 }


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24