mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-23 18:49:37 -10:00
intfstream_read_at reads at an offset and leaves the stream's position where it was: files and memory streams without touching the stream, so from several threads at once, CHD tracks by seeking there and back. The buffered stream reads from the file and keeps its window, and its own refills and wide reads go to the file at the offset. memstream_read_at backs memory streams. The CUE/ISO serial detectors read their probes this way. The zip reader takes its end records, directory, local headers and member chunks with one read at the offset each, where the file has them; the reads the stream lends from stay as they are. The Windows second handle is opened relative to the stream's own with an empty name through ntdll's NtCreateFile on every NT. From Vista on that is what ReOpenFile does; before it the handle is kept only when its volume and file index match the stream's, else the path reopen follows. Lanes: intfstream_read_at_test (file, buffered, memory; four threads), vfs_positional_ntverify_test (the check, on any version); archive_zip64 counts reads at offsets as reads through the stream.
72 lines
2.6 KiB
C
72 lines
2.6 KiB
C
/* Copyright (C) 2010-2020 The RetroArch team
|
|
*
|
|
* ---------------------------------------------------------------------------------------
|
|
* The following license statement only applies to this file (memory_stream.h).
|
|
* ---------------------------------------------------------------------------------------
|
|
*
|
|
* Permission is hereby granted, free of charge,
|
|
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#ifndef _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
|
|
#define _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
#include <retro_common_api.h>
|
|
|
|
RETRO_BEGIN_DECLS
|
|
|
|
typedef struct memstream memstream_t;
|
|
|
|
memstream_t *memstream_open(uint8_t *data, uint64_t size, unsigned writing);
|
|
|
|
void memstream_close(memstream_t *stream);
|
|
|
|
uint64_t memstream_read(memstream_t *stream, void *data, uint64_t bytes);
|
|
|
|
/**
|
|
* memstream_read_at:
|
|
*
|
|
* Up to @bytes from @offset, the stream's position left where it was.
|
|
* Returns the bytes copied, 0 at or past the end, -1 for a negative
|
|
* offset. Safe from any number of threads while nothing writes.
|
|
*/
|
|
int64_t memstream_read_at(memstream_t *stream, void *data, uint64_t bytes,
|
|
int64_t offset);
|
|
|
|
uint64_t memstream_write(memstream_t *stream, const void *data, uint64_t bytes);
|
|
|
|
int memstream_getc(memstream_t *stream);
|
|
|
|
void memstream_putc(memstream_t *stream, int c);
|
|
|
|
char *memstream_gets(memstream_t *stream, char *s, size_t len);
|
|
|
|
uint64_t memstream_pos(memstream_t *stream);
|
|
|
|
uint64_t memstream_get_size(memstream_t *stream);
|
|
|
|
void memstream_rewind(memstream_t *stream);
|
|
|
|
int64_t memstream_seek(memstream_t *stream, int64_t offset, int whence);
|
|
|
|
uint64_t memstream_get_ptr(memstream_t *stream);
|
|
|
|
RETRO_END_DECLS
|
|
|
|
#endif
|