CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/libzip/zip_error.c
Views: 1401
/*1zip_error.c -- zip_error_t helper functions2Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner34This file is part of libzip, a library to manipulate ZIP archives.5The authors can be contacted at <[email protected]>67Redistribution and use in source and binary forms, with or without8modification, are permitted provided that the following conditions9are met:101. Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.122. Redistributions in binary form must reproduce the above copyright13notice, this list of conditions and the following disclaimer in14the documentation and/or other materials provided with the15distribution.163. The names of the authors may not be used to endorse or promote17products derived from this software without specific prior18written permission.1920THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS21OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE26GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER28IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR29OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN30IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233#include <stdlib.h>3435#include "zipint.h"363738ZIP_EXTERN int39zip_error_code_system(const zip_error_t *error) {40return error->sys_err;41}424344ZIP_EXTERN int45zip_error_code_zip(const zip_error_t *error) {46return error->zip_err;47}484950ZIP_EXTERN void51zip_error_fini(zip_error_t *err) {52free(err->str);53err->str = NULL;54}555657ZIP_EXTERN void58zip_error_init(zip_error_t *err) {59err->zip_err = ZIP_ER_OK;60err->sys_err = 0;61err->str = NULL;62}6364ZIP_EXTERN void65zip_error_init_with_code(zip_error_t *error, int ze) {66zip_error_init(error);67error->zip_err = ze;68switch (zip_error_system_type(error)) {69case ZIP_ET_SYS:70error->sys_err = errno;71break;7273default:74error->sys_err = 0;75break;76}77}787980ZIP_EXTERN int81zip_error_system_type(const zip_error_t *error) {82if (error->zip_err < 0 || error->zip_err >= _zip_nerr_str)83return ZIP_ET_NONE;8485return _zip_err_type[error->zip_err];86}878889void90_zip_error_clear(zip_error_t *err) {91if (err == NULL)92return;9394err->zip_err = ZIP_ER_OK;95err->sys_err = 0;96}979899void100_zip_error_copy(zip_error_t *dst, const zip_error_t *src) {101if (dst == NULL) {102return;103}104105dst->zip_err = src->zip_err;106dst->sys_err = src->sys_err;107}108109110void111_zip_error_get(const zip_error_t *err, int *zep, int *sep) {112if (zep)113*zep = err->zip_err;114if (sep) {115if (zip_error_system_type(err) != ZIP_ET_NONE)116*sep = err->sys_err;117else118*sep = 0;119}120}121122123void124zip_error_set(zip_error_t *err, int ze, int se) {125if (err) {126err->zip_err = ze;127err->sys_err = se;128}129}130131132void133_zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {134_zip_error_copy(err, zip_source_error(src));135}136137138zip_int64_t139zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) {140int *e = (int *)data;141142if (length < sizeof(int) * 2) {143return -1;144}145146e[0] = zip_error_code_zip(error);147e[1] = zip_error_code_system(error);148return sizeof(int) * 2;149}150151152