@@ -535,137 +535,6 @@ windows_file_close(SDL_RWops * context)
535
535
}
536
536
#endif /* __WIN32__ */
537
537
538
- #ifdef HAVE_STDIO_H
539
-
540
- #ifdef HAVE_FOPEN64
541
- #define fopen fopen64
542
- #endif
543
- #ifdef HAVE_FSEEKO64
544
- #define fseek_off_t off64_t
545
- #define fseek fseeko64
546
- #define ftell ftello64
547
- #elif defined(HAVE_FSEEKO )
548
- #if defined(OFF_MIN ) && defined(OFF_MAX )
549
- #define FSEEK_OFF_MIN OFF_MIN
550
- #define FSEEK_OFF_MAX OFF_MAX
551
- #elif defined(HAVE_LIMITS_H )
552
- /* POSIX doesn't specify the minimum and maximum macros for off_t so
553
- * we have to improvise and dance around implementation-defined
554
- * behavior. This may fail if the off_t type has padding bits or
555
- * is not a two's-complement representation. The compilers will detect
556
- * and eliminate the dead code if off_t has 64 bits.
557
- */
558
- #define FSEEK_OFF_MAX (((((off_t)1 << (sizeof(off_t) * CHAR_BIT - 2)) - 1) << 1) + 1)
559
- #define FSEEK_OFF_MIN (-(FSEEK_OFF_MAX) - 1)
560
- #endif
561
- #define fseek_off_t off_t
562
- #define fseek fseeko
563
- #define ftell ftello
564
- #elif defined(HAVE__FSEEKI64 )
565
- #define fseek_off_t __int64
566
- #define fseek _fseeki64
567
- #define ftell _ftelli64
568
- #else
569
- #ifdef HAVE_LIMITS_H
570
- #define FSEEK_OFF_MIN LONG_MIN
571
- #define FSEEK_OFF_MAX LONG_MAX
572
- #endif
573
- #define fseek_off_t long
574
- #endif
575
-
576
- /* Functions to read/write stdio file pointers */
577
-
578
- static Sint64 SDLCALL
579
- stdio_size (SDL_RWops * context )
580
- {
581
- Sint64 pos , size ;
582
-
583
- pos = SDL_RWseek (context , 0 , RW_SEEK_CUR );
584
- if (pos < 0 ) {
585
- return -1 ;
586
- }
587
- size = SDL_RWseek (context , 0 , RW_SEEK_END );
588
-
589
- SDL_RWseek (context , pos , RW_SEEK_SET );
590
- return size ;
591
- }
592
-
593
- static Sint64 SDLCALL
594
- stdio_seek (SDL_RWops * context , Sint64 offset , int whence )
595
- {
596
- int stdiowhence ;
597
-
598
- switch (whence ) {
599
- case RW_SEEK_SET :
600
- stdiowhence = SEEK_SET ;
601
- break ;
602
- case RW_SEEK_CUR :
603
- stdiowhence = SEEK_CUR ;
604
- break ;
605
- case RW_SEEK_END :
606
- stdiowhence = SEEK_END ;
607
- break ;
608
- default :
609
- return SDL_SetError ("Unknown value for 'whence'" );
610
- }
611
-
612
- #if defined(FSEEK_OFF_MIN ) && defined(FSEEK_OFF_MAX )
613
- if (offset < (Sint64 )(FSEEK_OFF_MIN ) || offset > (Sint64 )(FSEEK_OFF_MAX )) {
614
- return SDL_SetError ("Seek offset out of range" );
615
- }
616
- #endif
617
-
618
- if (fseek (context -> hidden .stdio .fp , (fseek_off_t )offset , stdiowhence ) == 0 ) {
619
- Sint64 pos = ftell (context -> hidden .stdio .fp );
620
- if (pos < 0 ) {
621
- return SDL_SetError ("Couldn't get stream offset" );
622
- }
623
- return pos ;
624
- }
625
- return SDL_Error (SDL_EFSEEK );
626
- }
627
-
628
- static size_t SDLCALL
629
- stdio_read (SDL_RWops * context , void * ptr , size_t size , size_t maxnum )
630
- {
631
- size_t nread ;
632
-
633
- nread = fread (ptr , size , maxnum , context -> hidden .stdio .fp );
634
- if (nread == 0 && ferror (context -> hidden .stdio .fp )) {
635
- SDL_Error (SDL_EFREAD );
636
- }
637
- return nread ;
638
- }
639
-
640
- static size_t SDLCALL
641
- stdio_write (SDL_RWops * context , const void * ptr , size_t size , size_t num )
642
- {
643
- size_t nwrote ;
644
-
645
- nwrote = fwrite (ptr , size , num , context -> hidden .stdio .fp );
646
- if (nwrote == 0 && ferror (context -> hidden .stdio .fp )) {
647
- SDL_Error (SDL_EFWRITE );
648
- }
649
- return nwrote ;
650
- }
651
-
652
- static int SDLCALL
653
- stdio_close (SDL_RWops * context )
654
- {
655
- int status = 0 ;
656
- if (context ) {
657
- if (context -> hidden .stdio .autoclose ) {
658
- /* WARNING: Check the return value here! */
659
- if (fclose (context -> hidden .stdio .fp ) != 0 ) {
660
- status = SDL_Error (SDL_EFWRITE );
661
- }
662
- }
663
- SDL_FreeRW (context );
664
- }
665
- return status ;
666
- }
667
- #endif /* !HAVE_STDIO_H */
668
-
669
538
/* Functions to read/write memory pointers */
670
539
671
540
static Sint64 SDLCALL
@@ -755,133 +624,6 @@ mem_close(SDL_RWops * context)
755
624
756
625
/* Functions to create SDL_RWops structures from various data sources */
757
626
758
- SDL_RWops *
759
- SDL_RWFromFile (const char * file , const char * mode )
760
- {
761
- SDL_RWops * rwops = NULL ;
762
- if (!file || !* file || !mode || !* mode ) {
763
- SDL_SetError ("SDL_RWFromFile(): No file or no mode specified" );
764
- return NULL ;
765
- }
766
- #if defined(__ANDROID__ )
767
- #ifdef HAVE_STDIO_H
768
- /* Try to open the file on the filesystem first */
769
- if (* file == '/' ) {
770
- FILE * fp = fopen (file , mode );
771
- if (fp ) {
772
- return SDL_RWFromFP (fp , 1 );
773
- }
774
- } else {
775
- /* Try opening it from internal storage if it's a relative path */
776
- char * path ;
777
- FILE * fp ;
778
-
779
- /* !!! FIXME: why not just "char path[PATH_MAX];" ? */
780
- path = SDL_stack_alloc (char , PATH_MAX );
781
- if (path ) {
782
- SDL_snprintf (path , PATH_MAX , "%s/%s" ,
783
- SDL_AndroidGetInternalStoragePath (), file );
784
- fp = fopen (path , mode );
785
- SDL_stack_free (path );
786
- if (fp ) {
787
- return SDL_RWFromFP (fp , 1 );
788
- }
789
- }
790
- }
791
- #endif /* HAVE_STDIO_H */
792
-
793
- /* Try to open the file from the asset system */
794
- rwops = SDL_AllocRW ();
795
- if (!rwops )
796
- return NULL ; /* SDL_SetError already setup by SDL_AllocRW() */
797
- if (Android_JNI_FileOpen (rwops , file , mode ) < 0 ) {
798
- SDL_FreeRW (rwops );
799
- return NULL ;
800
- }
801
- rwops -> size = Android_JNI_FileSize ;
802
- rwops -> seek = Android_JNI_FileSeek ;
803
- rwops -> read = Android_JNI_FileRead ;
804
- rwops -> write = Android_JNI_FileWrite ;
805
- rwops -> close = Android_JNI_FileClose ;
806
- rwops -> type = SDL_RWOPS_JNIFILE ;
807
-
808
- #elif defined(__WIN32__ )
809
- rwops = SDL_AllocRW ();
810
- if (!rwops )
811
- return NULL ; /* SDL_SetError already setup by SDL_AllocRW() */
812
- if (windows_file_open (rwops , file , mode ) < 0 ) {
813
- SDL_FreeRW (rwops );
814
- return NULL ;
815
- }
816
- rwops -> size = windows_file_size ;
817
- rwops -> seek = windows_file_seek ;
818
- rwops -> read = windows_file_read ;
819
- rwops -> write = windows_file_write ;
820
- rwops -> close = windows_file_close ;
821
- rwops -> type = SDL_RWOPS_WINFILE ;
822
- #elif defined(__VITA__ )
823
- rwops = SDL_AllocRW ();
824
- if (!rwops )
825
- return NULL ; /* SDL_SetError already setup by SDL_AllocRW() */
826
- if (vita_file_open (rwops , file , mode ) < 0 ) {
827
- SDL_FreeRW (rwops );
828
- return NULL ;
829
- }
830
- rwops -> size = vita_file_size ;
831
- rwops -> seek = vita_file_seek ;
832
- rwops -> read = vita_file_read ;
833
- rwops -> write = vita_file_write ;
834
- rwops -> close = vita_file_close ;
835
- rwops -> type = SDL_RWOPS_VITAFILE ;
836
- #elif HAVE_STDIO_H
837
- {
838
- #if __WINRT__
839
- FILE * fp = NULL ;
840
- fopen_s (& fp , file , mode );
841
- #else
842
- FILE * fp = fopen (file , mode );
843
- #endif
844
- if (fp == NULL ) {
845
- SDL_SetError ("Couldn't open %s" , file );
846
- } else {
847
- rwops = SDL_RWFromFP (fp , SDL_TRUE );
848
- }
849
- }
850
- #else
851
- SDL_SetError ("SDL not compiled with stdio support" );
852
- #endif /* !HAVE_STDIO_H */
853
-
854
- return rwops ;
855
- }
856
-
857
- #ifdef HAVE_STDIO_H
858
- SDL_RWops *
859
- SDL_RWFromFP (FILE * fp , SDL_bool autoclose )
860
- {
861
- SDL_RWops * rwops = NULL ;
862
-
863
- rwops = SDL_AllocRW ();
864
- if (rwops != NULL ) {
865
- rwops -> size = stdio_size ;
866
- rwops -> seek = stdio_seek ;
867
- rwops -> read = stdio_read ;
868
- rwops -> write = stdio_write ;
869
- rwops -> close = stdio_close ;
870
- rwops -> hidden .stdio .fp = fp ;
871
- rwops -> hidden .stdio .autoclose = autoclose ;
872
- rwops -> type = SDL_RWOPS_STDFILE ;
873
- }
874
- return rwops ;
875
- }
876
- #else
877
- SDL_RWops *
878
- SDL_RWFromFP (void * fp , SDL_bool autoclose )
879
- {
880
- SDL_SetError ("SDL not compiled with stdio support" );
881
- return NULL ;
882
- }
883
- #endif /* HAVE_STDIO_H */
884
-
885
627
SDL_RWops *
886
628
SDL_RWFromMem (void * mem , int size )
887
629
{
@@ -1011,12 +753,6 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
1011
753
return data ;
1012
754
}
1013
755
1014
- void *
1015
- SDL_LoadFile (const char * file , size_t * datasize )
1016
- {
1017
- return SDL_LoadFile_RW (SDL_RWFromFile (file , "rb" ), datasize , 1 );
1018
- }
1019
-
1020
756
Sint64
1021
757
SDL_RWsize (SDL_RWops * context )
1022
758
{
0 commit comments