Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Forcing gzip to overwrite a .gz file in C

I am having a bit of trouble using gzip to compress a file from a C program. I am using this line of code execl("/usr/bin/gzip", "-f", filePath, NULL); to compress the file given by filePath. It works fine the first time (i.e. when there is no existing .gz file), but in subsequent executions of the program I am prompted whether or not I would like to overwrite the existing .gz file.

Am I using execl() incorrectly, because I am pretty sure that the -f switch forces gzip to overwrite without a prompt?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to provide argv[0] too. So, like this:

execl("/usr/bin/gzip",
      "whatever", "-f", filePath,
      NULL); 

In your code, you set argv[0] to be "-f", so it is essentially ignored.

Note that it’s customary to have argument 0 match program name, so "whatever" is a not nice in that sense.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading