Unzipping a file from C++ on Redhat: alternatives to system()

后端 未结 2 1280
再見小時候
再見小時候 2021-01-23 19:00

I need to unzip a file while running a C++ program (as described in Waiting for unzip to finish before carrying on C++ code on a RedHat machine)

To do this I currently d

2条回答
  •  借酒劲吻你
    2021-01-23 19:51

    You can use plain zlib, or the boost::iostream gzip facility.

    System isn't wrong per se, but you could also write a replacement for it which doesn't use the shell with fork, exec, wait and mkstemp. This is cumbersome though. Using boost::gzip_decompressor is the best C++ option to me if you decompress single files. Forking and friends may be better if you need to unzip a directory. Be sure to read about mkstemp.

    For a crash course on fork and exec family: http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html

    For an example of using wait for your child to terminate: http://support.sas.com/documentation/onlinedoc/sasc/doc/lr2/wait.htm

    For reference about creating a temporary directory: http://www.gnu.org/s/hello/manual/libc/Temporary-Files.html

提交回复
热议问题