rwops: Make read and write work like POSIX, not stdio.
This simplifies some things, clarifies some things, and also allows for the possibility of RWops that offer non-blocking i/o (although none of the current built-in ones do, intentionally, we could add this later if we choose, or people could provide things like network socket RWops implementations now, etc. Fixes #6729.
This commit is contained in:
@@ -99,7 +99,7 @@ void _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
{
|
||||
char buf[sizeof(RWopsHelloWorldTestString)];
|
||||
Sint64 i;
|
||||
size_t s;
|
||||
Sint64 s;
|
||||
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
|
||||
|
||||
/* Clear buffer */
|
||||
@@ -111,12 +111,12 @@ void _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
|
||||
|
||||
/* Test write. */
|
||||
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString) - 1, 1);
|
||||
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString) - 1);
|
||||
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
|
||||
if (write) {
|
||||
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int)s);
|
||||
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 == (size_t)0, "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 */
|
||||
@@ -130,7 +130,7 @@ void _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
|
||||
|
||||
/* Test read */
|
||||
s = SDL_RWread(rw, buf, 1, sizeof(RWopsHelloWorldTestString) - 1);
|
||||
s = SDL_RWread(rw, buf, sizeof(RWopsHelloWorldTestString) - 1);
|
||||
SDLTest_AssertPass("Call to SDL_RWread succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
s == (size_t)(sizeof(RWopsHelloWorldTestString) - 1),
|
||||
@@ -440,8 +440,8 @@ int rwops_testCompareRWFromMemWithRWFromFile(void)
|
||||
/* Read/seek from memory */
|
||||
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
|
||||
SDLTest_AssertPass("Call to SDL_RWFromMem()");
|
||||
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
|
||||
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
|
||||
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)");
|
||||
result = SDL_RWclose(rwops_mem);
|
||||
@@ -451,8 +451,8 @@ int rwops_testCompareRWFromMemWithRWFromFile(void)
|
||||
/* Read/see from file */
|
||||
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile()");
|
||||
rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
|
||||
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
|
||||
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)");
|
||||
result = SDL_RWclose(rwops_file);
|
||||
|
||||
@@ -145,7 +145,7 @@ static int unifont_init(const char *fontname)
|
||||
Uint8 glyphWidth;
|
||||
Uint32 codepoint;
|
||||
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer, 1, 9);
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer, 9);
|
||||
if (numGlyphs > 0 && bytesRead == 0) {
|
||||
break; /* EOF */
|
||||
}
|
||||
@@ -181,7 +181,7 @@ static int unifont_init(const char *fontname)
|
||||
if (codepointHexSize < 8) {
|
||||
SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread);
|
||||
}
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread);
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 33 - bytesOverread);
|
||||
if (bytesRead < (33 - bytesOverread)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
@@ -190,7 +190,7 @@ static int unifont_init(const char *fontname)
|
||||
glyphWidth = 8;
|
||||
} else {
|
||||
glyphWidth = 16;
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 1, 32);
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 32);
|
||||
if (bytesRead < 32) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
|
||||
@@ -420,7 +420,7 @@ int main(int argc, char **argv)
|
||||
quit(2);
|
||||
}
|
||||
|
||||
SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
|
||||
SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
||||
|
||||
SDL_RWclose(handle);
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ int main(int argc, char **argv)
|
||||
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
|
||||
SDL_WriteLE32(io, 0x61746164); /* data */
|
||||
SDL_WriteLE32(io, cvt.len_cvt); /* size */
|
||||
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
|
||||
SDL_RWwrite(io, cvt.buf, cvt.len_cvt);
|
||||
|
||||
if (SDL_RWclose(io) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
|
||||
|
||||
@@ -150,7 +150,7 @@ int main(int argc, char **argv)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
|
||||
quit(2);
|
||||
}
|
||||
SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
|
||||
SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
||||
SDL_RWclose(handle);
|
||||
|
||||
/* Create the window and renderer */
|
||||
|
||||
Reference in New Issue
Block a user