Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 20 Aug 2013 19:57:11 -0400
changeset 7667be1cc6f55840
parent 7666 603fb699946c
child 7668 66da4242ce53
Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module.
.hgignore
Android.mk
CMakeLists.txt
Makefile.in
Makefile.minimal
Makefile.pandora
Makefile.psp
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
VisualC/SDL/SDL_VS2012.vcxproj
configure
configure.in
include/SDL.h
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_config_android.h
include/SDL_config_iphoneos.h
include/SDL_config_macosx.h
include/SDL_config_minimal.h
include/SDL_config_pandora.h
include/SDL_config_psp.h
include/SDL_config_windows.h
include/SDL_filesystem.h
src/filesystem/beos/SDL_sysfilesystem.cc
src/filesystem/cocoa/SDL_sysfilesystem.m
src/filesystem/dummy/SDL_sysfilesystem.c
src/filesystem/unix/SDL_sysfilesystem.c
src/filesystem/windows/SDL_sysfilesystem.c
test/Makefile.in
test/testfilesystem.c
     1.1 --- a/.hgignore	Tue Aug 20 15:28:14 2013 -0400
     1.2 +++ b/.hgignore	Tue Aug 20 19:57:11 2013 -0400
     1.3 @@ -76,6 +76,7 @@
     1.4  test/testoverlay2
     1.5  test/testplatform
     1.6  test/testpower
     1.7 +test/testfilesystem
     1.8  test/testrelative
     1.9  test/testrendercopyex
    1.10  test/testrendertarget
     2.1 --- a/Android.mk	Tue Aug 20 15:28:14 2013 -0400
     2.2 +++ b/Android.mk	Tue Aug 20 19:57:11 2013 -0400
     2.3 @@ -33,6 +33,7 @@
     2.4  	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
     2.5  	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
     2.6  	$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
     2.7 +	$(wildcard $(LOCAL_PATH)/src/filesystem/dummy/*.c) \
     2.8  	$(wildcard $(LOCAL_PATH)/src/render/*.c) \
     2.9  	$(wildcard $(LOCAL_PATH)/src/render/*/*.c) \
    2.10  	$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
     3.1 --- a/CMakeLists.txt	Tue Aug 20 15:28:14 2013 -0400
     3.2 +++ b/CMakeLists.txt	Tue Aug 20 19:57:11 2013 -0400
     3.3 @@ -172,7 +172,7 @@
     3.4  
     3.5  set(SDL_SUBSYSTEMS
     3.6      Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
     3.7 -    File Loadso CPUinfo)
     3.8 +    File Loadso CPUinfo Filesystem)
     3.9  foreach(_SUB ${SDL_SUBSYSTEMS})
    3.10    string(TOUPPER ${_SUB} _OPT)
    3.11    option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ON)
    3.12 @@ -714,6 +714,13 @@
    3.13      endif(LINUX)
    3.14    endif(SDL_POWER)
    3.15  
    3.16 +  if(SDL_FILESYSTEM)
    3.17 +    set(SDL_FILESYSTEM_UNIX 1)
    3.18 +    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/unix/*.c)
    3.19 +    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
    3.20 +    set(HAVE_SDL_FILESYSTEM TRUE)
    3.21 +  endif(SDL_FILESYSTEM)
    3.22 +
    3.23    if(SDL_TIMERS)
    3.24      set(SDL_TIMER_UNIX 1)
    3.25      file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
    3.26 @@ -814,6 +821,13 @@
    3.27      set(HAVE_SDL_POWER TRUE)
    3.28    endif(SDL_POWER)
    3.29  
    3.30 +  if(SDL_FILESYSTEM)
    3.31 +    set(SDL_FILESYSTEM_WINDOWS 1)
    3.32 +    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesytem/windows/*.c)
    3.33 +    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
    3.34 +    set(HAVE_SDL_FILESYSTEM TRUE)
    3.35 +  endif(SDL_FILESYSTEM)
    3.36 +
    3.37    # Libraries for Win32 native and MinGW
    3.38    list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
    3.39  
    3.40 @@ -924,6 +938,13 @@
    3.41      set(SDL_FRAMEWORK_IOKIT 1)
    3.42    endif()
    3.43  
    3.44 +  if(SDL_FILESYSTEM)
    3.45 +    set(SDL_FILESYSTEM_COCOA 1)
    3.46 +    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
    3.47 +    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
    3.48 +    set(HAVE_SDL_FILESYSTEM TRUE)
    3.49 +  endif()
    3.50 +
    3.51    # Actually load the frameworks at the end so we don't duplicate include.
    3.52    if(SDL_FRAMEWORK_COCOA)
    3.53      find_library(COCOA_LIBRARY Cocoa)
    3.54 @@ -973,6 +994,11 @@
    3.55      set(SOURCE_FILES ${SOURCE_FILES} ${BWINDOW_SOURCES})
    3.56      set(HAVE_SDL_VIDEO TRUE)
    3.57  
    3.58 +    set(SDL_FILESYSTEM_BEOS 1)
    3.59 +    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/beos/*.cc)
    3.60 +    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
    3.61 +    set(HAVE_SDL_FILESYSTEM TRUE)
    3.62 +
    3.63      if(VIDEO_OPENGL)
    3.64        # TODO: Use FIND_PACKAGE(OpenGL) instead
    3.65        set(SDL_VIDEO_OPENGL 1)
    3.66 @@ -1010,6 +1036,11 @@
    3.67    file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
    3.68    set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
    3.69  endif(NOT HAVE_SDL_LOADSO)
    3.70 +if(NOT HAVE_SDL_FILESYSTEM)
    3.71 +  set(SDL_FILESYSTEM_DISABLED 1)
    3.72 +  file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
    3.73 +  set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
    3.74 +endif(NOT HAVE_SDL_FILESYSTEM)
    3.75  
    3.76  # We always need to have threads and timers around
    3.77  if(NOT HAVE_SDL_THREADS)
     4.1 --- a/Makefile.in	Tue Aug 20 15:28:14 2013 -0400
     4.2 +++ b/Makefile.in	Tue Aug 20 19:57:11 2013 -0400
     4.3 @@ -54,6 +54,7 @@
     4.4  	SDL_endian.h \
     4.5  	SDL_error.h \
     4.6  	SDL_events.h \
     4.7 +	SDL_filesystem.h \
     4.8  	SDL_gamecontroller.h \
     4.9  	SDL_gesture.h \
    4.10  	SDL_haptic.h \
     5.1 --- a/Makefile.minimal	Tue Aug 20 15:28:14 2013 -0400
     5.2 +++ b/Makefile.minimal	Tue Aug 20 19:57:11 2013 -0400
     5.3 @@ -19,6 +19,7 @@
     5.4  	src/joystick/dummy/*.c \
     5.5  	src/loadso/dummy/*.c \
     5.6  	src/power/*.c \
     5.7 +	src/filesystem/dummy/*.c \
     5.8  	src/render/*.c \
     5.9  	src/render/software/*.c \
    5.10  	src/stdlib/*.c \
     6.1 --- a/Makefile.pandora	Tue Aug 20 15:28:14 2013 -0400
     6.2 +++ b/Makefile.pandora	Tue Aug 20 19:57:11 2013 -0400
     6.3 @@ -19,7 +19,7 @@
     6.4  	./src/thread/pthread/SDL_systhread.c ./src/thread/pthread/SDL_syssem.c \
     6.5  	./src/thread/pthread/SDL_sysmutex.c ./src/thread/pthread/SDL_syscond.c \
     6.6  	./src/joystick/linux/*.c ./src/haptic/linux/*.c ./src/timer/unix/*.c \
     6.7 -	./src/atomic/linux/*.c \
     6.8 +	./src/atomic/linux/*.c ./src/filesystem/unix/*.c \
     6.9  	./src/video/pandora/SDL_pandora.o ./src/video/pandora/SDL_pandora_events.o ./src/video/x11/*.c 
    6.10  	
    6.11  
     7.1 --- a/Makefile.psp	Tue Aug 20 15:28:14 2013 -0400
     7.2 +++ b/Makefile.psp	Tue Aug 20 19:57:11 2013 -0400
     7.3 @@ -31,6 +31,7 @@
     7.4        src/joystick/psp/SDL_sysjoystick.o \
     7.5        src/power/SDL_power.o \
     7.6        src/power/psp/SDL_syspower.o \
     7.7 +      src/filesystem/dummy/SDL_sysfilesystem.o \
     7.8        src/render/SDL_render.o \
     7.9        src/render/SDL_yuv_sw.o \
    7.10        src/render/psp/SDL_render_psp.o \
     8.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Tue Aug 20 15:28:14 2013 -0400
     8.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Tue Aug 20 19:57:11 2013 -0400
     8.3 @@ -428,6 +428,10 @@
     8.4  				>
     8.5  			</File>
     8.6  			<File
     8.7 +				RelativePath="..\..\include\SDL_filesystem.h"
     8.8 +				>
     8.9 +			</File>
    8.10 +			<File
    8.11  				RelativePath="..\..\include\SDL_gamecontroller.h"
    8.12  				>
    8.13  			</File>
    8.14 @@ -1089,6 +1093,10 @@
    8.15  			>
    8.16  		</File>
    8.17  		<File
    8.18 +			RelativePath="..\..\src\filesystem\windows\SDL_sysfilesystem.c"
    8.19 +			>
    8.20 +		</File>
    8.21 +		<File
    8.22  			RelativePath="..\..\src\haptic\windows\SDL_syshaptic.c"
    8.23  			>
    8.24  		</File>
     9.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Tue Aug 20 15:28:14 2013 -0400
     9.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Tue Aug 20 19:57:11 2013 -0400
     9.3 @@ -229,6 +229,7 @@
     9.4      <ClInclude Include="..\..\include\SDL_endian.h" />
     9.5      <ClInclude Include="..\..\include\SDL_error.h" />
     9.6      <ClInclude Include="..\..\include\SDL_events.h" />
     9.7 +    <ClInclude Include="..\..\include\SDL_filesystem.h" />
     9.8      <ClInclude Include="..\..\include\SDL_gesture.h" />
     9.9      <ClInclude Include="..\..\include\SDL_haptic.h" />
    9.10      <ClInclude Include="..\..\include\SDL_hints.h" />
    9.11 @@ -430,6 +431,7 @@
    9.12      <ClCompile Include="..\..\src\stdlib\SDL_string.c" />
    9.13      <ClCompile Include="..\..\src\video\SDL_surface.c" />
    9.14      <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
    9.15 +    <ClCompile Include="..\..\src\filesystem\windows\SDL_sysfilesystem.c" />
    9.16      <ClCompile Include="..\..\src\haptic\windows\SDL_syshaptic.c" />
    9.17      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
    9.18      <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
    10.1 --- a/VisualC/SDL/SDL_VS2012.vcxproj	Tue Aug 20 15:28:14 2013 -0400
    10.2 +++ b/VisualC/SDL/SDL_VS2012.vcxproj	Tue Aug 20 19:57:11 2013 -0400
    10.3 @@ -19,7 +19,7 @@
    10.4      </ProjectConfiguration>
    10.5    </ItemGroup>
    10.6    <PropertyGroup Label="Globals">
    10.7 -    <ProjectName>SDL2</ProjectName>
    10.8 +    <ProjectName>SDL2</ProjectName>
    10.9      <ProjectGuid>{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}</ProjectGuid>
   10.10      <RootNamespace>SDL</RootNamespace>
   10.11    </PropertyGroup>
   10.12 @@ -233,6 +233,7 @@
   10.13      <ClInclude Include="..\..\include\SDL_endian.h" />
   10.14      <ClInclude Include="..\..\include\SDL_error.h" />
   10.15      <ClInclude Include="..\..\include\SDL_events.h" />
   10.16 +    <ClInclude Include="..\..\include\SDL_filesystem.h" />
   10.17      <ClInclude Include="..\..\include\SDL_gesture.h" />
   10.18      <ClInclude Include="..\..\include\SDL_haptic.h" />
   10.19      <ClInclude Include="..\..\include\SDL_hints.h" />
   10.20 @@ -433,6 +434,7 @@
   10.21      <ClCompile Include="..\..\src\stdlib\SDL_string.c" />
   10.22      <ClCompile Include="..\..\src\video\SDL_surface.c" />
   10.23      <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
   10.24 +    <ClCompile Include="..\..\src\filesystem\windows\SDL_sysfilesystem.c" />
   10.25      <ClCompile Include="..\..\src\haptic\windows\SDL_syshaptic.c" />
   10.26      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
   10.27      <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
    11.1 --- a/configure	Tue Aug 20 15:28:14 2013 -0400
    11.2 +++ b/configure	Tue Aug 20 19:57:11 2013 -0400
    11.3 @@ -783,6 +783,7 @@
    11.4  enable_joystick
    11.5  enable_haptic
    11.6  enable_power
    11.7 +enable_filesystem
    11.8  enable_threads
    11.9  enable_timers
   11.10  enable_file
   11.11 @@ -1496,6 +1497,7 @@
   11.12    --enable-haptic         Enable the haptic (force feedback) subsystem
   11.13                            [[default=yes]]
   11.14    --enable-power          Enable the power subsystem [[default=yes]]
   11.15 +  --enable-filesystem     Enable the filesystem subsystem [[default=yes]]
   11.16    --enable-threads        Enable the threading subsystem [[default=yes]]
   11.17    --enable-timers         Enable the timer subsystem [[default=yes]]
   11.18    --enable-file           Enable the file subsystem [[default=yes]]
   11.19 @@ -16767,6 +16769,7 @@
   11.20  SOURCES="$SOURCES $srcdir/src/joystick/*.c"
   11.21  SOURCES="$SOURCES $srcdir/src/libm/*.c"
   11.22  SOURCES="$SOURCES $srcdir/src/power/*.c"
   11.23 +#SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
   11.24  SOURCES="$SOURCES $srcdir/src/render/*.c"
   11.25  SOURCES="$SOURCES $srcdir/src/render/*/*.c"
   11.26  SOURCES="$SOURCES $srcdir/src/stdlib/*.c"
   11.27 @@ -16871,6 +16874,18 @@
   11.28  $as_echo "#define SDL_POWER_DISABLED 1" >>confdefs.h
   11.29  
   11.30  fi
   11.31 +# Check whether --enable-filesystem was given.
   11.32 +if test "${enable_filesystem+set}" = set; then :
   11.33 +  enableval=$enable_filesystem;
   11.34 +else
   11.35 +  enable_filesystem=yes
   11.36 +fi
   11.37 +
   11.38 +if test x$enable_filesystem != xyes; then
   11.39 +
   11.40 +$as_echo "#define SDL_FILESYSTEM_DISABLED 1" >>confdefs.h
   11.41 +
   11.42 +fi
   11.43  # Check whether --enable-threads was given.
   11.44  if test "${enable_threads+set}" = set; then :
   11.45    enableval=$enable_threads;
   11.46 @@ -22120,6 +22135,14 @@
   11.47                 ;;
   11.48               esac
   11.49          fi
   11.50 +        # Set up files for the filesystem library
   11.51 +        if test x$enable_filesystem = xyes; then
   11.52 +
   11.53 +$as_echo "#define SDL_FILESYSTEM_UNIX 1" >>confdefs.h
   11.54 +
   11.55 +            SOURCES="$SOURCES $srcdir/src/filesystem/unix/*.c"
   11.56 +            have_filesystem=yes
   11.57 +        fi
   11.58          # Set up files for the timer library
   11.59          if test x$enable_timers = xyes; then
   11.60  
   11.61 @@ -22222,6 +22245,13 @@
   11.62              SOURCES="$SOURCES $srcdir/src/power/windows/SDL_syspower.c"
   11.63              have_power=yes
   11.64          fi
   11.65 +        if test x$enable_filesystem = xyes; then
   11.66 +
   11.67 +$as_echo "#define SDL_FILESYSTEM_WINDOWS 1" >>confdefs.h
   11.68 +
   11.69 +            SOURCES="$SOURCES $srcdir/src/filesystem/windows/SDL_sysfilesystem.c"
   11.70 +            have_filesystem=yes
   11.71 +        fi
   11.72          # Set up files for the thread library
   11.73          if test x$enable_threads = xyes; then
   11.74  
   11.75 @@ -22355,6 +22385,14 @@
   11.76              SOURCES="$SOURCES $srcdir/src/power/beos/*.c"
   11.77              have_power=yes
   11.78          fi
   11.79 +        # Set up files for the system filesystem library
   11.80 +        if test x$enable_filesystem = xyes; then
   11.81 +
   11.82 +$as_echo "#define SDL_FILESYSTEM_BEOS 1" >>confdefs.h
   11.83 +
   11.84 +            SOURCES="$SOURCES $srcdir/src/power/beos/*.cc"
   11.85 +            have_filesystem=yes
   11.86 +        fi
   11.87          # The BeOS platform requires special setup.
   11.88          SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
   11.89          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
   11.90 @@ -22389,10 +22427,10 @@
   11.91          #    have_haptic=yes
   11.92          #    EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,ForceFeedback"
   11.93          #fi
   11.94 -        # Set up files for the power library
   11.95 -        if test x$enable_power = xyes; then
   11.96 -            SOURCES="$SOURCES $srcdir/src/power/uikit/*.m"
   11.97 -            have_power=yes
   11.98 +        # Set up files for the filesystem library
   11.99 +        if test x$enable_filesystem = xyes; then
  11.100 +            SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
  11.101 +            have_filesystem=yes
  11.102          fi
  11.103          # Set up files for the timer library
  11.104          if test x$enable_timers = xyes; then
  11.105 @@ -22475,6 +22513,14 @@
  11.106              SOURCES="$SOURCES $srcdir/src/power/macosx/*.c"
  11.107              have_power=yes
  11.108          fi
  11.109 +        # Set up files for the filesystem library
  11.110 +        if test x$enable_filesystem = xyes; then
  11.111 +
  11.112 +$as_echo "#define SDL_FILESYSTEM_COCOA 1" >>confdefs.h
  11.113 +
  11.114 +            SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
  11.115 +            have_filesystem=yes
  11.116 +        fi
  11.117          # Set up files for the timer library
  11.118          if test x$enable_timers = xyes; then
  11.119  
  11.120 @@ -22541,6 +22587,14 @@
  11.121      fi
  11.122      SOURCES="$SOURCES $srcdir/src/timer/dummy/*.c"
  11.123  fi
  11.124 +if test x$have_filesystem != xyes; then
  11.125 +    if test x$enable_filesystem = xyes; then
  11.126 +
  11.127 +$as_echo "#define SDL_FILESYSTEM_DISABLED 1" >>confdefs.h
  11.128 +
  11.129 +    fi
  11.130 +    SOURCES="$SOURCES $srcdir/src/filesystem/dummy/*.c"
  11.131 +fi
  11.132  if test x$have_loadso != xyes; then
  11.133      if test x$enable_loadso = xyes; then
  11.134  
    12.1 --- a/configure.in	Tue Aug 20 15:28:14 2013 -0400
    12.2 +++ b/configure.in	Tue Aug 20 19:57:11 2013 -0400
    12.3 @@ -325,6 +325,7 @@
    12.4  SOURCES="$SOURCES $srcdir/src/joystick/*.c"
    12.5  SOURCES="$SOURCES $srcdir/src/libm/*.c"
    12.6  SOURCES="$SOURCES $srcdir/src/power/*.c"
    12.7 +#SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
    12.8  SOURCES="$SOURCES $srcdir/src/render/*.c"
    12.9  SOURCES="$SOURCES $srcdir/src/render/*/*.c"
   12.10  SOURCES="$SOURCES $srcdir/src/stdlib/*.c"
   12.11 @@ -382,6 +383,12 @@
   12.12  if test x$enable_power != xyes; then
   12.13      AC_DEFINE(SDL_POWER_DISABLED, 1, [ ])
   12.14  fi
   12.15 +AC_ARG_ENABLE(filesystem,
   12.16 +AC_HELP_STRING([--enable-filesystem], [Enable the filesystem subsystem [[default=yes]]]),
   12.17 +              , enable_filesystem=yes)
   12.18 +if test x$enable_filesystem != xyes; then
   12.19 +    AC_DEFINE(SDL_FILESYSTEM_DISABLED, 1, [ ])
   12.20 +fi
   12.21  AC_ARG_ENABLE(threads,
   12.22  AC_HELP_STRING([--enable-threads], [Enable the threading subsystem [[default=yes]]]),
   12.23                , enable_threads=yes)
   12.24 @@ -2431,6 +2438,12 @@
   12.25                 ;;
   12.26               esac
   12.27          fi
   12.28 +        # Set up files for the filesystem library
   12.29 +        if test x$enable_filesystem = xyes; then
   12.30 +            AC_DEFINE(SDL_FILESYSTEM_UNIX, 1, [ ])
   12.31 +            SOURCES="$SOURCES $srcdir/src/filesystem/unix/*.c"
   12.32 +            have_filesystem=yes
   12.33 +        fi
   12.34          # Set up files for the timer library
   12.35          if test x$enable_timers = xyes; then
   12.36              AC_DEFINE(SDL_TIMER_UNIX, 1, [ ])
   12.37 @@ -2509,6 +2522,11 @@
   12.38              SOURCES="$SOURCES $srcdir/src/power/windows/SDL_syspower.c"
   12.39              have_power=yes
   12.40          fi
   12.41 +        if test x$enable_filesystem = xyes; then
   12.42 +            AC_DEFINE(SDL_FILESYSTEM_WINDOWS, 1, [ ])
   12.43 +            SOURCES="$SOURCES $srcdir/src/filesystem/windows/SDL_sysfilesystem.c"
   12.44 +            have_filesystem=yes
   12.45 +        fi
   12.46          # Set up files for the thread library
   12.47          if test x$enable_threads = xyes; then
   12.48              AC_DEFINE(SDL_THREAD_WINDOWS, 1, [ ])
   12.49 @@ -2591,6 +2609,12 @@
   12.50              SOURCES="$SOURCES $srcdir/src/power/beos/*.c"
   12.51              have_power=yes
   12.52          fi
   12.53 +        # Set up files for the system filesystem library
   12.54 +        if test x$enable_filesystem = xyes; then
   12.55 +            AC_DEFINE(SDL_FILESYSTEM_BEOS, 1, [ ])
   12.56 +            SOURCES="$SOURCES $srcdir/src/power/beos/*.cc"
   12.57 +            have_filesystem=yes
   12.58 +        fi
   12.59          # The BeOS platform requires special setup.
   12.60          SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
   12.61          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
   12.62 @@ -2630,6 +2654,11 @@
   12.63              SOURCES="$SOURCES $srcdir/src/power/uikit/*.m"
   12.64              have_power=yes
   12.65          fi
   12.66 +        # Set up files for the filesystem library
   12.67 +        if test x$enable_filesystem = xyes; then
   12.68 +            SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
   12.69 +            have_filesystem=yes
   12.70 +        fi
   12.71          # Set up files for the timer library
   12.72          if test x$enable_timers = xyes; then
   12.73              SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
   12.74 @@ -2703,6 +2732,12 @@
   12.75              SOURCES="$SOURCES $srcdir/src/power/macosx/*.c"
   12.76              have_power=yes
   12.77          fi
   12.78 +        # Set up files for the filesystem library
   12.79 +        if test x$enable_filesystem = xyes; then
   12.80 +            AC_DEFINE(SDL_FILESYSTEM_COCOA, 1, [ ])
   12.81 +            SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
   12.82 +            have_filesystem=yes
   12.83 +        fi
   12.84          # Set up files for the timer library
   12.85          if test x$enable_timers = xyes; then
   12.86              AC_DEFINE(SDL_TIMER_UNIX, 1, [ ])
   12.87 @@ -2760,6 +2795,12 @@
   12.88      fi
   12.89      SOURCES="$SOURCES $srcdir/src/timer/dummy/*.c"
   12.90  fi
   12.91 +if test x$have_filesystem != xyes; then
   12.92 +    if test x$enable_filesystem = xyes; then
   12.93 +        AC_DEFINE(SDL_FILESYSTEM_DISABLED, 1, [ ])
   12.94 +    fi
   12.95 +    SOURCES="$SOURCES $srcdir/src/filesystem/dummy/*.c"
   12.96 +fi
   12.97  if test x$have_loadso != xyes; then
   12.98      if test x$enable_loadso = xyes; then
   12.99          AC_DEFINE(SDL_LOADSO_DISABLED, 1, [ ])
    13.1 --- a/include/SDL.h	Tue Aug 20 15:28:14 2013 -0400
    13.2 +++ b/include/SDL.h	Tue Aug 20 19:57:11 2013 -0400
    13.3 @@ -74,6 +74,7 @@
    13.4  #include "SDL_endian.h"
    13.5  #include "SDL_error.h"
    13.6  #include "SDL_events.h"
    13.7 +#include "SDL_filesystem.h"
    13.8  #include "SDL_joystick.h"
    13.9  #include "SDL_gamecontroller.h"
   13.10  #include "SDL_haptic.h"
    14.1 --- a/include/SDL_config.h.cmake	Tue Aug 20 15:28:14 2013 -0400
    14.2 +++ b/include/SDL_config.h.cmake	Tue Aug 20 19:57:11 2013 -0400
    14.3 @@ -182,6 +182,7 @@
    14.4  #cmakedefine SDL_TIMERS_DISABLED @SDL_TIMERS_DISABLED@
    14.5  #cmakedefine SDL_VIDEO_DISABLED @SDL_VIDEO_DISABLED@
    14.6  #cmakedefine SDL_POWER_DISABLED @SDL_POWER_DISABLED@
    14.7 +#cmakedefine SDL_FILESYSTEM_DISABLED @SDL_FILESYSTEM_DISABLED@
    14.8  
    14.9  /* Enable various audio drivers */
   14.10  #cmakedefine SDL_AUDIO_DRIVER_ALSA @SDL_AUDIO_DRIVER_ALSA@
   14.11 @@ -301,6 +302,13 @@
   14.12  #cmakedefine SDL_POWER_BEOS @SDL_POWER_BEOS@
   14.13  #cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@
   14.14  
   14.15 +/* Enable system filesystem support */
   14.16 +#cmakedefine SDL_FILESYSTEM_BEOS @SDL_FILESYSTEM_BEOS@
   14.17 +#cmakedefine SDL_FILESYSTEM_COCOA @SDL_FILESYSTEM_COCOA@
   14.18 +#cmakedefine SDL_FILESYSTEM_DUMMY @SDL_FILESYSTEM_DUMMY@
   14.19 +#cmakedefine SDL_FILESYSTEM_UNIX @SDL_FILESYSTEM_UNIX@
   14.20 +#cmakedefine SDL_FILESYSTEM_WINDOWS @SDL_FILESYSTEM_WINDOWS@
   14.21 +
   14.22  /* Enable assembly routines */
   14.23  #cmakedefine SDL_ASSEMBLY_ROUTINES @SDL_ASSEMBLY_ROUTINES@
   14.24  #cmakedefine SDL_ALTIVEC_BLITTERS @SDL_ALTIVEC_BLITTERS@
    15.1 --- a/include/SDL_config.h.in	Tue Aug 20 15:28:14 2013 -0400
    15.2 +++ b/include/SDL_config.h.in	Tue Aug 20 19:57:11 2013 -0400
    15.3 @@ -184,6 +184,7 @@
    15.4  #undef SDL_TIMERS_DISABLED
    15.5  #undef SDL_VIDEO_DISABLED
    15.6  #undef SDL_POWER_DISABLED
    15.7 +#undef SDL_FILESYSTEM_DISABLED
    15.8  
    15.9  /* Enable various audio drivers */
   15.10  #undef SDL_AUDIO_DRIVER_ALSA
   15.11 @@ -303,6 +304,13 @@
   15.12  #undef SDL_POWER_BEOS
   15.13  #undef SDL_POWER_HARDWIRED
   15.14  
   15.15 +/* Enable system filesystem support */
   15.16 +#undef SDL_FILESYSTEM_BEOS
   15.17 +#undef SDL_FILESYSTEM_COCOA
   15.18 +#undef SDL_FILESYSTEM_DUMMY
   15.19 +#undef SDL_FILESYSTEM_UNIX
   15.20 +#undef SDL_FILESYSTEM_WINDOWS
   15.21 +
   15.22  /* Enable assembly routines */
   15.23  #undef SDL_ASSEMBLY_ROUTINES
   15.24  #undef SDL_ALTIVEC_BLITTERS
    16.1 --- a/include/SDL_config_android.h	Tue Aug 20 15:28:14 2013 -0400
    16.2 +++ b/include/SDL_config_android.h	Tue Aug 20 19:57:11 2013 -0400
    16.3 @@ -136,4 +136,7 @@
    16.4  /* Enable system power support */
    16.5  #define SDL_POWER_ANDROID 1
    16.6  
    16.7 +/* !!! FIXME: what does Android do for filesystem stuff? */
    16.8 +#define SDL_FILESYSTEM_DUMMY   1
    16.9 +
   16.10  #endif /* _SDL_config_android_h */
    17.1 --- a/include/SDL_config_iphoneos.h	Tue Aug 20 15:28:14 2013 -0400
    17.2 +++ b/include/SDL_config_iphoneos.h	Tue Aug 20 19:57:11 2013 -0400
    17.3 @@ -148,4 +148,7 @@
    17.4   */
    17.5  #define SDL_IPHONE_MAX_GFORCE 5.0
    17.6  
    17.7 +/* enable filesystem support */
    17.8 +#define SDL_FILESYSTEM_COCOA   1
    17.9 +
   17.10  #endif /* _SDL_config_iphoneos_h */
    18.1 --- a/include/SDL_config_macosx.h	Tue Aug 20 15:28:14 2013 -0400
    18.2 +++ b/include/SDL_config_macosx.h	Tue Aug 20 19:57:11 2013 -0400
    18.3 @@ -171,6 +171,9 @@
    18.4  /* Enable system power support */
    18.5  #define SDL_POWER_MACOSX 1
    18.6  
    18.7 +/* enable filesystem support */
    18.8 +#define SDL_FILESYSTEM_COCOA   1
    18.9 +
   18.10  /* Enable assembly routines */
   18.11  #define SDL_ASSEMBLY_ROUTINES   1
   18.12  #ifdef __ppc__
    19.1 --- a/include/SDL_config_minimal.h	Tue Aug 20 15:28:14 2013 -0400
    19.2 +++ b/include/SDL_config_minimal.h	Tue Aug 20 19:57:11 2013 -0400
    19.3 @@ -75,4 +75,7 @@
    19.4  /* Enable the dummy video driver (src/video/dummy/\*.c) */
    19.5  #define SDL_VIDEO_DRIVER_DUMMY  1
    19.6  
    19.7 +/* Enable the dummy filesystem driver (src/filesystem/dummy/\*.c) */
    19.8 +#define SDL_FILESYSTEM_DUMMY  1
    19.9 +
   19.10  #endif /* _SDL_config_minimal_h */
    20.1 --- a/include/SDL_config_pandora.h	Tue Aug 20 15:28:14 2013 -0400
    20.2 +++ b/include/SDL_config_pandora.h	Tue Aug 20 19:57:11 2013 -0400
    20.3 @@ -114,6 +114,7 @@
    20.4  #define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1
    20.5  
    20.6  #define SDL_TIMER_UNIX 1
    20.7 +#define SDL_FILESYSTEM_UNIX 1
    20.8  
    20.9  #define SDL_VIDEO_DRIVER_DUMMY 1
   20.10  #define SDL_VIDEO_DRIVER_X11 1
    21.1 --- a/include/SDL_config_psp.h	Tue Aug 20 15:28:14 2013 -0400
    21.2 +++ b/include/SDL_config_psp.h	Tue Aug 20 19:57:11 2013 -0400
    21.3 @@ -126,6 +126,9 @@
    21.4  
    21.5  #define SDL_POWER_PSP          1
    21.6  
    21.7 +/* !!! FIXME: what does PSP do for filesystem stuff? */
    21.8 +#define SDL_FILESYSTEM_DUMMY   1
    21.9 +
   21.10  /* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */
   21.11  #define SDL_HAPTIC_DISABLED    1
   21.12  
    22.1 --- a/include/SDL_config_windows.h	Tue Aug 20 15:28:14 2013 -0400
    22.2 +++ b/include/SDL_config_windows.h	Tue Aug 20 19:57:11 2013 -0400
    22.3 @@ -181,6 +181,9 @@
    22.4  /* Enable system power support */
    22.5  #define SDL_POWER_WINDOWS 1
    22.6  
    22.7 +/* Enable filesystem support */
    22.8 +#define SDL_FILESYSTEM_WINDOWS  1
    22.9 +
   22.10  /* Enable assembly routines (Win64 doesn't have inline asm) */
   22.11  #ifndef _WIN64
   22.12  #define SDL_ASSEMBLY_ROUTINES   1
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/include/SDL_filesystem.h	Tue Aug 20 19:57:11 2013 -0400
    23.3 @@ -0,0 +1,136 @@
    23.4 +/*
    23.5 +  Simple DirectMedia Layer
    23.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    23.7 +
    23.8 +  This software is provided 'as-is', without any express or implied
    23.9 +  warranty.  In no event will the authors be held liable for any damages
   23.10 +  arising from the use of this software.
   23.11 +
   23.12 +  Permission is granted to anyone to use this software for any purpose,
   23.13 +  including commercial applications, and to alter it and redistribute it
   23.14 +  freely, subject to the following restrictions:
   23.15 +
   23.16 +  1. The origin of this software must not be misrepresented; you must not
   23.17 +     claim that you wrote the original software. If you use this software
   23.18 +     in a product, an acknowledgment in the product documentation would be
   23.19 +     appreciated but is not required.
   23.20 +  2. Altered source versions must be plainly marked as such, and must not be
   23.21 +     misrepresented as being the original software.
   23.22 +  3. This notice may not be removed or altered from any source distribution.
   23.23 +*/
   23.24 +
   23.25 +/**
   23.26 + *  \file SDL_filesystem.h
   23.27 + *
   23.28 + *  \brief Include file for filesystem SDL API functions
   23.29 + */
   23.30 +
   23.31 +#ifndef _SDL_filesystem_h
   23.32 +#define _SDL_filesystem_h
   23.33 +
   23.34 +#include "SDL_stdinc.h"
   23.35 +
   23.36 +#include "begin_code.h"
   23.37 +
   23.38 +/* Set up for C function definitions, even when using C++ */
   23.39 +#ifdef __cplusplus
   23.40 +extern "C" {
   23.41 +#endif
   23.42 +
   23.43 +/**
   23.44 + * \brief Get the path where the application resides.
   23.45 + *
   23.46 + * Get the "base path". This is the directory where the application was run
   23.47 + *  from, which is probably the installation directory, and may or may not
   23.48 + *  be the process's current working directory.
   23.49 + *
   23.50 + * This returns an absolute path in UTF-8 encoding, and is guaranteed to
   23.51 + *  end with a path separator ('\\' on Windows, '/' most other places).
   23.52 + *
   23.53 + * The pointer returned by this function is owned by you. Please call
   23.54 + *  SDL_free() on the pointer when you are done with it, or it will be a
   23.55 + *  memory leak. This is not necessarily a fast call, though, so you should
   23.56 + *  call this once near startup and save the string if you need it.
   23.57 + *
   23.58 + * Some platforms can't determine the application's path, and on other
   23.59 + *  platforms, this might be meaningless. In such cases, this function will
   23.60 + *  return NULL.
   23.61 + *
   23.62 + *  \return String of base dir in UTF-8 encoding, or NULL on error.
   23.63 + *
   23.64 + * \sa SDL_GetPrefPath
   23.65 + */
   23.66 +extern DECLSPEC char *SDLCALL SDL_GetBasePath(void);
   23.67 +
   23.68 +/**
   23.69 + * \brief Get the user-and-app-specific path where files can be written.
   23.70 + *
   23.71 + * Get the "pref dir". This is meant to be where users can write personal
   23.72 + *  files (preferences and save games, etc) that are specific to your
   23.73 + *  application. This directory is unique per user, per application.
   23.74 + *
   23.75 + * This function will decide the appropriate location in the native filesystem,
   23.76 + *  create the directory if necessary, and return a string of the absolute
   23.77 + *  path to the directory in UTF-8 encoding.
   23.78 + *
   23.79 + * On Windows, the string might look like:
   23.80 + *  "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name"
   23.81 + *
   23.82 + * On Linux, the string might look like:
   23.83 + *  "/home/bob/.local/share/My Program Name"
   23.84 + *
   23.85 + * On Mac OS X, the string might look like:
   23.86 + *  "/Users/bob/Library/Application Support/My Program Name"
   23.87 + *
   23.88 + * (etc.)
   23.89 + *
   23.90 + * You specify the name of your organization (if it's not a real organization,
   23.91 + *  your name or an Internet domain you own might do) and the name of your
   23.92 + *  application. These should be untranslated proper names.
   23.93 + *
   23.94 + * Both the org and app strings may become part of a directory name, so
   23.95 + *  please follow these rules:
   23.96 + *
   23.97 + *    - Try to use the same org string (including case-sensitivity) for
   23.98 + *      all your applications that use this function.
   23.99 + *    - Always use a unique app string for each one, and make sure it never
  23.100 + *      changes for an app once you've decided on it.
  23.101 + *    - Unicode characters are legal, as long as it's UTF-8 encoded, but...
  23.102 + *    - ...only use letters, numbers, and spaces. Avoid punctuation like
  23.103 + *      "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
  23.104 + *
  23.105 + * This returns an absolute path in UTF-8 encoding, and is guaranteed to
  23.106 + *  end with a path separator ('\\' on Windows, '/' most other places).
  23.107 + *
  23.108 + * The pointer returned by this function is owned by you. Please call
  23.109 + *  SDL_free() on the pointer when you are done with it, or it will be a
  23.110 + *  memory leak. This is not necessarily a fast call, though, so you should
  23.111 + *  call this once near startup and save the string if you need it.
  23.112 + *
  23.113 + * You should assume the path returned by this function is the only safe
  23.114 + *  place to write files (and that SDL_GetBasePath(), while it might be
  23.115 + *  writable, or even the parent of the returned path, aren't where you
  23.116 + *  should be writing things).
  23.117 + *
  23.118 + * Some platforms can't determine the pref path, and on other
  23.119 + *  platforms, this might be meaningless. In such cases, this function will
  23.120 + *  return NULL.
  23.121 + *
  23.122 + *   \param org The name of your organization.
  23.123 + *   \param app The name of your application.
  23.124 + *  \return UTF-8 string of user dir in platform-dependent notation. NULL
  23.125 + *          if there's a problem (creating directory failed, etc).
  23.126 + *
  23.127 + * \sa SDL_GetBasePath
  23.128 + */
  23.129 +extern DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
  23.130 +
  23.131 +/* Ends C function definitions when using C++ */
  23.132 +#ifdef __cplusplus
  23.133 +}
  23.134 +#endif
  23.135 +#include "close_code.h"
  23.136 +
  23.137 +#endif /* _SDL_system_h */
  23.138 +
  23.139 +/* vi: set ts=4 sw=4 expandtab: */
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/filesystem/beos/SDL_sysfilesystem.cc	Tue Aug 20 19:57:11 2013 -0400
    24.3 @@ -0,0 +1,92 @@
    24.4 +/*
    24.5 +  Simple DirectMedia Layer
    24.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    24.7 +
    24.8 +  This software is provided 'as-is', without any express or implied
    24.9 +  warranty.  In no event will the authors be held liable for any damages
   24.10 +  arising from the use of this software.
   24.11 +
   24.12 +  Permission is granted to anyone to use this software for any purpose,
   24.13 +  including commercial applications, and to alter it and redistribute it
   24.14 +  freely, subject to the following restrictions:
   24.15 +
   24.16 +  1. The origin of this software must not be misrepresented; you must not
   24.17 +     claim that you wrote the original software. If you use this software
   24.18 +     in a product, an acknowledgment in the product documentation would be
   24.19 +     appreciated but is not required.
   24.20 +  2. Altered source versions must be plainly marked as such, and must not be
   24.21 +     misrepresented as being the original software.
   24.22 +  3. This notice may not be removed or altered from any source distribution.
   24.23 +*/
   24.24 +#include "SDL_config.h"
   24.25 +
   24.26 +#ifdef SDL_FILESYSTEM_BEOS
   24.27 +
   24.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   24.29 +/* System dependent filesystem routines                                */
   24.30 +
   24.31 +#include <os/kernel/image.h>
   24.32 +#include <os/storage/Directory.h>
   24.33 +#include <os/storage/Path.h>
   24.34 +
   24.35 +#include "SDL_error.h"
   24.36 +#include "SDL_stdinc.h"
   24.37 +#include "SDL_assert.h"
   24.38 +#include "SDL_filesystem.h"
   24.39 +
   24.40 +char *
   24.41 +SDL_GetBasePath(void)
   24.42 +{
   24.43 +    image_info info;
   24.44 +    int32 cookie = 0;
   24.45 +
   24.46 +    while (get_next_image_info(0, &cookie, &info) == B_OK) {
   24.47 +        if (info.type == B_APP_IMAGE) {
   24.48 +            break;
   24.49 +        }
   24.50 +    }
   24.51 +
   24.52 +    BEntry entry(info.name, true);
   24.53 +    BPath path;
   24.54 +    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
   24.55 +    SDL_assert(rc == B_OK);
   24.56 +    rc = path.GetParent(&path); /* chop filename, keep directory. */
   24.57 +    SDL_assert(rc == B_OK);
   24.58 +    const char *str = path.Path();
   24.59 +    SDL_assert(str != NULL);
   24.60 +
   24.61 +    const size_t len = SDL_strlen(str);
   24.62 +    char *retval = (char *) SDL_malloc(len + 2);
   24.63 +    if (!retval) {
   24.64 +        SDL_OutOfMemory();
   24.65 +        return NULL;
   24.66 +    }
   24.67 +
   24.68 +    SDL_strcpy(retval, str);
   24.69 +    retval[len] = '/';
   24.70 +    retval[len+1] = '\0';
   24.71 +    return retval;
   24.72 +}
   24.73 +
   24.74 +
   24.75 +char *
   24.76 +SDL_GetPrefPath(const char *org, const char *app)
   24.77 +{
   24.78 +    // !!! FIXME: is there a better way to do this?
   24.79 +    const char *home = SDL_getenv("HOME");
   24.80 +    const char *append = "config/settings/";
   24.81 +    const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(app) + 2;
   24.82 +    char *retval = (char *) SDL_malloc(len);
   24.83 +    if (!retval) {
   24.84 +        SDL_OutOfMemory();
   24.85 +    } else {
   24.86 +        SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
   24.87 +        create_directory(retval, 0700);  // BeOS api: creates missing dirs
   24.88 +    }
   24.89 +
   24.90 +    return retval;
   24.91 +}
   24.92 +
   24.93 +#endif /* SDL_FILESYSTEM_BEOS */
   24.94 +
   24.95 +/* vi: set ts=4 sw=4 expandtab: */
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/filesystem/cocoa/SDL_sysfilesystem.m	Tue Aug 20 19:57:11 2013 -0400
    25.3 @@ -0,0 +1,93 @@
    25.4 +/*
    25.5 +  Simple DirectMedia Layer
    25.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    25.7 +
    25.8 +  This software is provided 'as-is', without any express or implied
    25.9 +  warranty.  In no event will the authors be held liable for any damages
   25.10 +  arising from the use of this software.
   25.11 +
   25.12 +  Permission is granted to anyone to use this software for any purpose,
   25.13 +  including commercial applications, and to alter it and redistribute it
   25.14 +  freely, subject to the following restrictions:
   25.15 +
   25.16 +  1. The origin of this software must not be misrepresented; you must not
   25.17 +     claim that you wrote the original software. If you use this software
   25.18 +     in a product, an acknowledgment in the product documentation would be
   25.19 +     appreciated but is not required.
   25.20 +  2. Altered source versions must be plainly marked as such, and must not be
   25.21 +     misrepresented as being the original software.
   25.22 +  3. This notice may not be removed or altered from any source distribution.
   25.23 +*/
   25.24 +#include "SDL_config.h"
   25.25 +
   25.26 +#ifdef SDL_FILESYSTEM_COCOA
   25.27 +
   25.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   25.29 +/* System dependent filesystem routines                                */
   25.30 +
   25.31 +#include <Cocoa/Cocoa.h>
   25.32 +#include <sys/stat.h>
   25.33 +
   25.34 +#include "SDL_error.h"
   25.35 +#include "SDL_stdinc.h"
   25.36 +#include "SDL_filesystem.h"
   25.37 +
   25.38 +char *
   25.39 +SDL_GetBasePath(void)
   25.40 +{
   25.41 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   25.42 +    const char *base = [[[NSBundle mainBundle] bundlePath] UTF8String];
   25.43 +    char *retval = NULL;
   25.44 +    if (base) {
   25.45 +        const size_t len = SDL_strlen(base) + 2;
   25.46 +        retval = (char *) SDL_malloc(len);
   25.47 +        if (retval == NULL) {
   25.48 +            SDL_OutOfMemory();
   25.49 +        } else {
   25.50 +            SDL_snprintf(retval, len, "%s/", base);
   25.51 +        }
   25.52 +    }
   25.53 +
   25.54 +    [pool release];
   25.55 +    return retval;
   25.56 +}
   25.57 +
   25.58 +char *
   25.59 +SDL_GetPrefPath(const char *org, const char *app)
   25.60 +{
   25.61 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   25.62 +    NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
   25.63 +    char *retval = NULL;
   25.64 +
   25.65 +    (void) org;  // unused on Mac OS X and iOS.
   25.66 +
   25.67 +    if ([array count] > 0) {  // we only want the first item in the list.
   25.68 +        NSString *str = [array objectAtIndex:0];
   25.69 +        const char *base = [str UTF8String];
   25.70 +        if (base) {
   25.71 +            const size_t len = SDL_strlen(base) + SDL_strlen(app) + 3;
   25.72 +            retval = (char *) SDL_malloc(len);
   25.73 +            if (retval == NULL) {
   25.74 +                SDL_OutOfMemory();
   25.75 +            } else {
   25.76 +                char *ptr;
   25.77 +                SDL_snprintf(retval, len, "%s/%s/", base, app);
   25.78 +                for (ptr = retval+1; *ptr; ptr++) {
   25.79 +                    if (*ptr == '/') {
   25.80 +                        *ptr = '\0';
   25.81 +                        mkdir(retval, 0700);
   25.82 +                        *ptr = '/';
   25.83 +                    }
   25.84 +                }
   25.85 +                mkdir(retval, 0700);
   25.86 +            }
   25.87 +        }
   25.88 +    }
   25.89 +
   25.90 +    [pool release];
   25.91 +    return retval;
   25.92 +}
   25.93 +
   25.94 +#endif /* SDL_FILESYSTEM_COCOA */
   25.95 +
   25.96 +/* vi: set ts=4 sw=4 expandtab: */
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/filesystem/dummy/SDL_sysfilesystem.c	Tue Aug 20 19:57:11 2013 -0400
    26.3 @@ -0,0 +1,47 @@
    26.4 +/*
    26.5 +  Simple DirectMedia Layer
    26.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    26.7 +
    26.8 +  This software is provided 'as-is', without any express or implied
    26.9 +  warranty.  In no event will the authors be held liable for any damages
   26.10 +  arising from the use of this software.
   26.11 +
   26.12 +  Permission is granted to anyone to use this software for any purpose,
   26.13 +  including commercial applications, and to alter it and redistribute it
   26.14 +  freely, subject to the following restrictions:
   26.15 +
   26.16 +  1. The origin of this software must not be misrepresented; you must not
   26.17 +     claim that you wrote the original software. If you use this software
   26.18 +     in a product, an acknowledgment in the product documentation would be
   26.19 +     appreciated but is not required.
   26.20 +  2. Altered source versions must be plainly marked as such, and must not be
   26.21 +     misrepresented as being the original software.
   26.22 +  3. This notice may not be removed or altered from any source distribution.
   26.23 +*/
   26.24 +#include "SDL_config.h"
   26.25 +
   26.26 +#ifdef SDL_FILESYSTEM_DUMMY
   26.27 +
   26.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   26.29 +/* System dependent filesystem routines                                */
   26.30 +
   26.31 +#include "SDL_error.h"
   26.32 +#include "SDL_filesystem.h"
   26.33 +
   26.34 +char *
   26.35 +SDL_GetBasePath(void)
   26.36 +{
   26.37 +    SDL_Unsupported();
   26.38 +    return NULL;
   26.39 +}
   26.40 +
   26.41 +char *
   26.42 +SDL_GetPrefPath(const char *org, const char *app)
   26.43 +{
   26.44 +    SDL_Unsupported();
   26.45 +    return NULL;
   26.46 +}
   26.47 +
   26.48 +#endif /* SDL_FILESYSTEM_DUMMY */
   26.49 +
   26.50 +/* vi: set ts=4 sw=4 expandtab: */
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/filesystem/unix/SDL_sysfilesystem.c	Tue Aug 20 19:57:11 2013 -0400
    27.3 @@ -0,0 +1,161 @@
    27.4 +/*
    27.5 +  Simple DirectMedia Layer
    27.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    27.7 +
    27.8 +  This software is provided 'as-is', without any express or implied
    27.9 +  warranty.  In no event will the authors be held liable for any damages
   27.10 +  arising from the use of this software.
   27.11 +
   27.12 +  Permission is granted to anyone to use this software for any purpose,
   27.13 +  including commercial applications, and to alter it and redistribute it
   27.14 +  freely, subject to the following restrictions:
   27.15 +
   27.16 +  1. The origin of this software must not be misrepresented; you must not
   27.17 +     claim that you wrote the original software. If you use this software
   27.18 +     in a product, an acknowledgment in the product documentation would be
   27.19 +     appreciated but is not required.
   27.20 +  2. Altered source versions must be plainly marked as such, and must not be
   27.21 +     misrepresented as being the original software.
   27.22 +  3. This notice may not be removed or altered from any source distribution.
   27.23 +*/
   27.24 +#include "SDL_config.h"
   27.25 +
   27.26 +#ifdef SDL_FILESYSTEM_UNIX
   27.27 +
   27.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   27.29 +/* System dependent filesystem routines                                */
   27.30 +
   27.31 +#include <unistd.h>
   27.32 +
   27.33 +#include "SDL_error.h"
   27.34 +#include "SDL_stdinc.h"
   27.35 +#include "SDL_filesystem.h"
   27.36 +
   27.37 +static char *readSymLink(const char *path)
   27.38 +{
   27.39 +    char *retval = NULL;
   27.40 +    ssize_t len = 64;
   27.41 +    ssize_t rc = -1;
   27.42 +
   27.43 +    while (1)
   27.44 +    {
   27.45 +        char *ptr = (char *) SDL_realloc(retval, (size_t) len);
   27.46 +        if (ptr == NULL) {
   27.47 +            SDL_OutOfMemory();
   27.48 +            break;
   27.49 +        }
   27.50 +
   27.51 +        retval = ptr;
   27.52 +
   27.53 +        rc = readlink(path, retval, len);
   27.54 +        if (rc == -1) {
   27.55 +            break;  /* not a symlink, i/o error, etc. */
   27.56 +        } else if (rc < len) {
   27.57 +            retval[rc] = '\0';  /* readlink doesn't null-terminate. */
   27.58 +            return retval;  /* we're good to go. */
   27.59 +        }
   27.60 +
   27.61 +        len *= 2;  /* grow buffer, try again. */
   27.62 +    }
   27.63 +
   27.64 +    if (retval != NULL) {
   27.65 +        SDL_free(retval);
   27.66 +    }
   27.67 +    return NULL;
   27.68 +}
   27.69 +
   27.70 +
   27.71 +char *
   27.72 +SDL_GetBasePath(void)
   27.73 +{
   27.74 +    char *retval = NULL;
   27.75 +
   27.76 +    /* is a Linux-style /proc filesystem available? */
   27.77 +    if (access("/proc", F_OK) {
   27.78 +        retval = readSymLink("/proc/self/exe");
   27.79 +        if (retval == NULL) {
   27.80 +            /* older kernels don't have /proc/self ... try PID version... */
   27.81 +            char path[64];
   27.82 +            const int rc = (int) SDL_snprintf(path, sizeof(path),
   27.83 +                                              "/proc/%llu/exe",
   27.84 +                                              (unsigned long long) getpid());
   27.85 +            if ( (rc > 0) && (rc < sizeof(path)) ) {
   27.86 +                retval = readSymLink(path);
   27.87 +            }
   27.88 +        }
   27.89 +    }
   27.90 +
   27.91 +    /* If we had access to argv[0] here, we could check it for a path,
   27.92 +        or troll through $PATH looking for it, too. */
   27.93 +
   27.94 +    if (retval != NULL) { /* chop off filename. */
   27.95 +        char *ptr = SDL_strrchr(retval, '/');
   27.96 +        if (ptr != NULL) {
   27.97 +            *(ptr+1) = '\0';
   27.98 +        } else {  /* shouldn't happen, but just in case... */
   27.99 +            SDL_free(retval);
  27.100 +            retval = NULL;
  27.101 +        }
  27.102 +    }
  27.103 +
  27.104 +    if (retval != NULL) {
  27.105 +        /* try to shrink buffer... */
  27.106 +        char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
  27.107 +        if (ptr != NULL)
  27.108 +            retval = ptr;  /* oh well if it failed. */
  27.109 +    }
  27.110 +
  27.111 +    return retval;
  27.112 +}
  27.113 +
  27.114 +char *
  27.115 +SDL_GetPrefPath(const char *org, const char *app)
  27.116 +{
  27.117 +    /*
  27.118 +     * We use XDG's base directory spec, even if you're not on Linux.
  27.119 +     *  This isn't strictly correct, but the results are relatively sane
  27.120 +     *  in any case.
  27.121 +     *
  27.122 +     * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
  27.123 +     */
  27.124 +    const char *envr = SDL_getenv("XDG_DATA_HOME");
  27.125 +    const char *append = "/";
  27.126 +    char *retval = NULL;
  27.127 +    char *ptr = NULL;
  27.128 +    size_t len = 0;
  27.129 +
  27.130 +    if (!envr) {
  27.131 +        /* You end up with "$HOME/.local/share/Game Name 2" */
  27.132 +        envr = SDL_getenv("HOME");
  27.133 +        if (!envr) {
  27.134 +            /* we could take heroic measures with /etc/passwd, but oh well. */
  27.135 +            SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
  27.136 +            return NULL;
  27.137 +        }
  27.138 +        append = ".local/share/";
  27.139 +    } /* if */
  27.140 +
  27.141 +    len = SDL_strlen(envr) + SDL_strlen(append) + SDL_strlen(app) + 2;
  27.142 +    retval = (char *) SDL_malloc(len);
  27.143 +    if (!retval) {
  27.144 +        SDL_OutOfMemory();
  27.145 +        return NULL;
  27.146 +    }
  27.147 +
  27.148 +    SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
  27.149 +
  27.150 +    for (ptr = retval+1; *ptr; ptr++) {
  27.151 +        if (*ptr == '/') {
  27.152 +            *ptr = '\0';
  27.153 +            mkdir(retval, 0700);
  27.154 +            *ptr = '/';
  27.155 +        }
  27.156 +    }
  27.157 +    mkdir(retval, 0700);
  27.158 +
  27.159 +    return retval;
  27.160 +}
  27.161 +
  27.162 +#endif /* SDL_FILESYSTEM_UNIX */
  27.163 +
  27.164 +/* vi: set ts=4 sw=4 expandtab: */
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/filesystem/windows/SDL_sysfilesystem.c	Tue Aug 20 19:57:11 2013 -0400
    28.3 @@ -0,0 +1,96 @@
    28.4 +/*
    28.5 +  Simple DirectMedia Layer
    28.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    28.7 +
    28.8 +  This software is provided 'as-is', without any express or implied
    28.9 +  warranty.  In no event will the authors be held liable for any damages
   28.10 +  arising from the use of this software.
   28.11 +
   28.12 +  Permission is granted to anyone to use this software for any purpose,
   28.13 +  including commercial applications, and to alter it and redistribute it
   28.14 +  freely, subject to the following restrictions:
   28.15 +
   28.16 +  1. The origin of this software must not be misrepresented; you must not
   28.17 +     claim that you wrote the original software. If you use this software
   28.18 +     in a product, an acknowledgment in the product documentation would be
   28.19 +     appreciated but is not required.
   28.20 +  2. Altered source versions must be plainly marked as such, and must not be
   28.21 +     misrepresented as being the original software.
   28.22 +  3. This notice may not be removed or altered from any source distribution.
   28.23 +*/
   28.24 +#include "SDL_config.h"
   28.25 +
   28.26 +#ifdef SDL_FILESYSTEM_WINDOWS
   28.27 +
   28.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   28.29 +/* System dependent filesystem routines                                */
   28.30 +
   28.31 +#include "SDL_error.h"
   28.32 +#include "SDL_windows.h"
   28.33 +#include "SDL_stdinc.h"
   28.34 +#include "SDL_filesystem.h"
   28.35 +
   28.36 +char *
   28.37 +SDL_GetBasePath(void)
   28.38 +{
   28.39 +    TCHAR path[MAX_PATH];
   28.40 +    const DWORD len = GetModuleFileName(NULL, path, SDL_arraysize(path));
   28.41 +    size_t i;
   28.42 +
   28.43 +    SDL_assert(len < SDL_arraysize(path));
   28.44 +
   28.45 +    if (len == 0) {
   28.46 +        WIN_SetError("Couldn't locate our .exe");
   28.47 +        return NULL;
   28.48 +    }
   28.49 +
   28.50 +    for (i = len-1; i > 0; i--) {
   28.51 +        if (path[i] == '\\') {
   28.52 +            break;
   28.53 +        }
   28.54 +    }
   28.55 +
   28.56 +    SDL_assert(i > 0); /* Should have been an absolute path. */
   28.57 +    path[i+1] = '\0';  /* chop off filename. */
   28.58 +    return WIN_StringToUTF8(path);
   28.59 +}
   28.60 +
   28.61 +char *
   28.62 +SDL_GetPrefPath(const char *org, const char *app)
   28.63 +{
   28.64 +    /*
   28.65 +     * Vista and later has a new API for this, but SHGetFolderPath works there,
   28.66 +     *  and apparently just wraps the new API. This is the new way to do it:
   28.67 +     *
   28.68 +     *     SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
   28.69 +     *                          NULL, &wszPath);
   28.70 +     */
   28.71 +
   28.72 +    TCHAR path[MAX_PATH];
   28.73 +    char *utf8 = NULL;
   28.74 +    char *retval = NULL;
   28.75 +
   28.76 +    if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
   28.77 +        WIN_SetError("Couldn't locate our prefpath");
   28.78 +        return NULL;
   28.79 +    }
   28.80 +
   28.81 +    utf8 = WIN_StringToUTF8(path);
   28.82 +    if (utf8) {
   28.83 +        const size_t len = SDL_strlen(utf8) + SDL_strlen(org) + SDL_strlen(app) + 4;
   28.84 +        retval = (char *) SDL_malloc(len);
   28.85 +        if (!retval) {
   28.86 +            SDL_free(utf8);
   28.87 +            SDL_OutOfMemory();
   28.88 +            return NULL;
   28.89 +        }
   28.90 +        SDL_snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
   28.91 +        SDL_free(utf8);
   28.92 +    }
   28.93 +
   28.94 +    return retval;
   28.95 +}
   28.96 +
   28.97 +#endif /* SDL_FILESYSTEM_WINDOWS */
   28.98 +
   28.99 +/* vi: set ts=4 sw=4 expandtab: */
    29.1 --- a/test/Makefile.in	Tue Aug 20 15:28:14 2013 -0400
    29.2 +++ b/test/Makefile.in	Tue Aug 20 19:57:11 2013 -0400
    29.3 @@ -36,6 +36,7 @@
    29.4  	testoverlay2$(EXE) \
    29.5  	testplatform$(EXE) \
    29.6  	testpower$(EXE) \
    29.7 +	testfilesystem$(EXE) \
    29.8  	testrendertarget$(EXE) \
    29.9  	testresample$(EXE) \
   29.10  	testscale$(EXE) \
   29.11 @@ -180,6 +181,9 @@
   29.12  testpower$(EXE): $(srcdir)/testpower.c
   29.13  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
   29.14  
   29.15 +testfilesystem$(EXE): $(srcdir)/testfilesystem.c
   29.16 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
   29.17 +
   29.18  testrendertarget$(EXE): $(srcdir)/testrendertarget.c
   29.19  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
   29.20  
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/testfilesystem.c	Tue Aug 20 19:57:11 2013 -0400
    30.3 @@ -0,0 +1,33 @@
    30.4 +/*
    30.5 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    30.6 +
    30.7 +  This software is provided 'as-is', without any express or implied
    30.8 +  warranty.  In no event will the authors be held liable for any damages
    30.9 +  arising from the use of this software.
   30.10 +
   30.11 +  Permission is granted to anyone to use this software for any purpose,
   30.12 +  including commercial applications, and to alter it and redistribute it
   30.13 +  freely.
   30.14 +*/
   30.15 +/* Simple test of power subsystem. */
   30.16 +
   30.17 +#include <stdio.h>
   30.18 +#include "SDL.h"
   30.19 +
   30.20 +int
   30.21 +main(int argc, char *argv[])
   30.22 +{
   30.23 +    /* Enable standard application logging */
   30.24 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   30.25 +
   30.26 +    if (SDL_Init(0) == -1) {
   30.27 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
   30.28 +        return 1;
   30.29 +    }
   30.30 +
   30.31 +    SDL_Log("base path: '%s'\n", SDL_GetBasePath());
   30.32 +    SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
   30.33 +
   30.34 +    SDL_Quit();
   30.35 +    return 0;
   30.36 +}