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

Go to the source code of this file.

Functions

ZIP_EXTERN int zip_source_seek (zip_source_t *src, zip_int64_t offset, int whence)
 
zip_int64_t zip_source_seek_compute_offset (zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error)
 

Function Documentation

◆ zip_source_seek()

ZIP_EXTERN int zip_source_seek ( zip_source_t src,
zip_int64_t  offset,
int  whence 
)

Definition at line 39 of file zip_source_seek.c.

39  {
41 
42  if (src->source_closed) {
43  return -1;
44  }
45  if (!ZIP_SOURCE_IS_OPEN_READING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
46  zip_error_set(&src->error, ZIP_ER_INVAL, 0);
47  return -1;
48  }
49 
50  args.offset = offset;
51  args.whence = whence;
52 
53  if (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK) < 0) {
54  return -1;
55  }
56 
57  src->eof = 0;
58  return 0;
59 }
lzma_index * src
Definition: index.h:567
voidpf uLong offset
Definition: ioapi.h:144
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
@ ZIP_SOURCE_SEEK
Definition: zip.h:226
#define ZIP_ER_INVAL
Definition: zip.h:123
int args
Definition: mipsasm.c:18
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84
zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command)
#define ZIP_SOURCE_IS_OPEN_READING(src)
Definition: zipint.h:402

References _zip_source_call(), args, SEEK_CUR, SEEK_END, SEEK_SET, src, ZIP_ER_INVAL, zip_error_set(), ZIP_SOURCE_IS_OPEN_READING, and ZIP_SOURCE_SEEK.

Referenced by _zip_checkcons(), _zip_dirent_size(), _zip_file_get_end(), _zip_file_get_offset(), _zip_find_central_dir(), _zip_read_cdir(), _zip_read_eocd64(), _zip_read_local_ef(), crc_read(), window_read(), zip_close(), and zip_fseek().

◆ zip_source_seek_compute_offset()

zip_int64_t zip_source_seek_compute_offset ( zip_uint64_t  offset,
zip_uint64_t  length,
void *  data,
zip_uint64_t  data_length,
zip_error_t error 
)

Definition at line 63 of file zip_source_seek.c.

63  {
64  zip_int64_t new_offset;
66 
67  if (args == NULL) {
68  return -1;
69  }
70 
71  switch (args->whence) {
72  case SEEK_CUR:
73  new_offset = (zip_int64_t)offset + args->offset;
74  break;
75 
76  case SEEK_END:
77  new_offset = (zip_int64_t)length + args->offset;
78  break;
79 
80  case SEEK_SET:
81  new_offset = args->offset;
82  break;
83 
84  default:
86  return -1;
87  }
88 
89  if (new_offset < 0 || (zip_uint64_t)new_offset > length) {
91  return -1;
92  }
93 
94  return new_offset;
95 }
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define ZIP_SOURCE_GET_ARGS(type, data, len, error)
Definition: zip.h:279
void error(const char *msg)
Definition: untgz.c:593
uint64_t zip_uint64_t
Definition: zipconf.h:39
int64_t zip_int64_t
Definition: zipconf.h:38

References args, error(), length, NULL, SEEK_CUR, SEEK_END, SEEK_SET, ZIP_ER_INVAL, zip_error_set(), and ZIP_SOURCE_GET_ARGS.

Referenced by buffer_seek(), read_file(), and window_read().