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

Go to the source code of this file.

Functions

ZIP_EXTERN void zip_file_attributes_init (zip_file_attributes_t *attributes)
 
int zip_source_get_file_attributes (zip_source_t *src, zip_file_attributes_t *attributes)
 

Function Documentation

◆ zip_file_attributes_init()

ZIP_EXTERN void zip_file_attributes_init ( zip_file_attributes_t attributes)

◆ zip_source_get_file_attributes()

int zip_source_get_file_attributes ( zip_source_t src,
zip_file_attributes_t attributes 
)

Definition at line 43 of file zip_source_get_file_attributes.c.

43  {
44  if (src->source_closed) {
45  return -1;
46  }
47  if (attributes == NULL) {
48  zip_error_set(&src->error, ZIP_ER_INVAL, 0);
49  return -1;
50  }
51 
52  zip_file_attributes_init(attributes);
53 
55  if (_zip_source_call(src, attributes, sizeof(*attributes), ZIP_SOURCE_GET_FILE_ATTRIBUTES) < 0) {
56  return -1;
57  }
58  }
59 
61  zip_file_attributes_t lower_attributes;
62 
63  if (zip_source_get_file_attributes(src->src, &lower_attributes) < 0) {
64  _zip_error_set_from_source(&src->error, src->src);
65  return -1;
66  }
67 
68  if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) == 0) {
69  attributes->host_system = lower_attributes.host_system;
71  }
72  if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_ASCII) && (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) == 0) {
73  attributes->ascii = lower_attributes.ascii;
74  attributes->valid |= ZIP_FILE_ATTRIBUTES_ASCII;
75  }
76  if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED)) {
77  if (attributes->valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED) {
78  attributes->version_needed = ZIP_MAX(lower_attributes.version_needed, attributes->version_needed);
79  }
80  else {
81  attributes->version_needed = lower_attributes.version_needed;
83  }
84  }
86  attributes->external_file_attributes = lower_attributes.external_file_attributes;
88  }
89  if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS)) {
91  /* only take from lower level what is not defined at current level */
92  lower_attributes.general_purpose_bit_mask &= ~attributes->general_purpose_bit_mask;
93 
94  attributes->general_purpose_bit_flags |= lower_attributes.general_purpose_bit_flags & lower_attributes.general_purpose_bit_mask;
95  attributes->general_purpose_bit_mask |= lower_attributes.general_purpose_bit_mask;
96  }
97  else {
99  attributes->general_purpose_bit_flags = lower_attributes.general_purpose_bit_flags;
100  attributes->general_purpose_bit_mask = lower_attributes.general_purpose_bit_mask;
101  }
102  }
103  }
104 
105  return 0;
106 }
lzma_index * src
Definition: index.h:567
#define NULL
Definition: cris-opc.c:27
#define ZIP_FILE_ATTRIBUTES_ASCII
Definition: zip.h:330
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM
Definition: zip.h:329
#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES
Definition: zip.h:332
#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd)
Definition: zip.h:243
@ ZIP_SOURCE_GET_FILE_ATTRIBUTES
Definition: zip.h:239
#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS
Definition: zip.h:333
#define ZIP_ER_INVAL
Definition: zip.h:123
#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED
Definition: zip.h:331
zip_uint8_t host_system
Definition: zip.h:321
zip_uint16_t general_purpose_bit_mask
Definition: zip.h:326
zip_uint8_t ascii
Definition: zip.h:322
zip_uint16_t general_purpose_bit_flags
Definition: zip.h:325
zip_uint8_t version_needed
Definition: zip.h:323
zip_uint32_t external_file_attributes
Definition: zip.h:324
void _zip_error_set_from_source(zip_error_t *err, zip_source_t *src)
Definition: zip_error.c:135
zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command)
int zip_source_get_file_attributes(zip_source_t *src, zip_file_attributes_t *attributes)
ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *attributes)
#define ZIP_MAX(a, b)
Definition: zipint.h:472
#define ZIP_SOURCE_IS_LAYERED(src)
Definition: zipint.h:404

References _zip_error_set_from_source(), _zip_source_call(), zip_file_attributes::ascii, zip_file_attributes::external_file_attributes, zip_file_attributes::general_purpose_bit_flags, zip_file_attributes::general_purpose_bit_mask, zip_file_attributes::host_system, NULL, src, zip_file_attributes::valid, zip_file_attributes::version_needed, ZIP_ER_INVAL, zip_error_set(), ZIP_FILE_ATTRIBUTES_ASCII, ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES, ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS, ZIP_FILE_ATTRIBUTES_HOST_SYSTEM, zip_file_attributes_init(), ZIP_FILE_ATTRIBUTES_VERSION_NEEDED, ZIP_MAX, ZIP_SOURCE_GET_FILE_ATTRIBUTES, zip_source_get_file_attributes(), ZIP_SOURCE_IS_LAYERED, and ZIP_SOURCE_MAKE_COMMAND_BITMASK.

Referenced by add_data(), compress_callback(), and zip_source_get_file_attributes().