Rizin
unix-like reverse engineering framework and cli tools
zip_file_set_external_attributes.c File Reference
#include "zipint.h"

Go to the source code of this file.

Functions

ZIP_EXTERN int zip_file_set_external_attributes (zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes)
 

Function Documentation

◆ zip_file_set_external_attributes()

ZIP_EXTERN int zip_file_set_external_attributes ( zip_t za,
zip_uint64_t  idx,
zip_flags_t  flags,
zip_uint8_t  opsys,
zip_uint32_t  attributes 
)

Definition at line 37 of file zip_file_set_external_attributes.c.

37  {
38  zip_entry_t *e;
39  int changed;
40  zip_uint8_t unchanged_opsys;
41  zip_uint32_t unchanged_attributes;
42 
43  if (_zip_get_dirent(za, idx, 0, NULL) == NULL)
44  return -1;
45 
46  if (ZIP_IS_RDONLY(za)) {
48  return -1;
49  }
50 
51  e = za->entry + idx;
52 
53  unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby >> 8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT);
54  unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT;
55 
56  changed = (opsys != unchanged_opsys || attributes != unchanged_attributes);
57 
58  if (changed) {
59  if (e->changes == NULL) {
60  if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
62  return -1;
63  }
64  }
65  e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff));
66  e->changes->ext_attrib = attributes;
67  e->changes->changed |= ZIP_DIRENT_ATTRIBUTES;
68  }
69  else if (e->changes) {
70  e->changes->changed &= ~ZIP_DIRENT_ATTRIBUTES;
71  if (e->changes->changed == 0) {
72  _zip_dirent_free(e->changes);
73  e->changes = NULL;
74  }
75  else {
76  e->changes->version_madeby = (zip_uint16_t)((unchanged_opsys << 8) | (e->changes->version_madeby & 0xff));
77  e->changes->ext_attrib = unchanged_attributes;
78  }
79  }
80 
81  return 0;
82 }
#define e(frag)
#define NULL
Definition: cris-opc.c:27
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_ER_MEMORY
Definition: zip.h:119
#define ZIP_ER_RDONLY
Definition: zip.h:130
#define ZIP_OPSYS_DEFAULT
Definition: zip.h:216
int idx
Definition: setup.py:197
Definition: zipint.h:408
zip_error_t error
Definition: zipint.h:281
zip_entry_t * entry
Definition: zipint.h:294
zip_dirent_t * _zip_dirent_clone(const zip_dirent_t *sde)
Definition: zip_dirent.c:215
zip_dirent_t * _zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
Definition: zip_dirent.c:1064
void _zip_dirent_free(zip_dirent_t *zde)
Definition: zip_dirent.c:258
uint32_t zip_uint32_t
Definition: zipconf.h:37
uint8_t zip_uint8_t
Definition: zipconf.h:33
uint16_t zip_uint16_t
Definition: zipconf.h:35
#define ZIP_DIRENT_ATTRIBUTES
Definition: zipint.h:320
#define ZIP_IS_RDONLY(za)
Definition: zipint.h:479
#define ZIP_EXT_ATTRIB_DEFAULT
Definition: zipint.h:93
zip_t * za
Definition: ziptool.c:79

References _zip_dirent_clone(), _zip_dirent_free(), _zip_get_dirent(), e, zip::entry, zip::error, setup::idx, NULL, za, ZIP_DIRENT_ATTRIBUTES, ZIP_ER_MEMORY, ZIP_ER_RDONLY, zip_error_set(), ZIP_EXT_ATTRIB_DEFAULT, ZIP_IS_RDONLY, and ZIP_OPSYS_DEFAULT.

Referenced by zip_dir_add().