~ubuntu-branches/ubuntu/vivid/libzip/vivid

« back to all changes in this revision

Viewing changes to regress/set_compression.c

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2014-02-09 13:24:18 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140209132418-t7u2auujqnfb5rvm
Tags: 0.11.2-1
* New upstream release (Closes: #734388).
* Remove patches:
  - fix_open_nonarchive_test.patch - fixed upstream
  - fix_zipconf_path.patch - fixed upstream
  - fix_broken_decrypt.patch - fixed upstream
  - fix_autotools_tests.diff - stolen upstream
* Update debian/control:
  - add unzip to Build-Depends.
  - bump compat to 9
* Update *.install: multiarch paths.
* Update libzip2 symbols file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  set_compression.c -- set compression method for file in archive
 
3
  Copyright (C) 2012 Dieter Baron and Thomas Klausner
 
4
 
 
5
  This file is part of libzip, a library to manipulate ZIP archives.
 
6
  The authors can be contacted at <libzip@nih.at>
 
7
 
 
8
  Redistribution and use in source and binary forms, with or without
 
9
  modification, are permitted provided that the following conditions
 
10
  are met:
 
11
  1. Redistributions of source code must retain the above copyright
 
12
     notice, this list of conditions and the following disclaimer.
 
13
  2. Redistributions in binary form must reproduce the above copyright
 
14
     notice, this list of conditions and the following disclaimer in
 
15
     the documentation and/or other materials provided with the
 
16
     distribution.
 
17
  3. The names of the authors may not be used to endorse or promote
 
18
     products derived from this software without specific prior
 
19
     written permission.
 
20
 
 
21
  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
 
22
  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
23
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
24
  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 
25
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
26
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 
27
  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
28
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 
29
  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
30
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 
31
  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
32
*/
 
33
 
 
34
 
 
35
 
 
36
#include <errno.h>
 
37
#include <stdio.h>
 
38
#include <stdlib.h>
 
39
#include <string.h>
 
40
 
 
41
#include "zipint.h"
 
42
 
 
43
#include "compat.h"
 
44
 
 
45
const char *prg;
 
46
 
 
47
int
 
48
main(int argc, char *argv[])
 
49
{
 
50
    const char *archive, *name;
 
51
    int method;
 
52
    struct zip *za;
 
53
    char buf[100];
 
54
    int err;
 
55
    zip_int64_t idx;
 
56
 
 
57
    prg = argv[0];
 
58
 
 
59
    if (argc != 4) {
 
60
        fprintf(stderr, "usage: %s archive file method\n", prg);
 
61
        return 1;
 
62
    }
 
63
 
 
64
    archive = argv[1];
 
65
    name = argv[2];
 
66
    method = atoi(argv[3]);
 
67
    
 
68
    if ((za=zip_open(archive, 0, &err)) == NULL) {
 
69
        zip_error_to_str(buf, sizeof(buf), err, errno);
 
70
        fprintf(stderr, "%s: can't open zip archive '%s': %s\n", prg,
 
71
                archive, buf);
 
72
        return 1;
 
73
    }
 
74
    if ((idx=zip_name_locate(za, name, 0)) < 0) {
 
75
        printf("%s: unexpected error while looking for '%s': %s\n",
 
76
               prg, name, zip_strerror(za));
 
77
        return 1;
 
78
    }
 
79
    if (zip_set_file_compression(za, idx, method, /* TODO: add flags * when supported */ 0) < 0) {
 
80
        fprintf(stderr, "zip_set_file_compression with method '%d' on file %" PRId64 " failed: %s\n",
 
81
                method, idx, zip_strerror(za));
 
82
        return 1;
 
83
    }
 
84
    if (zip_close(za) == -1) {
 
85
        fprintf(stderr, "%s: can't close zip archive '%s': %s\n", prg, archive, zip_strerror(za));
 
86
        return 1;
 
87
    }
 
88
 
 
89
    return 0;
 
90
}