mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-27 10:51:54 +00: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:
@@ -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);
|
||||
|
||||
120
test/testfile.c
120
test/testfile.c
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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