Lines Matching refs:ctx

43 static int _win32_create_temp_file(_zip_source_win32_read_file_t *ctx);
48 static int _zip_stat_win32(void *h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx);
75 _zip_source_win32_read_file_t *ctx; in _zip_source_win32_handle_or_name() local
83 …if ((ctx = (_zip_source_win32_read_file_t *)malloc(sizeof(_zip_source_win32_read_file_t))) == NULL… in _zip_source_win32_handle_or_name()
88 ctx->fname = NULL; in _zip_source_win32_handle_or_name()
90 if ((ctx->fname = ops->op_strdup(fname)) == NULL) { in _zip_source_win32_handle_or_name()
92 free(ctx); in _zip_source_win32_handle_or_name()
97 ctx->ops = ops; in _zip_source_win32_handle_or_name()
98 ctx->h = h; in _zip_source_win32_handle_or_name()
99 ctx->start = start; in _zip_source_win32_handle_or_name()
100 ctx->end = (len < 0 ? 0 : start + (zip_uint64_t)len); in _zip_source_win32_handle_or_name()
101 ctx->closep = ctx->fname ? 1 : closep; in _zip_source_win32_handle_or_name()
103 memcpy(&ctx->st, st, sizeof(ctx->st)); in _zip_source_win32_handle_or_name()
104 ctx->st.name = NULL; in _zip_source_win32_handle_or_name()
105 ctx->st.valid &= ~ZIP_STAT_NAME; in _zip_source_win32_handle_or_name()
108 zip_stat_init(&ctx->st); in _zip_source_win32_handle_or_name()
111 ctx->tmpname = NULL; in _zip_source_win32_handle_or_name()
112 ctx->hout = INVALID_HANDLE_VALUE; in _zip_source_win32_handle_or_name()
114 zip_error_init(&ctx->error); in _zip_source_win32_handle_or_name()
116ctx->supports = ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS,… in _zip_source_win32_handle_or_name()
117 if (ctx->fname) { in _zip_source_win32_handle_or_name()
120 th = ops->op_open(ctx); in _zip_source_win32_handle_or_name()
122 ctx->supports = ZIP_SOURCE_SUPPORTS_WRITABLE; in _zip_source_win32_handle_or_name()
128 else if (GetFileType(ctx->h) == FILE_TYPE_DISK) { in _zip_source_win32_handle_or_name()
129 ctx->supports = ZIP_SOURCE_SUPPORTS_SEEKABLE; in _zip_source_win32_handle_or_name()
132 if ((zs = zip_source_function_create(_win32_read_file, ctx, error)) == NULL) { in _zip_source_win32_handle_or_name()
133 free(ctx->fname); in _zip_source_win32_handle_or_name()
134 free(ctx); in _zip_source_win32_handle_or_name()
145 _zip_source_win32_read_file_t *ctx; in _win32_read_file() local
150 ctx = (_zip_source_win32_read_file_t *)state; in _win32_read_file()
155 if (ctx->fname == NULL) { in _win32_read_file()
156 zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); in _win32_read_file()
159 return _win32_create_temp_file(ctx); in _win32_read_file()
162 if (!CloseHandle(ctx->hout)) { in _win32_read_file()
163 ctx->hout = INVALID_HANDLE_VALUE; in _win32_read_file()
164 zip_error_set(&ctx->error, ZIP_ER_WRITE, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
166 ctx->hout = INVALID_HANDLE_VALUE; in _win32_read_file()
167 if (ctx->ops->op_rename_temp(ctx) < 0) { in _win32_read_file()
168 zip_error_set(&ctx->error, ZIP_ER_RENAME, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
171 free(ctx->tmpname); in _win32_read_file()
172 ctx->tmpname = NULL; in _win32_read_file()
177 if (ctx->fname) { in _win32_read_file()
178 CloseHandle(ctx->h); in _win32_read_file()
179 ctx->h = INVALID_HANDLE_VALUE; in _win32_read_file()
184 return zip_error_to_data(&ctx->error, data, len); in _win32_read_file()
187 free(ctx->fname); in _win32_read_file()
188 free(ctx->tmpname); in _win32_read_file()
189 if (ctx->closep && ctx->h != INVALID_HANDLE_VALUE) in _win32_read_file()
190 CloseHandle(ctx->h); in _win32_read_file()
191 free(ctx); in _win32_read_file()
195 if (ctx->fname) { in _win32_read_file()
196 if ((ctx->h = ctx->ops->op_open(ctx)) == INVALID_HANDLE_VALUE) { in _win32_read_file()
197 zip_error_set(&ctx->error, ZIP_ER_OPEN, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
202 if (ctx->closep && ctx->start > 0) { in _win32_read_file()
203 if (_zip_seek_win32_u(ctx->h, ctx->start, SEEK_SET, &ctx->error) < 0) { in _win32_read_file()
207 ctx->current = ctx->start; in _win32_read_file()
211 if (ctx->end > 0) { in _win32_read_file()
212 n = ctx->end - ctx->current; in _win32_read_file()
224 if (!ctx->closep) { in _win32_read_file()
225 if (_zip_seek_win32_u(ctx->h, ctx->current, SEEK_SET, &ctx->error) < 0) { in _win32_read_file()
230 if (!ReadFile(ctx->h, buf, (DWORD)n, &i, NULL)) { in _win32_read_file()
231 zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
234 ctx->current += i; in _win32_read_file()
239 if (ctx->ops->op_remove(ctx->fname) < 0) { in _win32_read_file()
240 zip_error_set(&ctx->error, ZIP_ER_REMOVE, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
246 if (ctx->hout) { in _win32_read_file()
247 CloseHandle(ctx->hout); in _win32_read_file()
248 ctx->hout = INVALID_HANDLE_VALUE; in _win32_read_file()
250 ctx->ops->op_remove(ctx->tmpname); in _win32_read_file()
251 free(ctx->tmpname); in _win32_read_file()
252 ctx->tmpname = NULL; in _win32_read_file()
258 zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error); in _win32_read_file()
263 need_seek = ctx->closep; in _win32_read_file()
271 if (ctx->end == 0) { in _win32_read_file()
275 if (_zip_seek_win32(ctx->h, args->offset, SEEK_END, &ctx->error) < 0) { in _win32_read_file()
279 if (!SetFilePointerEx(ctx->h, zero, &new_offset, FILE_CURRENT)) { in _win32_read_file()
280 zip_error_set(&ctx->error, ZIP_ER_SEEK, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
287 new_current = (zip_int64_t)ctx->end + args->offset; in _win32_read_file()
291 new_current = (zip_int64_t)ctx->current + args->offset; in _win32_read_file()
295 zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); in _win32_read_file()
299 …w_current < 0 || (zip_uint64_t)new_current < ctx->start || (ctx->end != 0 && (zip_uint64_t)new_cur… in _win32_read_file()
300 zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); in _win32_read_file()
304 ctx->current = (zip_uint64_t)new_current; in _win32_read_file()
307 if (_zip_seek_win32_u(ctx->h, ctx->current, SEEK_SET, &ctx->error) < 0) { in _win32_read_file()
317 args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error); in _win32_read_file()
322 if (_zip_seek_win32(ctx->hout, args->offset, args->whence, &ctx->error) < 0) { in _win32_read_file()
329 if (len < sizeof(ctx->st)) in _win32_read_file()
332 if (ctx->st.valid != 0) in _win32_read_file()
333 memcpy(data, &ctx->st, sizeof(ctx->st)); in _win32_read_file()
342 if (ctx->h != INVALID_HANDLE_VALUE) { in _win32_read_file()
343 h = ctx->h; in _win32_read_file()
346 h = ctx->ops->op_open(ctx); in _win32_read_file()
348 zip_error_set(&ctx->error, ZIP_ER_READ, ENOENT); in _win32_read_file()
353 success = _zip_stat_win32(h, st, ctx); in _win32_read_file()
357 if (h != ctx->h) { in _win32_read_file()
363 zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(win32err)); in _win32_read_file()
367 return sizeof(ctx->st); in _win32_read_file()
371 return ctx->supports; in _win32_read_file()
374 return (zip_int64_t)ctx->current; in _win32_read_file()
382 if (!SetFilePointerEx(ctx->hout, zero, &offset, FILE_CURRENT)) { in _win32_read_file()
383 zip_error_set(&ctx->error, ZIP_ER_TELL, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
393 if (!WriteFile(ctx->hout, data, (DWORD)len, &ret, NULL) || ret != len) { in _win32_read_file()
394 zip_error_set(&ctx->error, ZIP_ER_WRITE, _zip_win32_error_to_errno(GetLastError())); in _win32_read_file()
402 zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); in _win32_read_file()
409 _win32_create_temp_file(_zip_source_win32_read_file_t *ctx) in _win32_create_temp_file() argument
432 if (ctx->h != INVALID_HANDLE_VALUE && GetFileType(ctx->h) == FILE_TYPE_DISK) { in _win32_create_temp_file()
435 success = GetUserObjectSecurity(ctx->h, &si, NULL, len, &len); in _win32_create_temp_file()
438 zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); in _win32_create_temp_file()
441 success = GetUserObjectSecurity(ctx->h, &si, psd, len, &len); in _win32_create_temp_file()
453 th = ctx->ops->op_create_temp(ctx, &temp, value + i, psa); in _win32_create_temp_file()
461 zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, _zip_win32_error_to_errno(GetLastError())); in _win32_create_temp_file()
466 ctx->hout = th; in _win32_create_temp_file()
467 ctx->tmpname = temp; in _win32_create_temp_file()
543 _zip_stat_win32(HANDLE h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx) in _zip_stat_win32() argument
551 zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError())); in _zip_stat_win32()
555 zip_error_set(&ctx->error, ZIP_ER_READ, ERANGE); in _zip_stat_win32()
565 zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError())); in _zip_stat_win32()
572 if (ctx->end != 0) { in _zip_stat_win32()
573 st->size = ctx->end - ctx->start; in _zip_stat_win32()