Back to index

php5  5.3.10
zip_unchange.c
Go to the documentation of this file.
00001 /*
00002   zip_unchange.c -- undo changes to file in zip archive
00003   Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
00004 
00005   This file is part of libzip, a library to manipulate ZIP archives.
00006   The authors can be contacted at <libzip@nih.at>
00007 
00008   Redistribution and use in source and binary forms, with or without
00009   modification, are permitted provided that the following conditions
00010   are met:
00011   1. Redistributions of source code must retain the above copyright
00012      notice, this list of conditions and the following disclaimer.
00013   2. Redistributions in binary form must reproduce the above copyright
00014      notice, this list of conditions and the following disclaimer in
00015      the documentation and/or other materials provided with the
00016      distribution.
00017   3. The names of the authors may not be used to endorse or promote
00018      products derived from this software without specific prior
00019      written permission.
00020  
00021   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
00022   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
00025   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00027   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00029   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00030   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00031   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 */
00033 
00034 
00035 
00036 #include <stdlib.h>
00037 
00038 #include "zipint.h"
00039 
00040 
00041 
00042 ZIP_EXTERN(int)
00043 zip_unchange(struct zip *za, int idx)
00044 {
00045     return _zip_unchange(za, idx, 0);
00046 }
00047 
00048 
00049 
00050 int
00051 _zip_unchange(struct zip *za, int idx, int allow_duplicates)
00052 {
00053     int i;
00054     
00055     if (idx < 0 || idx >= za->nentry) {
00056        _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
00057        return -1;
00058     }
00059 
00060     if (za->entry[idx].ch_filename) {
00061        if (!allow_duplicates) {
00062            i = _zip_name_locate(za,
00063                       _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL),
00064                              0, NULL);
00065            if (i != -1 && i != idx) {
00066               _zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
00067               return -1;
00068            }
00069        }
00070 
00071        free(za->entry[idx].ch_filename);
00072        za->entry[idx].ch_filename = NULL;
00073     }
00074 
00075     free(za->entry[idx].ch_comment);
00076     za->entry[idx].ch_comment = NULL;
00077     za->entry[idx].ch_comment_len = -1;
00078 
00079     _zip_unchange_data(za->entry+idx);
00080 
00081     return 0;
00082 }