0

I'm using libzip but I can't even use it. I'd like to create a new zip file.

zip_open("/path/to/my.zip", ZIP_CREATE, &err)

gives me this error code : -858993460

I compiled zlib and then libzip myself successfully (since I get no error) for both debug and release in Visual Studio. I followed instructions from this link.

What do I miss?

Community
  • 1
  • 1
Spiralwise
  • 338
  • 3
  • 18
  • You miss reading of documentation that tells you what that error code means. – Lightness Races in Orbit Dec 16 '15 at 17:41
  • How do you obtain the the error? In particular, how is `err` initialized and how is it printed? – Dietmar Kühl Dec 16 '15 at 17:52
  • 1
    -858993460 is 0xCCCCCCCC which is what VS will initialize memory to in debug mode. This may mean that `err` wasn't changed at all by the `zip_open` call. Try setting `err` to 0 before the call to verify it's being changed. Is `zip_open` returning NULL to indicate an error occurred? – pcarter Dec 16 '15 at 20:15
  • If I put 0 to `err`, it won't be changed. So does it actually mean it's ok? However, `zip_source_file` and `zip_file_add` still don't add the file into the archive. – Spiralwise Dec 17 '15 at 14:47
  • Ok, I know why it didn't create the zip. It is because the length parameter for `zip_source_file`. It must be -1 in order to process the whole file. – Spiralwise Dec 17 '15 at 15:22

1 Answers1

0

I resolved my issue thanks to comments in my question. Actually, my work is working. It is just that err variable must be initialized to 0 since when there is no error, err is not automatically updated. If not initialized, VS will do by itself with 0xCCCCCCCC which is actually -858993460 in decimal.

So the code should looks like this:

int err = 0;
zip_t *myzip = zip_open("/path/to/my.zip", ZIP_CREATE, &err);
Spiralwise
  • 338
  • 3
  • 18