1.1 Binary file VisualC.zip has changed
2.1 --- a/include/SDL_rwops.h Mon Feb 27 18:58:12 2006 +0000
2.2 +++ b/include/SDL_rwops.h Mon Feb 27 19:19:22 2006 +0000
2.3 @@ -64,7 +64,6 @@
2.4 union {
2.5 #ifdef __WIN32__
2.6 struct {
2.7 - int autoclose;
2.8 int append;
2.9 void* h;
2.10 } win32io;
3.1 --- a/src/file/SDL_rwops.c Mon Feb 27 18:58:12 2006 +0000
3.2 +++ b/src/file/SDL_rwops.c Mon Feb 27 19:19:22 2006 +0000
3.3 @@ -59,8 +59,8 @@
3.4 must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0;
3.5 truncate = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0;
3.6 r_right = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0;
3.7 - a_mode = ( SDL_strchr(mode,'a') != NULL );
3.8 - w_right = ( a_mode || SDL_strchr(mode,'w') || truncate ) ? GENERIC_WRITE : 0;
3.9 + a_mode = ( SDL_strchr(mode,'a') != NULL ) ? OPEN_ALWAYS : 0;
3.10 + w_right = ( a_mode || SDL_strchr(mode,'+') || truncate ) ? GENERIC_WRITE : 0;
3.11
3.12 if (!r_right && !w_right) /* inconsistent mode */
3.13 return -1; /* failed (invalid call)*/
3.14 @@ -69,7 +69,7 @@
3.15 old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
3.16
3.17 h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ,
3.18 - NULL, (must_exist|truncate), FILE_ATTRIBUTE_NORMAL,NULL);
3.19 + NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
3.20
3.21 /* restore old behaviour */
3.22 SetErrorMode(old_error_mode);
3.23 @@ -338,6 +338,8 @@
3.24
3.25 #ifdef __WIN32__
3.26 rwops = SDL_AllocRW();
3.27 + if (!rwops)
3.28 + return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
3.29 rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
3.30 if (win32_file_open(rwops,file,mode)) {
3.31 SDL_FreeRW(rwops);
4.1 --- a/test/Makefile.in Mon Feb 27 18:58:12 2006 +0000
4.2 +++ b/test/Makefile.in Mon Feb 27 19:19:22 2006 +0000
4.3 @@ -7,7 +7,7 @@
4.4 CFLAGS = @CFLAGS@
4.5 LIBS = @LIBS@
4.6
4.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testdyngl$(EXE) testerror$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
4.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
4.9
4.10 all: $(TARGETS)
4.11
4.12 @@ -38,6 +38,9 @@
4.13 testerror$(EXE): $(srcdir)/testerror.c
4.14 $(CC) -o $@ $? $(CFLAGS) $(LIBS)
4.15
4.16 +testfile$(EXE): $(srcdir)/testfile.c
4.17 + $(CC) -o $@ $? $(CFLAGS) $(LIBS)
4.18 +
4.19 testgamma$(EXE): $(srcdir)/testgamma.c
4.20 $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
4.21
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/test/testfile.c Mon Feb 27 19:19:22 2006 +0000
5.3 @@ -0,0 +1,178 @@
5.4 +
5.5 +/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
5.6 +
5.7 +
5.8 +
5.9 +#include "SDL.h"
5.10 +#include "SDL_endian.h"
5.11 +
5.12 +
5.13 +#include <stdio.h>
5.14 +
5.15 +/* WARNING ! those 2 files will be destroyed by this test program */
5.16 +#define FBASENAME1 "sdldata1" /* this file will be created during tests */
5.17 +#define FBASENAME2 "sdldata2" /* this file should not exists before starting test */
5.18 +
5.19 +
5.20 +#ifndef NULL
5.21 +#define NULL ((void *)0)
5.22 +#endif
5.23 +
5.24 +static void cleanup( void ) {
5.25 +
5.26 + unlink(FBASENAME1);
5.27 + unlink(FBASENAME2);
5.28 +}
5.29 +
5.30 +static void rwops_error_quit( unsigned line, SDL_RWops *rwops) {
5.31 +
5.32 + printf("testfile.c(%d): failed\n",line);
5.33 + if (rwops) {
5.34 + rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
5.35 + }
5.36 + cleanup();
5.37 + exit(1); /* quit with rwops error (test failed) */
5.38 +}
5.39 +
5.40 +#define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) )
5.41 +
5.42 +
5.43 +
5.44 +int main(int argc, char *argv[])
5.45 +{
5.46 + SDL_RWops *rwops = NULL;
5.47 + char test_buf[30];
5.48 +
5.49 + cleanup();
5.50 +
5.51 +/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
5.52 +
5.53 + rwops = SDL_RWFromFile(NULL,NULL);
5.54 + if (rwops) RWOP_ERR_QUIT(rwops);
5.55 + rwops = SDL_RWFromFile(NULL,"a+" WIN32_FILE_MODE);
5.56 + if (rwops) RWOP_ERR_QUIT(rwops);
5.57 + rwops = SDL_RWFromFile(NULL,"sldfkjsldkfj");
5.58 + if (rwops) RWOP_ERR_QUIT(rwops);
5.59 + rwops = SDL_RWFromFile("something","");
5.60 + if (rwops) RWOP_ERR_QUIT(rwops);
5.61 + rwops = SDL_RWFromFile("something",NULL);
5.62 + if (rwops) RWOP_ERR_QUIT(rwops);
5.63 + printf("test1 OK\n");
5.64 +
5.65 +/* test 2 : check that inexistant file is not successfully opened/created when required */
5.66 +/* modes : r, r+ implie that file MUST exist
5.67 + modes : a, a+, w, w+ checks that it succeeds (file may not exists)
5.68 +
5.69 + */
5.70 + rwops = SDL_RWFromFile(FBASENAME2,"rb"); /* this file doesn't exist that call must fail */
5.71 + if (rwops) RWOP_ERR_QUIT(rwops);
5.72 + rwops = SDL_RWFromFile(FBASENAME2,"rb+"); /* this file doesn't exist that call must fail */
5.73 + if (rwops) RWOP_ERR_QUIT(rwops);
5.74 + rwops = SDL_RWFromFile(FBASENAME2,"wb");
5.75 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.76 + rwops->close(rwops); unlink(FBASENAME2);
5.77 + rwops = SDL_RWFromFile(FBASENAME2,"wb+");
5.78 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.79 + rwops->close(rwops); unlink(FBASENAME2);
5.80 + rwops = SDL_RWFromFile(FBASENAME2,"ab");
5.81 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.82 + rwops->close(rwops); unlink(FBASENAME2);
5.83 + rwops = SDL_RWFromFile(FBASENAME2,"ab+");
5.84 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.85 + rwops->close(rwops); unlink(FBASENAME2);
5.86 + printf("test2 OK\n");
5.87 +
5.88 +/* test 3 : creation, writing , reading, seeking,
5.89 + test : w mode, r mode, w+ mode
5.90 + */
5.91 + rwops = SDL_RWFromFile(FBASENAME1,"wb"); /* write only */
5.92 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.93 + if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
5.94 + if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
5.95 + if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
5.96 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.97 + if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in write only mode */
5.98 + rwops->close(rwops);
5.99 +
5.100 + rwops = SDL_RWFromFile(FBASENAME1,"rb"); /* read mode, file must exists */
5.101 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.102 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.103 + if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
5.104 + if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
5.105 + if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
5.106 + if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
5.107 + if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
5.108 + if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
5.109 + if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
5.110 + if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops);
5.111 + if (0!=rwops->write(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* readonly mode */
5.112 + rwops->close(rwops);
5.113 +
5.114 +/* test 3: same with w+ mode */
5.115 + rwops = SDL_RWFromFile(FBASENAME1,"wb+"); /* write + read + truncation */
5.116 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.117 + if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
5.118 + if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
5.119 + if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
5.120 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.121 + if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
5.122 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.123 + if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
5.124 + if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
5.125 + if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
5.126 + if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
5.127 + if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
5.128 + if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
5.129 + if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
5.130 + if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops);
5.131 + rwops->close(rwops);
5.132 + printf("test3 OK\n");
5.133 +
5.134 +/* test 4: same in r+ mode */
5.135 + rwops = SDL_RWFromFile(FBASENAME1,"rb+"); /* write + read + file must exists, no truncation */
5.136 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.137 + if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
5.138 + if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
5.139 + if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
5.140 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.141 + if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
5.142 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.143 + if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
5.144 + if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
5.145 + if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
5.146 + if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
5.147 + if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
5.148 + if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
5.149 + if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
5.150 + if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops);
5.151 + rwops->close(rwops);
5.152 + printf("test4 OK\n");
5.153 +
5.154 +/* test5 : append mode */
5.155 + rwops = SDL_RWFromFile(FBASENAME1,"ab+"); /* write + read + append */
5.156 + if (!rwops) RWOP_ERR_QUIT(rwops);
5.157 + if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
5.158 + if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
5.159 + if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
5.160 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.161 +
5.162 + if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
5.163 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.164 +
5.165 + if (20+27!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
5.166 + if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
5.167 + if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
5.168 + if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
5.169 + if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
5.170 +
5.171 + if (27!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
5.172 +
5.173 + if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
5.174 + if (3!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
5.175 + if (SDL_memcmp(test_buf,"123456789012345678901234567123",30))
5.176 + RWOP_ERR_QUIT(rwops);
5.177 + rwops->close(rwops);
5.178 + printf("test5 OK\n");
5.179 + cleanup();
5.180 + return 0; /* all ok */
5.181 +}