"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/libzip/zip_error.c" (10 Oct 2018, 3602 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "zip_error.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.21_Source_vs_1.22_Source.

    1 /*
    2   zip_error.c -- zip_error_t helper functions
    3   Copyright (C) 1999-2016 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 #include <stdlib.h>
   35 
   36 #include "zipint.h"
   37 
   38 
   39 ZIP_EXTERN int
   40 zip_error_code_system(const zip_error_t *error) {
   41     return error->sys_err;
   42 }
   43 
   44 
   45 ZIP_EXTERN int
   46 zip_error_code_zip(const zip_error_t *error) {
   47     return error->zip_err;
   48 }
   49 
   50 
   51 ZIP_EXTERN void
   52 zip_error_fini(zip_error_t *err) {
   53     free(err->str);
   54     err->str = NULL;
   55 }
   56 
   57 
   58 ZIP_EXTERN void
   59 zip_error_init(zip_error_t *err) {
   60     err->zip_err = ZIP_ER_OK;
   61     err->sys_err = 0;
   62     err->str = NULL;
   63 }
   64 
   65 ZIP_EXTERN void
   66 zip_error_init_with_code(zip_error_t *error, int ze) {
   67     zip_error_init(error);
   68     error->zip_err = ze;
   69     switch (zip_error_system_type(error)) {
   70     case ZIP_ET_SYS:
   71     error->sys_err = errno;
   72     break;
   73 
   74     default:
   75     error->sys_err = 0;
   76     break;
   77     }
   78 }
   79 
   80 
   81 ZIP_EXTERN int
   82 zip_error_system_type(const zip_error_t *error) {
   83     if (error->zip_err < 0 || error->zip_err >= _zip_nerr_str)
   84     return ZIP_ET_NONE;
   85 
   86     return _zip_err_type[error->zip_err];
   87 }
   88 
   89 
   90 void
   91 _zip_error_clear(zip_error_t *err) {
   92     if (err == NULL)
   93     return;
   94 
   95     err->zip_err = ZIP_ER_OK;
   96     err->sys_err = 0;
   97 }
   98 
   99 
  100 void
  101 _zip_error_copy(zip_error_t *dst, const zip_error_t *src) {
  102     if (dst == NULL) {
  103     return;
  104     }
  105 
  106     dst->zip_err = src->zip_err;
  107     dst->sys_err = src->sys_err;
  108 }
  109 
  110 
  111 void
  112 _zip_error_get(const zip_error_t *err, int *zep, int *sep) {
  113     if (zep)
  114     *zep = err->zip_err;
  115     if (sep) {
  116     if (zip_error_system_type(err) != ZIP_ET_NONE)
  117         *sep = err->sys_err;
  118     else
  119         *sep = 0;
  120     }
  121 }
  122 
  123 
  124 void
  125 zip_error_set(zip_error_t *err, int ze, int se) {
  126     if (err) {
  127     err->zip_err = ze;
  128     err->sys_err = se;
  129     }
  130 }
  131 
  132 
  133 void
  134 _zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {
  135     _zip_error_copy(err, zip_source_error(src));
  136 }
  137 
  138 
  139 zip_int64_t
  140 zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) {
  141     int *e = (int *)data;
  142 
  143     if (length < sizeof(int) * 2) {
  144     return -1;
  145     }
  146 
  147     e[0] = zip_error_code_zip(error);
  148     e[1] = zip_error_code_system(error);
  149     return sizeof(int) * 2;
  150 }