summaryrefslogtreecommitdiffstats
path: root/src/libzip-test.c
blob: 26615929354959357f5ecd7dfbfc5eac5e0ebbd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * This file is part of MXE. See LICENSE.md for licensing information.
 */

#include <zip.h>
#include <stdlib.h>

/* Adapted from freedink/src/SDL_rwops_libzip.c */
int main(int argc, char* argv[])
{
    struct zip* zarchive;
    int errorp = 0;

    (void)argc;
    (void)argv;

    zarchive = zip_open("idontexist.zip", ZIP_CHECKCONS, &errorp);
    if (errorp != 0)
        {
            char *errorbuf = NULL;
            int len = 1;
            errorbuf = malloc(len);
            len = zip_error_to_str(errorbuf, len, errorp, errno);
            errorbuf = realloc(errorbuf, len + 1);
            len = zip_error_to_str(errorbuf, len, errorp, errno);
            fprintf(stderr, "zip_open: %s\n", errorbuf);
            free(errorbuf);
        }
    else
        {
            struct zip_file* zfile;
            zfile = zip_fopen(zarchive, "fichier.txt", 0);
            if (zfile == NULL)
                {
                    fprintf(stderr, "zip_open: %s\n", zip_strerror(zarchive));
                    zip_close(zarchive);
                }
        }

    return 0;
}