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_file_set_external_attributes.c
Views: 1401
/*1zip_file_set_external_attributes.c -- set external attributes for entry2Copyright (C) 2013-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 "zipint.h"3435ZIP_EXTERN int36zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes) {37zip_entry_t *e;38int changed;39zip_uint8_t unchanged_opsys;40zip_uint32_t unchanged_attributes;4142if (_zip_get_dirent(za, idx, 0, NULL) == NULL)43return -1;4445if (ZIP_IS_RDONLY(za)) {46zip_error_set(&za->error, ZIP_ER_RDONLY, 0);47return -1;48}4950e = za->entry + idx;5152unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby >> 8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT);53unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT;5455changed = (opsys != unchanged_opsys || attributes != unchanged_attributes);5657if (changed) {58if (e->changes == NULL) {59if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {60zip_error_set(&za->error, ZIP_ER_MEMORY, 0);61return -1;62}63}64e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff));65e->changes->ext_attrib = attributes;66e->changes->changed |= ZIP_DIRENT_ATTRIBUTES;67}68else if (e->changes) {69e->changes->changed &= ~ZIP_DIRENT_ATTRIBUTES;70if (e->changes->changed == 0) {71_zip_dirent_free(e->changes);72e->changes = NULL;73}74else {75e->changes->version_madeby = (zip_uint16_t)((unchanged_opsys << 8) | (e->changes->version_madeby & 0xff));76e->changes->ext_attrib = unchanged_attributes;77}78}7980return 0;81}828384