mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-13 11:48:05 +08:00
SDL_rwops read/write functions return size_t again
The current status is stored in the SDL_rwops 'status' field to be able to determine whether a 0 return value is caused by end of file, an error, or a non-blocking source not being ready. The functions to read sized datatypes now return SDL_bool so you can detect read errors. Fixes https://github.com/libsdl-org/SDL/issues/6729
This commit is contained in:
@@ -2690,3 +2690,63 @@ typedef SDL_cond, SDL_Condition;
|
||||
- SDL_strtokr
|
||||
+ SDL_strtok_r
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_ReadLE16
|
||||
+ SDL_ReadU16LE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_ReadLE32
|
||||
+ SDL_ReadU32LE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_ReadBE32
|
||||
+ SDL_ReadU32BE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_ReadBE16
|
||||
+ SDL_ReadU16BE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_ReadLE64
|
||||
+ SDL_ReadU64LE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_ReadBE64
|
||||
+ SDL_ReadU64BE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_WriteLE16
|
||||
+ SDL_WriteU16LE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_WriteBE16
|
||||
+ SDL_WriteU16BE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_WriteLE32
|
||||
+ SDL_WriteU32LE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_WriteBE32
|
||||
+ SDL_WriteU32BE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_WriteLE64
|
||||
+ SDL_WriteU64LE
|
||||
(...)
|
||||
@@
|
||||
@@
|
||||
- SDL_WriteBE64
|
||||
+ SDL_WriteU64BE
|
||||
(...)
|
||||
|
||||
+37
-55
@@ -910,33 +910,26 @@ size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size, size_t maxn
|
||||
But now they look more like POSIX:
|
||||
|
||||
```c
|
||||
Sint64 SDL_RWread(SDL_RWops *context, void *ptr, Sint64 size);
|
||||
Sint64 SDL_RWwrite(SDL_RWops *context, const void *ptr, Sint64 size);
|
||||
size_t SDL_RWread(SDL_RWops *context, void *ptr, size_t size);
|
||||
size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size);
|
||||
```
|
||||
|
||||
SDL_RWread() previously returned 0 at end of file or other error. Now it returns the number of bytes read, 0 for end of file, -1 for another error, or -2 for data not ready (in the case of a non-blocking context).
|
||||
|
||||
Code that used to look like this:
|
||||
```
|
||||
size_t custom_read(void *ptr, size_t size, size_t nitems, SDL_RWops *stream)
|
||||
{
|
||||
return (size_t)SDL_RWread(stream, ptr, size, nitems);
|
||||
return SDL_RWread(stream, ptr, size, nitems);
|
||||
}
|
||||
```
|
||||
should be changed to:
|
||||
```
|
||||
size_t custom_read(void *ptr, size_t size, size_t nitems, SDL_RWops *stream)
|
||||
{
|
||||
Sint64 amount = SDL_RWread(stream, ptr, size * nitems);
|
||||
if (amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return (size_t)(amount / size);
|
||||
size_t bytes = SDL_RWread(stream, ptr, size * nitems);
|
||||
return (bytes / size);
|
||||
}
|
||||
```
|
||||
|
||||
Similarly, SDL_RWwrite() can return -2 for data not ready in the case of a non-blocking context. There is currently no way to create a non-blocking context, we have simply defined the semantic for your own custom SDL_RWops object.
|
||||
|
||||
SDL_RWFromFP has been removed from the API, due to issues when the SDL library uses a different C runtime from the application.
|
||||
|
||||
You can implement this in your own code easily:
|
||||
@@ -944,23 +937,7 @@ You can implement this in your own code easily:
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static Sint64 SDLCALL
|
||||
stdio_size(SDL_RWops * context)
|
||||
{
|
||||
Sint64 pos, size;
|
||||
|
||||
pos = SDL_RWseek(context, 0, SDL_RW_SEEK_CUR);
|
||||
if (pos < 0) {
|
||||
return -1;
|
||||
}
|
||||
size = SDL_RWseek(context, 0, SDL_RW_SEEK_END);
|
||||
|
||||
SDL_RWseek(context, pos, SDL_RW_SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
static Sint64 SDLCALL
|
||||
stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
|
||||
static Sint64 SDLCALL stdio_seek(SDL_RWops *context, Sint64 offset, int whence)
|
||||
{
|
||||
int stdiowhence;
|
||||
|
||||
@@ -988,54 +965,46 @@ stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
|
||||
return SDL_Error(SDL_EFSEEK);
|
||||
}
|
||||
|
||||
static Sint64 SDLCALL
|
||||
stdio_read(SDL_RWops * context, void *ptr, Sint64 size)
|
||||
static size_t SDLCALL stdio_read(SDL_RWops *context, void *ptr, size_t size)
|
||||
{
|
||||
size_t nread;
|
||||
size_t bytes;
|
||||
|
||||
nread = fread(ptr, 1, (size_t) size, (FILE *)context->hidden.stdio.fp);
|
||||
if (nread == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||
return SDL_Error(SDL_EFREAD);
|
||||
bytes = fread(ptr, 1, size, (FILE *)context->hidden.stdio.fp);
|
||||
if (bytes == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||
SDL_Error(SDL_EFREAD);
|
||||
}
|
||||
return (Sint64) nread;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static Sint64 SDLCALL
|
||||
stdio_write(SDL_RWops * context, const void *ptr, Sint64 size)
|
||||
static size_t SDLCALL stdio_write(SDL_RWops *context, const void *ptr, size_t size)
|
||||
{
|
||||
size_t nwrote;
|
||||
size_t bytes;
|
||||
|
||||
nwrote = fwrite(ptr, 1, (size_t) size, (FILE *)context->hidden.stdio.fp);
|
||||
if (nwrote == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||
return SDL_Error(SDL_EFWRITE);
|
||||
bytes = fwrite(ptr, 1, size, (FILE *)context->hidden.stdio.fp);
|
||||
if (bytes == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||
SDL_Error(SDL_EFWRITE);
|
||||
}
|
||||
return (Sint64) nwrote;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
stdio_close(SDL_RWops * context)
|
||||
static int SDLCALL stdio_close(SDL_RWops *context)
|
||||
{
|
||||
int status = 0;
|
||||
if (context) {
|
||||
if (context->hidden.stdio.autoclose) {
|
||||
/* WARNING: Check the return value here! */
|
||||
if (fclose((FILE *)context->hidden.stdio.fp) != 0) {
|
||||
status = SDL_Error(SDL_EFWRITE);
|
||||
}
|
||||
if (context->hidden.stdio.autoclose) {
|
||||
if (fclose((FILE *)context->hidden.stdio.fp) != 0) {
|
||||
status = SDL_Error(SDL_EFWRITE);
|
||||
}
|
||||
SDL_DestroyRW(context);
|
||||
}
|
||||
SDL_DestroyRW(context);
|
||||
return status;
|
||||
}
|
||||
|
||||
SDL_RWops *
|
||||
SDL_RWFromFP(void *fp, SDL_bool autoclose)
|
||||
SDL_RWops *SDL_RWFromFP(void *fp, SDL_bool autoclose)
|
||||
{
|
||||
SDL_RWops *rwops = NULL;
|
||||
|
||||
rwops = SDL_CreateRW();
|
||||
if (rwops != NULL) {
|
||||
rwops->size = stdio_size;
|
||||
rwops->seek = stdio_seek;
|
||||
rwops->read = stdio_read;
|
||||
rwops->write = stdio_write;
|
||||
@@ -1048,10 +1017,23 @@ SDL_RWFromFP(void *fp, SDL_bool autoclose)
|
||||
}
|
||||
```
|
||||
|
||||
The functions SDL_ReadU8(), SDL_ReadU16LE(), SDL_ReadU16BE(), SDL_ReadU32LE(), SDL_ReadU32BE(), SDL_ReadU64LE(), and SDL_ReadU64BE() now return SDL_TRUE if the read succeeded and SDL_FALSE if it didn't, and store the data in a pointer passed in as a parameter.
|
||||
|
||||
The following functions have been renamed:
|
||||
* SDL_AllocRW() => SDL_CreateRW()
|
||||
* SDL_FreeRW() => SDL_DestroyRW()
|
||||
* SDL_ReadBE16() => SDL_ReadU16BE()
|
||||
* SDL_ReadBE32() => SDL_ReadU32BE()
|
||||
* SDL_ReadBE64() => SDL_ReadU64BE()
|
||||
* SDL_ReadLE16() => SDL_ReadU16LE()
|
||||
* SDL_ReadLE32() => SDL_ReadU32LE()
|
||||
* SDL_ReadLE64() => SDL_ReadU64LE()
|
||||
* SDL_WriteBE16() => SDL_WriteU16BE()
|
||||
* SDL_WriteBE32() => SDL_WriteU32BE()
|
||||
* SDL_WriteBE64() => SDL_WriteU64BE()
|
||||
* SDL_WriteLE16() => SDL_WriteU16LE()
|
||||
* SDL_WriteLE32() => SDL_WriteU32LE()
|
||||
* SDL_WriteLE64() => SDL_WriteU64LE()
|
||||
|
||||
## SDL_sensor.h
|
||||
|
||||
|
||||
@@ -176,7 +176,8 @@ extern DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
|
||||
* constrained environment.
|
||||
*
|
||||
* \param src the data stream for the mappings to be added
|
||||
* \param freesrc non-zero to close the stream after being read
|
||||
* \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
|
||||
* even in the case of an error
|
||||
* \returns the number of mappings added or -1 on error; call SDL_GetError()
|
||||
* for more information.
|
||||
*
|
||||
@@ -186,7 +187,7 @@ extern DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
|
||||
* \sa SDL_AddGamepadMappingsFromFile
|
||||
* \sa SDL_GetGamepadMappingForGUID
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromRW(SDL_RWops *src, int freesrc);
|
||||
extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc);
|
||||
|
||||
/**
|
||||
* Load a set of gamepad mappings from a file.
|
||||
|
||||
@@ -423,6 +423,18 @@
|
||||
#define RW_SEEK_SET SDL_RW_SEEK_SET
|
||||
#define SDL_AllocRW SDL_CreateRW
|
||||
#define SDL_FreeRW SDL_DestroyRW
|
||||
#define SDL_ReadBE16 SDL_ReadU16BE
|
||||
#define SDL_ReadBE32 SDL_ReadU32BE
|
||||
#define SDL_ReadBE64 SDL_ReadU64BE
|
||||
#define SDL_ReadLE16 SDL_ReadU16LE
|
||||
#define SDL_ReadLE32 SDL_ReadU32LE
|
||||
#define SDL_ReadLE64 SDL_ReadU64LE
|
||||
#define SDL_WriteBE16 SDL_WriteU16BE
|
||||
#define SDL_WriteBE32 SDL_WriteU32BE
|
||||
#define SDL_WriteBE64 SDL_WriteU64BE
|
||||
#define SDL_WriteLE16 SDL_WriteU16LE
|
||||
#define SDL_WriteLE32 SDL_WriteU32LE
|
||||
#define SDL_WriteLE64 SDL_WriteU64LE
|
||||
|
||||
/* ##SDL_sensor.h */
|
||||
#define SDL_SensorClose SDL_CloseSensor
|
||||
@@ -863,6 +875,18 @@
|
||||
#define RW_SEEK_SET RW_SEEK_SET_renamed_SDL_RW_SEEK_SET
|
||||
#define SDL_AllocRW SDL_AllocRW_renamed_SDL_CreateRW
|
||||
#define SDL_FreeRW SDL_FreeRW_renamed_SDL_DestroyRW
|
||||
#define SDL_ReadBE16 SDL_ReadBE16_renamed_SDL_ReadU16BE
|
||||
#define SDL_ReadBE32 SDL_ReadBE32_renamed_SDL_ReadU32BE
|
||||
#define SDL_ReadBE64 SDL_ReadBE64_renamed_SDL_ReadU64BE
|
||||
#define SDL_ReadLE16 SDL_ReadLE16_renamed_SDL_ReadU16LE
|
||||
#define SDL_ReadLE32 SDL_ReadLE32_renamed_SDL_ReadU32LE
|
||||
#define SDL_ReadLE64 SDL_ReadLE64_renamed_SDL_ReadU64LE
|
||||
#define SDL_WriteBE16 SDL_WriteBE16_renamed_SDL_WriteU16BE
|
||||
#define SDL_WriteBE32 SDL_WriteBE32_renamed_SDL_WriteU32BE
|
||||
#define SDL_WriteBE64 SDL_WriteBE64_renamed_SDL_WriteU64BE
|
||||
#define SDL_WriteLE16 SDL_WriteLE16_renamed_SDL_WriteU16LE
|
||||
#define SDL_WriteLE32 SDL_WriteLE32_renamed_SDL_WriteU32LE
|
||||
#define SDL_WriteLE64 SDL_WriteLE64_renamed_SDL_WriteU64LE
|
||||
|
||||
/* ##SDL_sensor.h */
|
||||
#define SDL_SensorClose SDL_SensorClose_renamed_SDL_CloseSensor
|
||||
|
||||
+277
-136
File diff suppressed because it is too large
Load Diff
@@ -273,7 +273,8 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
|
||||
*
|
||||
* \param surface the SDL_Surface structure containing the image to be saved
|
||||
* \param dst a data stream to save to
|
||||
* \param freedst non-zero to close the stream after being written
|
||||
* \param freedst if SDL_TRUE, calls SDL_RWclose() on `dst` before returning,
|
||||
* even in the case of an error
|
||||
* \returns 0 on success or a negative error code on failure; call
|
||||
* SDL_GetError() for more information.
|
||||
*
|
||||
@@ -282,7 +283,7 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP(const char *file);
|
||||
* \sa SDL_LoadBMP_RW
|
||||
* \sa SDL_SaveBMP
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst);
|
||||
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, SDL_bool freedst);
|
||||
|
||||
/**
|
||||
* Save a surface to a file.
|
||||
|
||||
+22
-17
@@ -1553,7 +1553,7 @@ static int WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t len
|
||||
return -2;
|
||||
}
|
||||
|
||||
chunk->size = (size_t) SDL_RWread(src, chunk->data, length);
|
||||
chunk->size = SDL_RWread(src, chunk->data, length);
|
||||
if (chunk->size != length) {
|
||||
/* Expected to be handled by the caller. */
|
||||
}
|
||||
@@ -1614,16 +1614,20 @@ static int WaveReadFormat(WaveFile *file)
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
format->formattag = SDL_ReadLE16(fmtsrc);
|
||||
if (!SDL_ReadU16LE(fmtsrc, &format->formattag) ||
|
||||
!SDL_ReadU16LE(fmtsrc, &format->channels) ||
|
||||
!SDL_ReadU32LE(fmtsrc, &format->frequency) ||
|
||||
!SDL_ReadU32LE(fmtsrc, &format->byterate) ||
|
||||
!SDL_ReadU16LE(fmtsrc, &format->blockalign)) {
|
||||
return -1;
|
||||
}
|
||||
format->encoding = format->formattag;
|
||||
format->channels = SDL_ReadLE16(fmtsrc);
|
||||
format->frequency = SDL_ReadLE32(fmtsrc);
|
||||
format->byterate = SDL_ReadLE32(fmtsrc);
|
||||
format->blockalign = SDL_ReadLE16(fmtsrc);
|
||||
|
||||
/* This is PCM specific in the first version of the specification. */
|
||||
if (fmtlen >= 16) {
|
||||
format->bitspersample = SDL_ReadLE16(fmtsrc);
|
||||
if (!SDL_ReadU16LE(fmtsrc, &format->bitspersample)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (format->encoding == PCM_CODE) {
|
||||
SDL_RWclose(fmtsrc);
|
||||
return SDL_SetError("Missing wBitsPerSample field in WAVE fmt chunk");
|
||||
@@ -1631,7 +1635,9 @@ static int WaveReadFormat(WaveFile *file)
|
||||
|
||||
/* The earlier versions also don't have this field. */
|
||||
if (fmtlen >= 18) {
|
||||
format->extsize = SDL_ReadLE16(fmtsrc);
|
||||
if (!SDL_ReadU16LE(fmtsrc, &format->extsize)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (format->formattag == EXTENSIBLE_CODE) {
|
||||
@@ -1647,10 +1653,11 @@ static int WaveReadFormat(WaveFile *file)
|
||||
return SDL_SetError("Extensible WAVE header too small");
|
||||
}
|
||||
|
||||
format->validsamplebits = SDL_ReadLE16(fmtsrc);
|
||||
if (!SDL_ReadU16LE(fmtsrc, &format->validsamplebits) ||
|
||||
!SDL_ReadU32LE(fmtsrc, &format->channelmask) ||
|
||||
SDL_RWread(fmtsrc, format->subformat, 16) != 16) {
|
||||
}
|
||||
format->samplesperblock = format->validsamplebits;
|
||||
format->channelmask = SDL_ReadLE32(fmtsrc);
|
||||
SDL_RWread(fmtsrc, format->subformat, 16);
|
||||
format->encoding = WaveGetFormatGUIDEncoding(format);
|
||||
}
|
||||
|
||||
@@ -1802,9 +1809,9 @@ static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 *
|
||||
if (RIFFchunk.fourcc == RIFF) {
|
||||
Uint32 formtype;
|
||||
/* Read the form type. "WAVE" expected. */
|
||||
if (SDL_RWread(src, &formtype, sizeof(Uint32)) != sizeof(Uint32)) {
|
||||
if (!SDL_ReadU32LE(src, &formtype)) {
|
||||
return SDL_SetError("Could not read RIFF form type");
|
||||
} else if (SDL_SwapLE32(formtype) != WAVE) {
|
||||
} else if (formtype != WAVE) {
|
||||
return SDL_SetError("RIFF form type is not WAVE (not a Waveform file)");
|
||||
}
|
||||
} else if (RIFFchunk.fourcc == WAVE) {
|
||||
@@ -1891,10 +1898,8 @@ static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 *
|
||||
} else {
|
||||
/* Let's use src directly, it's just too convenient. */
|
||||
Sint64 position = SDL_RWseek(src, chunk->position, SDL_RW_SEEK_SET);
|
||||
Uint32 samplelength;
|
||||
if (position == chunk->position && SDL_RWread(src, &samplelength, sizeof(Uint32)) == sizeof(Uint32)) {
|
||||
if (position == chunk->position && SDL_ReadU32LE(src, &file->fact.samplelength)) {
|
||||
file->fact.status = 1;
|
||||
file->fact.samplelength = SDL_SwapLE32(samplelength);
|
||||
} else {
|
||||
file->fact.status = -1;
|
||||
}
|
||||
@@ -1937,7 +1942,7 @@ static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 *
|
||||
Uint64 position = (Uint64)chunk->position + chunk->length - 1;
|
||||
if (position > SDL_MAX_SINT64 || SDL_RWseek(src, (Sint64)position, SDL_RW_SEEK_SET) != (Sint64)position) {
|
||||
return SDL_SetError("Could not seek to WAVE chunk data");
|
||||
} else if (SDL_RWread(src, &tmp, 1) != 1) {
|
||||
} else if (!SDL_ReadU8(src, &tmp)) {
|
||||
return SDL_SetError("RIFF size truncates chunk");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ static void DISKAUDIO_WaitDevice(SDL_AudioDevice *device)
|
||||
|
||||
static void DISKAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||
{
|
||||
const Sint64 written = SDL_RWwrite(device->hidden->io, buffer, buffer_size);
|
||||
const int written = (int)SDL_RWwrite(device->hidden->io, buffer, (size_t)buffer_size);
|
||||
if (written != buffer_size) { // If we couldn't write, assume fatal error for now
|
||||
SDL_AudioDeviceDisconnected(device);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ static int DISKAUDIO_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, in
|
||||
const int origbuflen = buflen;
|
||||
|
||||
if (h->io) {
|
||||
const int br = (int) SDL_RWread(h->io, buffer, (Sint64) buflen);
|
||||
const int br = (int)SDL_RWread(h->io, buffer, (size_t)buflen);
|
||||
buflen -= br;
|
||||
buffer = ((Uint8 *)buffer) + br;
|
||||
if (buflen > 0) { // EOF (or error, but whatever).
|
||||
|
||||
@@ -1983,13 +1983,18 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
Sint64 Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, Sint64 size)
|
||||
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size)
|
||||
{
|
||||
AAsset *asset = (AAsset *)ctx->hidden.androidio.asset;
|
||||
return (Sint64) AAsset_read(asset, buffer, (size_t) size);
|
||||
int bytes = AAsset_read(asset, buffer, size);
|
||||
if (bytes < 0) {
|
||||
SDL_SetError("AAsset_read() failed");
|
||||
return 0;
|
||||
}
|
||||
return (size_t)bytes;
|
||||
}
|
||||
|
||||
Sint64 Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, Sint64 size)
|
||||
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size)
|
||||
{
|
||||
return SDL_SetError("Cannot write to Android package filesystem");
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ extern SDL_bool Android_IsChromebook(void);
|
||||
int Android_JNI_FileOpen(SDL_RWops *ctx, const char *fileName, const char *mode);
|
||||
Sint64 Android_JNI_FileSize(SDL_RWops *ctx);
|
||||
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence);
|
||||
Sint64 Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, Sint64 size);
|
||||
Sint64 Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, Sint64 size);
|
||||
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size);
|
||||
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size);
|
||||
int Android_JNI_FileClose(SDL_RWops *ctx);
|
||||
|
||||
/* Environment support */
|
||||
|
||||
+23
-12
@@ -504,12 +504,12 @@ SDL3_0.0.0 {
|
||||
SDL_RWtell;
|
||||
SDL_RWwrite;
|
||||
SDL_RaiseWindow;
|
||||
SDL_ReadBE16;
|
||||
SDL_ReadBE32;
|
||||
SDL_ReadBE64;
|
||||
SDL_ReadLE16;
|
||||
SDL_ReadLE32;
|
||||
SDL_ReadLE64;
|
||||
SDL_ReadU16BE;
|
||||
SDL_ReadU32BE;
|
||||
SDL_ReadU64BE;
|
||||
SDL_ReadU16LE;
|
||||
SDL_ReadU32LE;
|
||||
SDL_ReadU64LE;
|
||||
SDL_ReadU8;
|
||||
SDL_RegisterApp;
|
||||
SDL_RegisterEvents;
|
||||
@@ -676,12 +676,12 @@ SDL3_0.0.0 {
|
||||
SDL_WinRTGetDeviceFamily;
|
||||
SDL_WinRTGetFSPathUNICODE;
|
||||
SDL_WinRTGetFSPathUTF8;
|
||||
SDL_WriteBE16;
|
||||
SDL_WriteBE32;
|
||||
SDL_WriteBE64;
|
||||
SDL_WriteLE16;
|
||||
SDL_WriteLE32;
|
||||
SDL_WriteLE64;
|
||||
SDL_WriteU16BE;
|
||||
SDL_WriteU32BE;
|
||||
SDL_WriteU64BE;
|
||||
SDL_WriteU16LE;
|
||||
SDL_WriteU32LE;
|
||||
SDL_WriteU64LE;
|
||||
SDL_WriteU8;
|
||||
SDL_abs;
|
||||
SDL_acos;
|
||||
@@ -888,6 +888,17 @@ SDL3_0.0.0 {
|
||||
SDL_IsAudioDevicePaused;
|
||||
SDL_GetAudioStreamBinding;
|
||||
SDL_ShowWindowSystemMenu;
|
||||
SDL_ReadS16LE;
|
||||
SDL_ReadS16BE;
|
||||
SDL_ReadS32LE;
|
||||
SDL_ReadS32BE;
|
||||
SDL_ReadS64LE;
|
||||
SDL_ReadS64BE;
|
||||
SDL_WriteS16LE;
|
||||
SDL_WriteS16BE;
|
||||
SDL_WriteS32LE;
|
||||
SDL_WriteS32BE;
|
||||
SDL_WriteS64LE;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -528,12 +528,12 @@
|
||||
#define SDL_RWtell SDL_RWtell_REAL
|
||||
#define SDL_RWwrite SDL_RWwrite_REAL
|
||||
#define SDL_RaiseWindow SDL_RaiseWindow_REAL
|
||||
#define SDL_ReadBE16 SDL_ReadBE16_REAL
|
||||
#define SDL_ReadBE32 SDL_ReadBE32_REAL
|
||||
#define SDL_ReadBE64 SDL_ReadBE64_REAL
|
||||
#define SDL_ReadLE16 SDL_ReadLE16_REAL
|
||||
#define SDL_ReadLE32 SDL_ReadLE32_REAL
|
||||
#define SDL_ReadLE64 SDL_ReadLE64_REAL
|
||||
#define SDL_ReadU16BE SDL_ReadU16BE_REAL
|
||||
#define SDL_ReadU32BE SDL_ReadU32BE_REAL
|
||||
#define SDL_ReadU64BE SDL_ReadU64BE_REAL
|
||||
#define SDL_ReadU16LE SDL_ReadU16LE_REAL
|
||||
#define SDL_ReadU32LE SDL_ReadU32LE_REAL
|
||||
#define SDL_ReadU64LE SDL_ReadU64LE_REAL
|
||||
#define SDL_ReadU8 SDL_ReadU8_REAL
|
||||
#define SDL_RegisterApp SDL_RegisterApp_REAL
|
||||
#define SDL_RegisterEvents SDL_RegisterEvents_REAL
|
||||
@@ -699,12 +699,12 @@
|
||||
#define SDL_WinRTGetDeviceFamily SDL_WinRTGetDeviceFamily_REAL
|
||||
#define SDL_WinRTGetFSPathUNICODE SDL_WinRTGetFSPathUNICODE_REAL
|
||||
#define SDL_WinRTGetFSPathUTF8 SDL_WinRTGetFSPathUTF8_REAL
|
||||
#define SDL_WriteBE16 SDL_WriteBE16_REAL
|
||||
#define SDL_WriteBE32 SDL_WriteBE32_REAL
|
||||
#define SDL_WriteBE64 SDL_WriteBE64_REAL
|
||||
#define SDL_WriteLE16 SDL_WriteLE16_REAL
|
||||
#define SDL_WriteLE32 SDL_WriteLE32_REAL
|
||||
#define SDL_WriteLE64 SDL_WriteLE64_REAL
|
||||
#define SDL_WriteU16BE SDL_WriteU16BE_REAL
|
||||
#define SDL_WriteU32BE SDL_WriteU32BE_REAL
|
||||
#define SDL_WriteU64BE SDL_WriteU64BE_REAL
|
||||
#define SDL_WriteU16LE SDL_WriteU16LE_REAL
|
||||
#define SDL_WriteU32LE SDL_WriteU32LE_REAL
|
||||
#define SDL_WriteU64LE SDL_WriteU64LE_REAL
|
||||
#define SDL_WriteU8 SDL_WriteU8_REAL
|
||||
#define SDL_abs SDL_abs_REAL
|
||||
#define SDL_acos SDL_acos_REAL
|
||||
@@ -913,3 +913,14 @@
|
||||
#define SDL_IsAudioDevicePaused SDL_IsAudioDevicePaused_REAL
|
||||
#define SDL_GetAudioStreamBinding SDL_GetAudioStreamBinding_REAL
|
||||
#define SDL_ShowWindowSystemMenu SDL_ShowWindowSystemMenu_REAL
|
||||
#define SDL_ReadS16LE SDL_ReadS16LE_REAL
|
||||
#define SDL_ReadS16BE SDL_ReadS16BE_REAL
|
||||
#define SDL_ReadS32LE SDL_ReadS32LE_REAL
|
||||
#define SDL_ReadS32BE SDL_ReadS32BE_REAL
|
||||
#define SDL_ReadS64LE SDL_ReadS64LE_REAL
|
||||
#define SDL_ReadS64BE SDL_ReadS64BE_REAL
|
||||
#define SDL_WriteS16LE SDL_WriteS16LE_REAL
|
||||
#define SDL_WriteS16BE SDL_WriteS16BE_REAL
|
||||
#define SDL_WriteS32LE SDL_WriteS32LE_REAL
|
||||
#define SDL_WriteS32BE SDL_WriteS32BE_REAL
|
||||
#define SDL_WriteS64LE SDL_WriteS64LE_REAL
|
||||
|
||||
@@ -119,7 +119,7 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_IsDeXMode,(void),(),return)
|
||||
|
||||
SDL_DYNAPI_PROC(void,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),)
|
||||
SDL_DYNAPI_PROC(int,SDL_AddGamepadMapping,(const char *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AddGamepadMappingsFromRW,(SDL_RWops *a, int b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AddGamepadMappingsFromRW,(SDL_RWops *a, SDL_bool b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_TimerID,SDL_AddTimer,(Uint32 a, SDL_TimerCallback b, void *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AtomicAdd,(SDL_AtomicInt *a, int b),(a,b),return)
|
||||
@@ -581,19 +581,19 @@ SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromConstMem,(const void *a, size_t b),(a,b),re
|
||||
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFile,(const char *a, const char *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromMem,(void *a, size_t b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_RWclose,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Sint64,SDL_RWread,(SDL_RWops *a, void *b, Sint64 c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_RWread,(SDL_RWops *a, void *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(Sint64,SDL_RWseek,(SDL_RWops *a, Sint64 b, int c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(Sint64,SDL_RWsize,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Sint64,SDL_RWtell,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Sint64,SDL_RWwrite,(SDL_RWops *a, const void *b, Sint64 c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_RWwrite,(SDL_RWops *a, const void *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_RaiseWindow,(SDL_Window *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint16,SDL_ReadBE16,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_ReadBE32,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint64,SDL_ReadBE64,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint16,SDL_ReadLE16,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_ReadLE32,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint64,SDL_ReadLE64,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint8,SDL_ReadU8,(SDL_RWops *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU16BE,(SDL_RWops *a, Uint16 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU32BE,(SDL_RWops *a, Uint32 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU64BE,(SDL_RWops *a, Uint64 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU16LE,(SDL_RWops *a, Uint16 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU32LE,(SDL_RWops *a, Uint32 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU64LE,(SDL_RWops *a, Uint64 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU8,(SDL_RWops *a, Uint8 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_RegisterEvents,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_RemoveTimer,(SDL_TimerID a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_RenderClear,(SDL_Renderer *a),(a),return)
|
||||
@@ -628,7 +628,7 @@ SDL_DYNAPI_PROC(int,SDL_RumbleJoystickTriggers,(SDL_Joystick *a, Uint16 b, Uint1
|
||||
SDL_DYNAPI_PROC(int,SDL_RunApp,(int a, char *b[], SDL_main_func c, void *d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_SIMDGetAlignment,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SaveBMP,(SDL_Surface *a, const char *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, SDL_bool c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ScreenKeyboardShown,(SDL_Window *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ScreenSaverEnabled,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SendGamepadEffect,(SDL_Gamepad *a, const void *b, int c),(a,b,c),return)
|
||||
@@ -750,13 +750,13 @@ SDL_DYNAPI_PROC(void,SDL_WaitThread,(SDL_Thread *a, int *b),(a,b),)
|
||||
SDL_DYNAPI_PROC(int,SDL_WarpMouseGlobal,(float a, float b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_WarpMouseInWindow,(SDL_Window *a, float b, float c),(a,b,c),)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_WasInit,(Uint32 a),(a),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteBE16,(SDL_RWops *a, Uint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteBE32,(SDL_RWops *a, Uint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteBE64,(SDL_RWops *a, Uint64 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteLE16,(SDL_RWops *a, Uint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteLE32,(SDL_RWops *a, Uint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteLE64,(SDL_RWops *a, Uint64 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteU8,(SDL_RWops *a, Uint8 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU16BE,(SDL_RWops *a, Uint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU32BE,(SDL_RWops *a, Uint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU64BE,(SDL_RWops *a, Uint64 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU16LE,(SDL_RWops *a, Uint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU32LE,(SDL_RWops *a, Uint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU64LE,(SDL_RWops *a, Uint64 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU8,(SDL_RWops *a, Uint8 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_abs,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(double,SDL_acos,(double a),(a),return)
|
||||
SDL_DYNAPI_PROC(float,SDL_acosf,(float a),(a),return)
|
||||
@@ -957,3 +957,14 @@ SDL_DYNAPI_PROC(int,SDL_ResumeAudioDevice,(SDL_AudioDeviceID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_IsAudioDevicePaused,(SDL_AudioDeviceID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_GetAudioStreamBinding,(SDL_AudioStream *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_ShowWindowSystemMenu,(SDL_Window *a, int b, int c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS16LE,(SDL_RWops *a, Sint16 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS16BE,(SDL_RWops *a, Sint16 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS32LE,(SDL_RWops *a, Sint32 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS32BE,(SDL_RWops *a, Sint32 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS64LE,(SDL_RWops *a, Sint64 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS64BE,(SDL_RWops *a, Sint64 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS16LE,(SDL_RWops *a, Sint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS16BE,(SDL_RWops *a, Sint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS32LE,(SDL_RWops *a, Sint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS32BE,(SDL_RWops *a, Sint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS64LE,(SDL_RWops *a, Sint64 b),(a,b),return)
|
||||
|
||||
+336
-206
File diff suppressed because it is too large
Load Diff
@@ -1694,40 +1694,18 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id
|
||||
/*
|
||||
* Add or update an entry into the Mappings Database
|
||||
*/
|
||||
int SDL_AddGamepadMappingsFromRW(SDL_RWops *src, int freesrc)
|
||||
int SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc)
|
||||
{
|
||||
const char *platform = SDL_GetPlatform();
|
||||
int gamepads = 0;
|
||||
char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
|
||||
Sint64 db_size;
|
||||
size_t db_size;
|
||||
size_t platform_len;
|
||||
|
||||
if (src == NULL) {
|
||||
return SDL_InvalidParamError("src");
|
||||
}
|
||||
db_size = SDL_RWsize(src);
|
||||
|
||||
buf = (char *)SDL_malloc((size_t)db_size + 1);
|
||||
buf = (char *)SDL_LoadFile_RW(src, &db_size, freesrc);
|
||||
if (buf == NULL) {
|
||||
if (freesrc) {
|
||||
SDL_RWclose(src);
|
||||
}
|
||||
return SDL_SetError("Could not allocate space to read DB into memory");
|
||||
}
|
||||
|
||||
if (SDL_RWread(src, buf, db_size) != db_size) {
|
||||
if (freesrc) {
|
||||
SDL_RWclose(src);
|
||||
}
|
||||
SDL_free(buf);
|
||||
return SDL_SetError("Could not read DB");
|
||||
}
|
||||
|
||||
if (freesrc) {
|
||||
SDL_RWclose(src);
|
||||
}
|
||||
|
||||
buf[db_size] = '\0';
|
||||
line = buf;
|
||||
|
||||
PushMappingChangeTracking();
|
||||
|
||||
+172
-131
File diff suppressed because it is too large
Load Diff
+55
-49
@@ -95,11 +95,11 @@ static void RWopsTearDown(void *arg)
|
||||
* \sa SDL_RWseek
|
||||
* \sa SDL_RWread
|
||||
*/
|
||||
static void testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
static void testGenericRWopsValidations(SDL_RWops *rw, SDL_bool write)
|
||||
{
|
||||
char buf[sizeof(RWopsHelloWorldTestString)];
|
||||
Sint64 i;
|
||||
Sint64 s;
|
||||
size_t s;
|
||||
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
|
||||
|
||||
/* Clear buffer */
|
||||
@@ -116,7 +116,7 @@ static void testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
if (write) {
|
||||
SDLTest_AssertCheck(s == sizeof(RWopsHelloWorldTestString) - 1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int)s);
|
||||
} else {
|
||||
SDLTest_AssertCheck(s == -1, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
|
||||
SDLTest_AssertCheck(s == 0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
|
||||
}
|
||||
|
||||
/* Test seek to random position */
|
||||
@@ -133,7 +133,7 @@ static void testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
s = SDL_RWread(rw, buf, sizeof(RWopsHelloWorldTestString) - 1);
|
||||
SDLTest_AssertPass("Call to SDL_RWread succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
s == (size_t)(sizeof(RWopsHelloWorldTestString) - 1),
|
||||
s == (sizeof(RWopsHelloWorldTestString) - 1),
|
||||
"Verify result from SDL_RWread, expected %i, got %i",
|
||||
(int)(sizeof(RWopsHelloWorldTestString) - 1),
|
||||
(int)s);
|
||||
@@ -242,7 +242,7 @@ static int rwops_testMem(void *arg)
|
||||
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY, rw->type);
|
||||
|
||||
/* Run generic tests */
|
||||
testGenericRWopsValidations(rw, 1);
|
||||
testGenericRWopsValidations(rw, SDL_TRUE);
|
||||
|
||||
/* Close */
|
||||
result = SDL_RWclose(rw);
|
||||
@@ -277,7 +277,7 @@ static int rwops_testConstMem(void *arg)
|
||||
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY_RO, rw->type);
|
||||
|
||||
/* Run generic tests */
|
||||
testGenericRWopsValidations(rw, 0);
|
||||
testGenericRWopsValidations(rw, SDL_FALSE);
|
||||
|
||||
/* Close handle */
|
||||
result = SDL_RWclose(rw);
|
||||
@@ -324,7 +324,7 @@ static int rwops_testFileRead(void *arg)
|
||||
#endif
|
||||
|
||||
/* Run generic tests */
|
||||
testGenericRWopsValidations(rw, 0);
|
||||
testGenericRWopsValidations(rw, SDL_FALSE);
|
||||
|
||||
/* Close handle */
|
||||
result = SDL_RWclose(rw);
|
||||
@@ -371,7 +371,7 @@ static int rwops_testFileWrite(void *arg)
|
||||
#endif
|
||||
|
||||
/* Run generic tests */
|
||||
testGenericRWopsValidations(rw, 1);
|
||||
testGenericRWopsValidations(rw, SDL_TRUE);
|
||||
|
||||
/* Close handle */
|
||||
result = SDL_RWclose(rw);
|
||||
@@ -437,7 +437,7 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
|
||||
/* Read/seek from memory */
|
||||
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
|
||||
SDLTest_AssertPass("Call to SDL_RWFromMem()");
|
||||
rv_mem = (size_t)SDL_RWread(rwops_mem, buffer_mem, size * 6);
|
||||
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size * 6);
|
||||
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size * 6);
|
||||
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
|
||||
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
|
||||
@@ -448,7 +448,7 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
|
||||
/* Read/see from file */
|
||||
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile()");
|
||||
rv_file = (size_t)SDL_RWread(rwops_file, buffer_file, size * 6);
|
||||
rv_file = SDL_RWread(rwops_file, buffer_file, size * 6);
|
||||
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size * 6);
|
||||
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
|
||||
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
|
||||
@@ -477,15 +477,14 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
|
||||
*
|
||||
* \sa SDL_RWFromFile
|
||||
* \sa SDL_RWClose
|
||||
* \sa SDL_ReadBE16
|
||||
* \sa SDL_WriteBE16
|
||||
* \sa SDL_ReadU16BE
|
||||
* \sa SDL_WriteU16BE
|
||||
*/
|
||||
static int rwops_testFileWriteReadEndian(void *arg)
|
||||
{
|
||||
SDL_RWops *rw;
|
||||
Sint64 result;
|
||||
int mode;
|
||||
size_t objectsWritten;
|
||||
Uint16 BE16value;
|
||||
Uint32 BE32value;
|
||||
Uint64 BE64value;
|
||||
@@ -498,6 +497,7 @@ static int rwops_testFileWriteReadEndian(void *arg)
|
||||
Uint16 LE16test;
|
||||
Uint32 LE32test;
|
||||
Uint64 LE64test;
|
||||
SDL_bool bresult;
|
||||
int cresult;
|
||||
|
||||
for (mode = 0; mode < 3; mode++) {
|
||||
@@ -545,24 +545,24 @@ static int rwops_testFileWriteReadEndian(void *arg)
|
||||
}
|
||||
|
||||
/* Write test data */
|
||||
objectsWritten = SDL_WriteBE16(rw, BE16value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteBE16()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
|
||||
objectsWritten = SDL_WriteBE32(rw, BE32value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteBE32()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
|
||||
objectsWritten = SDL_WriteBE64(rw, BE64value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteBE64()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
|
||||
objectsWritten = SDL_WriteLE16(rw, LE16value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteLE16()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
|
||||
objectsWritten = SDL_WriteLE32(rw, LE32value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteLE32()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
|
||||
objectsWritten = SDL_WriteLE64(rw, LE64value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteLE64()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
|
||||
bresult = SDL_WriteU16BE(rw, BE16value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteU16BE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
bresult = SDL_WriteU32BE(rw, BE32value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteU32BE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
bresult = SDL_WriteU64BE(rw, BE64value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteU64BE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
bresult = SDL_WriteU16LE(rw, LE16value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteU16LE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
bresult = SDL_WriteU32LE(rw, LE32value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteU32LE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
bresult = SDL_WriteU64LE(rw, LE64value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteU64LE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
|
||||
/* Test seek to start */
|
||||
result = SDL_RWseek(rw, 0, SDL_RW_SEEK_SET);
|
||||
@@ -570,24 +570,30 @@ static int rwops_testFileWriteReadEndian(void *arg)
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", (int)result);
|
||||
|
||||
/* Read test data */
|
||||
BE16test = SDL_ReadBE16(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadBE16()");
|
||||
SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
|
||||
BE32test = SDL_ReadBE32(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadBE32()");
|
||||
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
|
||||
BE64test = SDL_ReadBE64(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadBE64()");
|
||||
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, BE64value, BE64test);
|
||||
LE16test = SDL_ReadLE16(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadLE16()");
|
||||
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
|
||||
LE32test = SDL_ReadLE32(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadLE32()");
|
||||
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
|
||||
LE64test = SDL_ReadLE64(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadLE64()");
|
||||
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, LE64value, LE64test);
|
||||
bresult = SDL_ReadU16BE(rw, &BE16test);
|
||||
SDLTest_AssertPass("Call to SDL_ReadU16BE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
SDLTest_AssertCheck(BE16test == BE16value, "Validate object read from SDL_ReadU16BE, expected: %hu, got: %hu", BE16value, BE16test);
|
||||
bresult = SDL_ReadU32BE(rw, &BE32test);
|
||||
SDLTest_AssertPass("Call to SDL_ReadU32BE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
SDLTest_AssertCheck(BE32test == BE32value, "Validate object read from SDL_ReadU32BE, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
|
||||
bresult = SDL_ReadU64BE(rw, &BE64test);
|
||||
SDLTest_AssertPass("Call to SDL_ReadU64BE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
SDLTest_AssertCheck(BE64test == BE64value, "Validate object read from SDL_ReadU64BE, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, BE64value, BE64test);
|
||||
bresult = SDL_ReadU16LE(rw, &LE16test);
|
||||
SDLTest_AssertPass("Call to SDL_ReadU16LE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
SDLTest_AssertCheck(LE16test == LE16value, "Validate object read from SDL_ReadU16LE, expected: %hu, got: %hu", LE16value, LE16test);
|
||||
bresult = SDL_ReadU32LE(rw, &LE32test);
|
||||
SDLTest_AssertPass("Call to SDL_ReadU32LE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
SDLTest_AssertCheck(LE32test == LE32value, "Validate object read from SDL_ReadU32LE, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
|
||||
bresult = SDL_ReadU64LE(rw, &LE64test);
|
||||
SDLTest_AssertPass("Call to SDL_ReadU64LE()");
|
||||
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
|
||||
SDLTest_AssertCheck(LE64test == LE64value, "Validate object read from SDL_ReadU64LE, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, LE64value, LE64test);
|
||||
|
||||
/* Close handle */
|
||||
cresult = SDL_RWclose(rw);
|
||||
|
||||
+60
-60
@@ -55,7 +55,7 @@ rwops_error_quit(unsigned line, SDL_RWops *rwops)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
|
||||
if (rwops) {
|
||||
rwops->close(rwops); /* This calls SDL_DestroyRW(rwops); */
|
||||
SDL_RWclose(rwops); /* This calls SDL_DestroyRW(rwops); */
|
||||
}
|
||||
cleanup();
|
||||
SDLTest_CommonDestroyState(state);
|
||||
@@ -126,25 +126,25 @@ int main(int argc, char *argv[])
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab");
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
unlink(FBASENAME2);
|
||||
SDL_Log("test2 OK\n");
|
||||
|
||||
@@ -155,110 +155,110 @@ int main(int argc, char *argv[])
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 7)) {
|
||||
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (-1 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
||||
}
|
||||
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exist */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
if (20 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 7)) {
|
||||
if (7 != SDL_RWread(rwops, test_buf, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
if (0 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (27 != rwops->read(rwops, test_buf, 30)) {
|
||||
if (27 != SDL_RWread(rwops, test_buf, 30)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (-1 != rwops->write(rwops, test_buf, 1)) {
|
||||
if (0 != SDL_RWwrite(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
||||
}
|
||||
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
|
||||
/* test 3: same with w+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 7)) {
|
||||
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (1 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (1 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
if (20 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 7)) {
|
||||
if (7 != SDL_RWread(rwops, test_buf, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
if (0 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (27 != rwops->read(rwops, test_buf, 30)) {
|
||||
if (27 != SDL_RWread(rwops, test_buf, 30)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
SDL_Log("test3 OK\n");
|
||||
|
||||
/* test 4: same in r+ mode */
|
||||
@@ -266,50 +266,50 @@ int main(int argc, char *argv[])
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 7)) {
|
||||
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (1 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (1 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
if (20 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 7)) {
|
||||
if (7 != SDL_RWread(rwops, test_buf, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
if (0 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (27 != rwops->read(rwops, test_buf, 30)) {
|
||||
if (27 != SDL_RWread(rwops, test_buf, 30)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
SDL_Log("test4 OK\n");
|
||||
|
||||
/* test5 : append mode */
|
||||
@@ -317,56 +317,56 @@ int main(int argc, char *argv[])
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
||||
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 7)) {
|
||||
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (1 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (1 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (20 + 27 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
if (20 + 27 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 7)) {
|
||||
if (7 != SDL_RWread(rwops, test_buf, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
||||
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (27 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
if (27 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (30 != rwops->read(rwops, test_buf, 30)) {
|
||||
if (30 != SDL_RWread(rwops, test_buf, 30)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_RWclose(rwops);
|
||||
SDL_Log("test5 OK\n");
|
||||
cleanup();
|
||||
SDLTest_CommonDestroyState(state);
|
||||
|
||||
+2
-9
@@ -108,7 +108,7 @@ static int unifont_init(const char *fontname)
|
||||
Uint8 hexBuffer[65];
|
||||
Uint32 numGlyphs = 0;
|
||||
int lineNumber = 1;
|
||||
Sint64 bytesRead;
|
||||
size_t bytesRead;
|
||||
SDL_RWops *hexFile;
|
||||
const size_t unifontGlyphSize = UNIFONT_NUM_GLYPHS * sizeof(struct UnifontGlyph);
|
||||
const size_t unifontTextureSize = UNIFONT_NUM_TEXTURES * state->num_windows * sizeof(void *);
|
||||
@@ -150,11 +150,6 @@ static int unifont_init(const char *fontname)
|
||||
Uint32 codepoint;
|
||||
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer, 9);
|
||||
if (bytesRead < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "error SDL_RWread\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (numGlyphs > 0 && bytesRead == 0) {
|
||||
break; /* EOF */
|
||||
}
|
||||
@@ -196,9 +191,7 @@ static int unifont_init(const char *fontname)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((size_t)bytesRead < (33 - bytesOverread)) {
|
||||
if (bytesRead < (33 - bytesOverread)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
+13
-13
@@ -126,19 +126,19 @@ int main(int argc, char **argv)
|
||||
blockalign = (bitsize / 8) * cvtspec.channels;
|
||||
avgbytes = cvtspec.freq * blockalign;
|
||||
|
||||
SDL_WriteLE32(io, 0x46464952); /* RIFF */
|
||||
SDL_WriteLE32(io, dst_len + 36);
|
||||
SDL_WriteLE32(io, 0x45564157); /* WAVE */
|
||||
SDL_WriteLE32(io, 0x20746D66); /* fmt */
|
||||
SDL_WriteLE32(io, 16); /* chunk size */
|
||||
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
|
||||
SDL_WriteLE16(io, cvtspec.channels); /* channels */
|
||||
SDL_WriteLE32(io, cvtspec.freq); /* sample rate */
|
||||
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
|
||||
SDL_WriteLE16(io, blockalign); /* block align */
|
||||
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
|
||||
SDL_WriteLE32(io, 0x61746164); /* data */
|
||||
SDL_WriteLE32(io, dst_len); /* size */
|
||||
SDL_WriteU32LE(io, 0x46464952); /* RIFF */
|
||||
SDL_WriteU32LE(io, dst_len + 36);
|
||||
SDL_WriteU32LE(io, 0x45564157); /* WAVE */
|
||||
SDL_WriteU32LE(io, 0x20746D66); /* fmt */
|
||||
SDL_WriteU32LE(io, 16); /* chunk size */
|
||||
SDL_WriteU16LE(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
|
||||
SDL_WriteU16LE(io, cvtspec.channels); /* channels */
|
||||
SDL_WriteU32LE(io, cvtspec.freq); /* sample rate */
|
||||
SDL_WriteU32LE(io, avgbytes); /* average bytes per second */
|
||||
SDL_WriteU16LE(io, blockalign); /* block align */
|
||||
SDL_WriteU16LE(io, bitsize); /* significant bits per sample */
|
||||
SDL_WriteU32LE(io, 0x61746164); /* data */
|
||||
SDL_WriteU32LE(io, dst_len); /* size */
|
||||
SDL_RWwrite(io, dst_buf, dst_len);
|
||||
|
||||
if (SDL_RWclose(io) == -1) {
|
||||
|
||||
Reference in New Issue
Block a user