Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
diff --git a/.hgignore b/.hgignore
index b6c427f..c4b1187 100644
--- a/.hgignore
+++ b/.hgignore
@@ -76,6 +76,7 @@ test/testnative
test/testoverlay2
test/testplatform
test/testpower
+test/testfilesystem
test/testrelative
test/testrendercopyex
test/testrendertarget
diff --git a/Android.mk b/Android.mk
index 7338233..f3fcb3a 100755
--- a/Android.mk
+++ b/Android.mk
@@ -33,6 +33,7 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
+ $(wildcard $(LOCAL_PATH)/src/filesystem/dummy/*.c) \
$(wildcard $(LOCAL_PATH)/src/render/*.c) \
$(wildcard $(LOCAL_PATH)/src/render/*/*.c) \
$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d79b84b..8eca0c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -172,7 +172,7 @@ include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
set(SDL_SUBSYSTEMS
Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
- File Loadso CPUinfo)
+ File Loadso CPUinfo Filesystem)
foreach(_SUB ${SDL_SUBSYSTEMS})
string(TOUPPER ${_SUB} _OPT)
option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ON)
@@ -714,6 +714,13 @@ if(UNIX AND NOT APPLE)
endif(LINUX)
endif(SDL_POWER)
+ if(SDL_FILESYSTEM)
+ set(SDL_FILESYSTEM_UNIX 1)
+ file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/unix/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
+ set(HAVE_SDL_FILESYSTEM TRUE)
+ endif(SDL_FILESYSTEM)
+
if(SDL_TIMERS)
set(SDL_TIMER_UNIX 1)
file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
@@ -814,6 +821,13 @@ elseif(WINDOWS)
set(HAVE_SDL_POWER TRUE)
endif(SDL_POWER)
+ if(SDL_FILESYSTEM)
+ set(SDL_FILESYSTEM_WINDOWS 1)
+ file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesytem/windows/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
+ set(HAVE_SDL_FILESYSTEM TRUE)
+ endif(SDL_FILESYSTEM)
+
# Libraries for Win32 native and MinGW
list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
@@ -924,6 +938,13 @@ elseif(APPLE)
set(SDL_FRAMEWORK_IOKIT 1)
endif()
+ if(SDL_FILESYSTEM)
+ set(SDL_FILESYSTEM_COCOA 1)
+ file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
+ set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
+ set(HAVE_SDL_FILESYSTEM TRUE)
+ endif()
+
# Actually load the frameworks at the end so we don't duplicate include.
if(SDL_FRAMEWORK_COCOA)
find_library(COCOA_LIBRARY Cocoa)
@@ -973,6 +994,11 @@ elseif(BEOS)
set(SOURCE_FILES ${SOURCE_FILES} ${BWINDOW_SOURCES})
set(HAVE_SDL_VIDEO TRUE)
+ set(SDL_FILESYSTEM_BEOS 1)
+ file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/beos/*.cc)
+ set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
+ set(HAVE_SDL_FILESYSTEM TRUE)
+
if(VIDEO_OPENGL)
# TODO: Use FIND_PACKAGE(OpenGL) instead
set(SDL_VIDEO_OPENGL 1)
@@ -1010,6 +1036,11 @@ if(NOT HAVE_SDL_LOADSO)
file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
endif(NOT HAVE_SDL_LOADSO)
+if(NOT HAVE_SDL_FILESYSTEM)
+ set(SDL_FILESYSTEM_DISABLED 1)
+ file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
+endif(NOT HAVE_SDL_FILESYSTEM)
# We always need to have threads and timers around
if(NOT HAVE_SDL_THREADS)
diff --git a/Makefile.in b/Makefile.in
index ae6293e..da42661 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -54,6 +54,7 @@ HDRS = \
SDL_endian.h \
SDL_error.h \
SDL_events.h \
+ SDL_filesystem.h \
SDL_gamecontroller.h \
SDL_gesture.h \
SDL_haptic.h \
diff --git a/Makefile.minimal b/Makefile.minimal
index a060832..6ec1ce8 100644
--- a/Makefile.minimal
+++ b/Makefile.minimal
@@ -19,6 +19,7 @@ SOURCES = \
src/joystick/dummy/*.c \
src/loadso/dummy/*.c \
src/power/*.c \
+ src/filesystem/dummy/*.c \
src/render/*.c \
src/render/software/*.c \
src/stdlib/*.c \
diff --git a/Makefile.pandora b/Makefile.pandora
index de15c84..bb89d52 100644
--- a/Makefile.pandora
+++ b/Makefile.pandora
@@ -19,7 +19,7 @@ SOURCES = ./src/*.c ./src/audio/*.c ./src/cpuinfo/*.c ./src/events/*.c \
./src/thread/pthread/SDL_systhread.c ./src/thread/pthread/SDL_syssem.c \
./src/thread/pthread/SDL_sysmutex.c ./src/thread/pthread/SDL_syscond.c \
./src/joystick/linux/*.c ./src/haptic/linux/*.c ./src/timer/unix/*.c \
- ./src/atomic/linux/*.c \
+ ./src/atomic/linux/*.c ./src/filesystem/unix/*.c \
./src/video/pandora/SDL_pandora.o ./src/video/pandora/SDL_pandora_events.o ./src/video/x11/*.c
diff --git a/Makefile.psp b/Makefile.psp
index 8bcdcb9..5e7dcd2 100644
--- a/Makefile.psp
+++ b/Makefile.psp
@@ -31,6 +31,7 @@ OBJS= src/SDL.o \
src/joystick/psp/SDL_sysjoystick.o \
src/power/SDL_power.o \
src/power/psp/SDL_syspower.o \
+ src/filesystem/dummy/SDL_sysfilesystem.o \
src/render/SDL_render.o \
src/render/SDL_yuv_sw.o \
src/render/psp/SDL_render_psp.o \
diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj
index 72eb2d4..1e7db21 100644
--- a/VisualC/SDL/SDL_VS2008.vcproj
+++ b/VisualC/SDL/SDL_VS2008.vcproj
@@ -428,6 +428,10 @@
>
</File>
<File
+ RelativePath="..\..\include\SDL_filesystem.h"
+ >
+ </File>
+ <File
RelativePath="..\..\include\SDL_gamecontroller.h"
>
</File>
@@ -1089,6 +1093,10 @@
>
</File>
<File
+ RelativePath="..\..\src\filesystem\windows\SDL_sysfilesystem.c"
+ >
+ </File>
+ <File
RelativePath="..\..\src\haptic\windows\SDL_syshaptic.c"
>
</File>
diff --git a/VisualC/SDL/SDL_VS2010.vcxproj b/VisualC/SDL/SDL_VS2010.vcxproj
index 4fa9111..58807a5 100644
--- a/VisualC/SDL/SDL_VS2010.vcxproj
+++ b/VisualC/SDL/SDL_VS2010.vcxproj
@@ -229,6 +229,7 @@
<ClInclude Include="..\..\include\SDL_endian.h" />
<ClInclude Include="..\..\include\SDL_error.h" />
<ClInclude Include="..\..\include\SDL_events.h" />
+ <ClInclude Include="..\..\include\SDL_filesystem.h" />
<ClInclude Include="..\..\include\SDL_gesture.h" />
<ClInclude Include="..\..\include\SDL_haptic.h" />
<ClInclude Include="..\..\include\SDL_hints.h" />
@@ -430,6 +431,7 @@
<ClCompile Include="..\..\src\stdlib\SDL_string.c" />
<ClCompile Include="..\..\src\video\SDL_surface.c" />
<ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
+ <ClCompile Include="..\..\src\filesystem\windows\SDL_sysfilesystem.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_syshaptic.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
diff --git a/VisualC/SDL/SDL_VS2012.vcxproj b/VisualC/SDL/SDL_VS2012.vcxproj
index 213c10c..141bc64 100644
--- a/VisualC/SDL/SDL_VS2012.vcxproj
+++ b/VisualC/SDL/SDL_VS2012.vcxproj
@@ -19,7 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
- <ProjectName>SDL2</ProjectName>
+ <ProjectName>SDL2</ProjectName>
<ProjectGuid>{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}</ProjectGuid>
<RootNamespace>SDL</RootNamespace>
</PropertyGroup>
@@ -233,6 +233,7 @@
<ClInclude Include="..\..\include\SDL_endian.h" />
<ClInclude Include="..\..\include\SDL_error.h" />
<ClInclude Include="..\..\include\SDL_events.h" />
+ <ClInclude Include="..\..\include\SDL_filesystem.h" />
<ClInclude Include="..\..\include\SDL_gesture.h" />
<ClInclude Include="..\..\include\SDL_haptic.h" />
<ClInclude Include="..\..\include\SDL_hints.h" />
@@ -433,6 +434,7 @@
<ClCompile Include="..\..\src\stdlib\SDL_string.c" />
<ClCompile Include="..\..\src\video\SDL_surface.c" />
<ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
+ <ClCompile Include="..\..\src\filesystem\windows\SDL_sysfilesystem.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_syshaptic.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
diff --git a/configure b/configure
index 41adac4..f4c3f6a 100755
--- a/configure
+++ b/configure
@@ -783,6 +783,7 @@ enable_events
enable_joystick
enable_haptic
enable_power
+enable_filesystem
enable_threads
enable_timers
enable_file
@@ -1496,6 +1497,7 @@ Optional Features:
--enable-haptic Enable the haptic (force feedback) subsystem
[[default=yes]]
--enable-power Enable the power subsystem [[default=yes]]
+ --enable-filesystem Enable the filesystem subsystem [[default=yes]]
--enable-threads Enable the threading subsystem [[default=yes]]
--enable-timers Enable the timer subsystem [[default=yes]]
--enable-file Enable the file subsystem [[default=yes]]
@@ -16767,6 +16769,7 @@ SOURCES="$SOURCES $srcdir/src/haptic/*.c"
SOURCES="$SOURCES $srcdir/src/joystick/*.c"
SOURCES="$SOURCES $srcdir/src/libm/*.c"
SOURCES="$SOURCES $srcdir/src/power/*.c"
+#SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
SOURCES="$SOURCES $srcdir/src/render/*.c"
SOURCES="$SOURCES $srcdir/src/render/*/*.c"
SOURCES="$SOURCES $srcdir/src/stdlib/*.c"
@@ -16871,6 +16874,18 @@ if test x$enable_power != xyes; then
$as_echo "#define SDL_POWER_DISABLED 1" >>confdefs.h
fi
+# Check whether --enable-filesystem was given.
+if test "${enable_filesystem+set}" = set; then :
+ enableval=$enable_filesystem;
+else
+ enable_filesystem=yes
+fi
+
+if test x$enable_filesystem != xyes; then
+
+$as_echo "#define SDL_FILESYSTEM_DISABLED 1" >>confdefs.h
+
+fi
# Check whether --enable-threads was given.
if test "${enable_threads+set}" = set; then :
enableval=$enable_threads;
@@ -22120,6 +22135,14 @@ $as_echo "#define SDL_POWER_LINUX 1" >>confdefs.h
;;
esac
fi
+ # Set up files for the filesystem library
+ if test x$enable_filesystem = xyes; then
+
+$as_echo "#define SDL_FILESYSTEM_UNIX 1" >>confdefs.h
+
+ SOURCES="$SOURCES $srcdir/src/filesystem/unix/*.c"
+ have_filesystem=yes
+ fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
@@ -22222,6 +22245,13 @@ $as_echo "#define SDL_POWER_WINDOWS 1" >>confdefs.h
SOURCES="$SOURCES $srcdir/src/power/windows/SDL_syspower.c"
have_power=yes
fi
+ if test x$enable_filesystem = xyes; then
+
+$as_echo "#define SDL_FILESYSTEM_WINDOWS 1" >>confdefs.h
+
+ SOURCES="$SOURCES $srcdir/src/filesystem/windows/SDL_sysfilesystem.c"
+ have_filesystem=yes
+ fi
# Set up files for the thread library
if test x$enable_threads = xyes; then
@@ -22355,6 +22385,14 @@ $as_echo "#define SDL_POWER_BEOS 1" >>confdefs.h
SOURCES="$SOURCES $srcdir/src/power/beos/*.c"
have_power=yes
fi
+ # Set up files for the system filesystem library
+ if test x$enable_filesystem = xyes; then
+
+$as_echo "#define SDL_FILESYSTEM_BEOS 1" >>confdefs.h
+
+ SOURCES="$SOURCES $srcdir/src/power/beos/*.cc"
+ have_filesystem=yes
+ fi
# The BeOS platform requires special setup.
SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
@@ -22389,10 +22427,10 @@ $as_echo "#define SDL_POWER_BEOS 1" >>confdefs.h
# have_haptic=yes
# EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,ForceFeedback"
#fi
- # Set up files for the power library
- if test x$enable_power = xyes; then
- SOURCES="$SOURCES $srcdir/src/power/uikit/*.m"
- have_power=yes
+ # Set up files for the filesystem library
+ if test x$enable_filesystem = xyes; then
+ SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
+ have_filesystem=yes
fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
@@ -22475,6 +22513,14 @@ $as_echo "#define SDL_POWER_MACOSX 1" >>confdefs.h
SOURCES="$SOURCES $srcdir/src/power/macosx/*.c"
have_power=yes
fi
+ # Set up files for the filesystem library
+ if test x$enable_filesystem = xyes; then
+
+$as_echo "#define SDL_FILESYSTEM_COCOA 1" >>confdefs.h
+
+ SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
+ have_filesystem=yes
+ fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
@@ -22541,6 +22587,14 @@ $as_echo "#define SDL_TIMERS_DISABLED 1" >>confdefs.h
fi
SOURCES="$SOURCES $srcdir/src/timer/dummy/*.c"
fi
+if test x$have_filesystem != xyes; then
+ if test x$enable_filesystem = xyes; then
+
+$as_echo "#define SDL_FILESYSTEM_DISABLED 1" >>confdefs.h
+
+ fi
+ SOURCES="$SOURCES $srcdir/src/filesystem/dummy/*.c"
+fi
if test x$have_loadso != xyes; then
if test x$enable_loadso = xyes; then
diff --git a/configure.in b/configure.in
index de32e6a..f9d0bf2 100644
--- a/configure.in
+++ b/configure.in
@@ -325,6 +325,7 @@ SOURCES="$SOURCES $srcdir/src/haptic/*.c"
SOURCES="$SOURCES $srcdir/src/joystick/*.c"
SOURCES="$SOURCES $srcdir/src/libm/*.c"
SOURCES="$SOURCES $srcdir/src/power/*.c"
+#SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
SOURCES="$SOURCES $srcdir/src/render/*.c"
SOURCES="$SOURCES $srcdir/src/render/*/*.c"
SOURCES="$SOURCES $srcdir/src/stdlib/*.c"
@@ -382,6 +383,12 @@ AC_HELP_STRING([--enable-power], [Enable the power subsystem [[default=yes]]]),
if test x$enable_power != xyes; then
AC_DEFINE(SDL_POWER_DISABLED, 1, [ ])
fi
+AC_ARG_ENABLE(filesystem,
+AC_HELP_STRING([--enable-filesystem], [Enable the filesystem subsystem [[default=yes]]]),
+ , enable_filesystem=yes)
+if test x$enable_filesystem != xyes; then
+ AC_DEFINE(SDL_FILESYSTEM_DISABLED, 1, [ ])
+fi
AC_ARG_ENABLE(threads,
AC_HELP_STRING([--enable-threads], [Enable the threading subsystem [[default=yes]]]),
, enable_threads=yes)
@@ -2431,6 +2438,12 @@ case "$host" in
;;
esac
fi
+ # Set up files for the filesystem library
+ if test x$enable_filesystem = xyes; then
+ AC_DEFINE(SDL_FILESYSTEM_UNIX, 1, [ ])
+ SOURCES="$SOURCES $srcdir/src/filesystem/unix/*.c"
+ have_filesystem=yes
+ fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
AC_DEFINE(SDL_TIMER_UNIX, 1, [ ])
@@ -2509,6 +2522,11 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/power/windows/SDL_syspower.c"
have_power=yes
fi
+ if test x$enable_filesystem = xyes; then
+ AC_DEFINE(SDL_FILESYSTEM_WINDOWS, 1, [ ])
+ SOURCES="$SOURCES $srcdir/src/filesystem/windows/SDL_sysfilesystem.c"
+ have_filesystem=yes
+ fi
# Set up files for the thread library
if test x$enable_threads = xyes; then
AC_DEFINE(SDL_THREAD_WINDOWS, 1, [ ])
@@ -2591,6 +2609,12 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/power/beos/*.c"
have_power=yes
fi
+ # Set up files for the system filesystem library
+ if test x$enable_filesystem = xyes; then
+ AC_DEFINE(SDL_FILESYSTEM_BEOS, 1, [ ])
+ SOURCES="$SOURCES $srcdir/src/power/beos/*.cc"
+ have_filesystem=yes
+ fi
# The BeOS platform requires special setup.
SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
@@ -2630,6 +2654,11 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/power/uikit/*.m"
have_power=yes
fi
+ # Set up files for the filesystem library
+ if test x$enable_filesystem = xyes; then
+ SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
+ have_filesystem=yes
+ fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
@@ -2703,6 +2732,12 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/power/macosx/*.c"
have_power=yes
fi
+ # Set up files for the filesystem library
+ if test x$enable_filesystem = xyes; then
+ AC_DEFINE(SDL_FILESYSTEM_COCOA, 1, [ ])
+ SOURCES="$SOURCES $srcdir/src/filesystem/cocoa/*.m"
+ have_filesystem=yes
+ fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
AC_DEFINE(SDL_TIMER_UNIX, 1, [ ])
@@ -2760,6 +2795,12 @@ if test x$have_timers != xyes; then
fi
SOURCES="$SOURCES $srcdir/src/timer/dummy/*.c"
fi
+if test x$have_filesystem != xyes; then
+ if test x$enable_filesystem = xyes; then
+ AC_DEFINE(SDL_FILESYSTEM_DISABLED, 1, [ ])
+ fi
+ SOURCES="$SOURCES $srcdir/src/filesystem/dummy/*.c"
+fi
if test x$have_loadso != xyes; then
if test x$enable_loadso = xyes; then
AC_DEFINE(SDL_LOADSO_DISABLED, 1, [ ])
diff --git a/include/SDL.h b/include/SDL.h
index ca098ae..8b8a61c 100644
--- a/include/SDL.h
+++ b/include/SDL.h
@@ -74,6 +74,7 @@
#include "SDL_endian.h"
#include "SDL_error.h"
#include "SDL_events.h"
+#include "SDL_filesystem.h"
#include "SDL_joystick.h"
#include "SDL_gamecontroller.h"
#include "SDL_haptic.h"
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 12c14fa..500e72a 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -182,6 +182,7 @@
#cmakedefine SDL_TIMERS_DISABLED @SDL_TIMERS_DISABLED@
#cmakedefine SDL_VIDEO_DISABLED @SDL_VIDEO_DISABLED@
#cmakedefine SDL_POWER_DISABLED @SDL_POWER_DISABLED@
+#cmakedefine SDL_FILESYSTEM_DISABLED @SDL_FILESYSTEM_DISABLED@
/* Enable various audio drivers */
#cmakedefine SDL_AUDIO_DRIVER_ALSA @SDL_AUDIO_DRIVER_ALSA@
@@ -301,6 +302,13 @@
#cmakedefine SDL_POWER_BEOS @SDL_POWER_BEOS@
#cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@
+/* Enable system filesystem support */
+#cmakedefine SDL_FILESYSTEM_BEOS @SDL_FILESYSTEM_BEOS@
+#cmakedefine SDL_FILESYSTEM_COCOA @SDL_FILESYSTEM_COCOA@
+#cmakedefine SDL_FILESYSTEM_DUMMY @SDL_FILESYSTEM_DUMMY@
+#cmakedefine SDL_FILESYSTEM_UNIX @SDL_FILESYSTEM_UNIX@
+#cmakedefine SDL_FILESYSTEM_WINDOWS @SDL_FILESYSTEM_WINDOWS@
+
/* Enable assembly routines */
#cmakedefine SDL_ASSEMBLY_ROUTINES @SDL_ASSEMBLY_ROUTINES@
#cmakedefine SDL_ALTIVEC_BLITTERS @SDL_ALTIVEC_BLITTERS@
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index 3f92d57..7bb1283 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -184,6 +184,7 @@
#undef SDL_TIMERS_DISABLED
#undef SDL_VIDEO_DISABLED
#undef SDL_POWER_DISABLED
+#undef SDL_FILESYSTEM_DISABLED
/* Enable various audio drivers */
#undef SDL_AUDIO_DRIVER_ALSA
@@ -303,6 +304,13 @@
#undef SDL_POWER_BEOS
#undef SDL_POWER_HARDWIRED
+/* Enable system filesystem support */
+#undef SDL_FILESYSTEM_BEOS
+#undef SDL_FILESYSTEM_COCOA
+#undef SDL_FILESYSTEM_DUMMY
+#undef SDL_FILESYSTEM_UNIX
+#undef SDL_FILESYSTEM_WINDOWS
+
/* Enable assembly routines */
#undef SDL_ASSEMBLY_ROUTINES
#undef SDL_ALTIVEC_BLITTERS
diff --git a/include/SDL_config_android.h b/include/SDL_config_android.h
index 7c6b6cb..0826415 100644
--- a/include/SDL_config_android.h
+++ b/include/SDL_config_android.h
@@ -136,4 +136,7 @@
/* Enable system power support */
#define SDL_POWER_ANDROID 1
+/* !!! FIXME: what does Android do for filesystem stuff? */
+#define SDL_FILESYSTEM_DUMMY 1
+
#endif /* _SDL_config_android_h */
diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h
index b27b189..ade2966 100644
--- a/include/SDL_config_iphoneos.h
+++ b/include/SDL_config_iphoneos.h
@@ -148,4 +148,7 @@
*/
#define SDL_IPHONE_MAX_GFORCE 5.0
+/* enable filesystem support */
+#define SDL_FILESYSTEM_COCOA 1
+
#endif /* _SDL_config_iphoneos_h */
diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h
index 68a0ebb..9f2f76e 100644
--- a/include/SDL_config_macosx.h
+++ b/include/SDL_config_macosx.h
@@ -171,6 +171,9 @@
/* Enable system power support */
#define SDL_POWER_MACOSX 1
+/* enable filesystem support */
+#define SDL_FILESYSTEM_COCOA 1
+
/* Enable assembly routines */
#define SDL_ASSEMBLY_ROUTINES 1
#ifdef __ppc__
diff --git a/include/SDL_config_minimal.h b/include/SDL_config_minimal.h
index fe3cebc..3248bdd 100644
--- a/include/SDL_config_minimal.h
+++ b/include/SDL_config_minimal.h
@@ -75,4 +75,7 @@ typedef unsigned long uintptr_t;
/* Enable the dummy video driver (src/video/dummy/\*.c) */
#define SDL_VIDEO_DRIVER_DUMMY 1
+/* Enable the dummy filesystem driver (src/filesystem/dummy/\*.c) */
+#define SDL_FILESYSTEM_DUMMY 1
+
#endif /* _SDL_config_minimal_h */
diff --git a/include/SDL_config_pandora.h b/include/SDL_config_pandora.h
index b93a1bc..4bfad48 100644
--- a/include/SDL_config_pandora.h
+++ b/include/SDL_config_pandora.h
@@ -114,6 +114,7 @@
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1
#define SDL_TIMER_UNIX 1
+#define SDL_FILESYSTEM_UNIX 1
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_X11 1
diff --git a/include/SDL_config_psp.h b/include/SDL_config_psp.h
index 85cf53c..09eef29 100644
--- a/include/SDL_config_psp.h
+++ b/include/SDL_config_psp.h
@@ -126,6 +126,9 @@
#define SDL_POWER_PSP 1
+/* !!! FIXME: what does PSP do for filesystem stuff? */
+#define SDL_FILESYSTEM_DUMMY 1
+
/* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */
#define SDL_HAPTIC_DISABLED 1
diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h
index 0b76215..9f3448e 100644
--- a/include/SDL_config_windows.h
+++ b/include/SDL_config_windows.h
@@ -181,6 +181,9 @@ typedef unsigned int uintptr_t;
/* Enable system power support */
#define SDL_POWER_WINDOWS 1
+/* Enable filesystem support */
+#define SDL_FILESYSTEM_WINDOWS 1
+
/* Enable assembly routines (Win64 doesn't have inline asm) */
#ifndef _WIN64
#define SDL_ASSEMBLY_ROUTINES 1
diff --git a/include/SDL_filesystem.h b/include/SDL_filesystem.h
new file mode 100644
index 0000000..71ced94
--- /dev/null
+++ b/include/SDL_filesystem.h
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_filesystem.h
+ *
+ * \brief Include file for filesystem SDL API functions
+ */
+
+#ifndef _SDL_filesystem_h
+#define _SDL_filesystem_h
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Get the path where the application resides.
+ *
+ * Get the "base path". This is the directory where the application was run
+ * from, which is probably the installation directory, and may or may not
+ * be the process's current working directory.
+ *
+ * This returns an absolute path in UTF-8 encoding, and is guaranteed to
+ * end with a path separator ('\\' on Windows, '/' most other places).
+ *
+ * The pointer returned by this function is owned by you. Please call
+ * SDL_free() on the pointer when you are done with it, or it will be a
+ * memory leak. This is not necessarily a fast call, though, so you should
+ * call this once near startup and save the string if you need it.
+ *
+ * Some platforms can't determine the application's path, and on other
+ * platforms, this might be meaningless. In such cases, this function will
+ * return NULL.
+ *
+ * \return String of base dir in UTF-8 encoding, or NULL on error.
+ *
+ * \sa SDL_GetPrefPath
+ */
+extern DECLSPEC char *SDLCALL SDL_GetBasePath(void);
+
+/**
+ * \brief Get the user-and-app-specific path where files can be written.
+ *
+ * Get the "pref dir". This is meant to be where users can write personal
+ * files (preferences and save games, etc) that are specific to your
+ * application. This directory is unique per user, per application.
+ *
+ * This function will decide the appropriate location in the native filesystem,
+ * create the directory if necessary, and return a string of the absolute
+ * path to the directory in UTF-8 encoding.
+ *
+ * On Windows, the string might look like:
+ * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name"
+ *
+ * On Linux, the string might look like:
+ * "/home/bob/.local/share/My Program Name"
+ *
+ * On Mac OS X, the string might look like:
+ * "/Users/bob/Library/Application Support/My Program Name"
+ *
+ * (etc.)
+ *
+ * You specify the name of your organization (if it's not a real organization,
+ * your name or an Internet domain you own might do) and the name of your
+ * application. These should be untranslated proper names.
+ *
+ * Both the org and app strings may become part of a directory name, so
+ * please follow these rules:
+ *
+ * - Try to use the same org string (including case-sensitivity) for
+ * all your applications that use this function.
+ * - Always use a unique app string for each one, and make sure it never
+ * changes for an app once you've decided on it.
+ * - Unicode characters are legal, as long as it's UTF-8 encoded, but...
+ * - ...only use letters, numbers, and spaces. Avoid punctuation like
+ * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
+ *
+ * This returns an absolute path in UTF-8 encoding, and is guaranteed to
+ * end with a path separator ('\\' on Windows, '/' most other places).
+ *
+ * The pointer returned by this function is owned by you. Please call
+ * SDL_free() on the pointer when you are done with it, or it will be a
+ * memory leak. This is not necessarily a fast call, though, so you should
+ * call this once near startup and save the string if you need it.
+ *
+ * You should assume the path returned by this function is the only safe
+ * place to write files (and that SDL_GetBasePath(), while it might be
+ * writable, or even the parent of the returned path, aren't where you
+ * should be writing things).
+ *
+ * Some platforms can't determine the pref path, and on other
+ * platforms, this might be meaningless. In such cases, this function will
+ * return NULL.
+ *
+ * \param org The name of your organization.
+ * \param app The name of your application.
+ * \return UTF-8 string of user dir in platform-dependent notation. NULL
+ * if there's a problem (creating directory failed, etc).
+ *
+ * \sa SDL_GetBasePath
+ */
+extern DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* _SDL_system_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/filesystem/beos/SDL_sysfilesystem.cc b/src/filesystem/beos/SDL_sysfilesystem.cc
new file mode 100644
index 0000000..7b63fab
--- /dev/null
+++ b/src/filesystem/beos/SDL_sysfilesystem.cc
@@ -0,0 +1,92 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_FILESYSTEM_BEOS
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <os/kernel/image.h>
+#include <os/storage/Directory.h>
+#include <os/storage/Path.h>
+
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ image_info info;
+ int32 cookie = 0;
+
+ while (get_next_image_info(0, &cookie, &info) == B_OK) {
+ if (info.type == B_APP_IMAGE) {
+ break;
+ }
+ }
+
+ BEntry entry(info.name, true);
+ BPath path;
+ status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */
+ SDL_assert(rc == B_OK);
+ rc = path.GetParent(&path); /* chop filename, keep directory. */
+ SDL_assert(rc == B_OK);
+ const char *str = path.Path();
+ SDL_assert(str != NULL);
+
+ const size_t len = SDL_strlen(str);
+ char *retval = (char *) SDL_malloc(len + 2);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ SDL_strcpy(retval, str);
+ retval[len] = '/';
+ retval[len+1] = '\0';
+ return retval;
+}
+
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ // !!! FIXME: is there a better way to do this?
+ const char *home = SDL_getenv("HOME");
+ const char *append = "config/settings/";
+ const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(app) + 2;
+ char *retval = (char *) SDL_malloc(len);
+ if (!retval) {
+ SDL_OutOfMemory();
+ } else {
+ SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
+ create_directory(retval, 0700); // BeOS api: creates missing dirs
+ }
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_BEOS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/filesystem/cocoa/SDL_sysfilesystem.m b/src/filesystem/cocoa/SDL_sysfilesystem.m
new file mode 100644
index 0000000..3c45974
--- /dev/null
+++ b/src/filesystem/cocoa/SDL_sysfilesystem.m
@@ -0,0 +1,93 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_FILESYSTEM_COCOA
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <Cocoa/Cocoa.h>
+#include <sys/stat.h>
+
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ const char *base = [[[NSBundle mainBundle] bundlePath] UTF8String];
+ char *retval = NULL;
+ if (base) {
+ const size_t len = SDL_strlen(base) + 2;
+ retval = (char *) SDL_malloc(len);
+ if (retval == NULL) {
+ SDL_OutOfMemory();
+ } else {
+ SDL_snprintf(retval, len, "%s/", base);
+ }
+ }
+
+ [pool release];
+ return retval;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ char *retval = NULL;
+
+ (void) org; // unused on Mac OS X and iOS.
+
+ if ([array count] > 0) { // we only want the first item in the list.
+ NSString *str = [array objectAtIndex:0];
+ const char *base = [str UTF8String];
+ if (base) {
+ const size_t len = SDL_strlen(base) + SDL_strlen(app) + 3;
+ retval = (char *) SDL_malloc(len);
+ if (retval == NULL) {
+ SDL_OutOfMemory();
+ } else {
+ char *ptr;
+ SDL_snprintf(retval, len, "%s/%s/", base, app);
+ for (ptr = retval+1; *ptr; ptr++) {
+ if (*ptr == '/') {
+ *ptr = '\0';
+ mkdir(retval, 0700);
+ *ptr = '/';
+ }
+ }
+ mkdir(retval, 0700);
+ }
+ }
+ }
+
+ [pool release];
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/filesystem/dummy/SDL_sysfilesystem.c b/src/filesystem/dummy/SDL_sysfilesystem.c
new file mode 100644
index 0000000..a6bd577
--- /dev/null
+++ b/src/filesystem/dummy/SDL_sysfilesystem.c
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_FILESYSTEM_DUMMY
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include "SDL_error.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ SDL_Unsupported();
+ return NULL;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ SDL_Unsupported();
+ return NULL;
+}
+
+#endif /* SDL_FILESYSTEM_DUMMY */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
new file mode 100644
index 0000000..326637e
--- /dev/null
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -0,0 +1,161 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_FILESYSTEM_UNIX
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <unistd.h>
+
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_filesystem.h"
+
+static char *readSymLink(const char *path)
+{
+ char *retval = NULL;
+ ssize_t len = 64;
+ ssize_t rc = -1;
+
+ while (1)
+ {
+ char *ptr = (char *) SDL_realloc(retval, (size_t) len);
+ if (ptr == NULL) {
+ SDL_OutOfMemory();
+ break;
+ }
+
+ retval = ptr;
+
+ rc = readlink(path, retval, len);
+ if (rc == -1) {
+ break; /* not a symlink, i/o error, etc. */
+ } else if (rc < len) {
+ retval[rc] = '\0'; /* readlink doesn't null-terminate. */
+ return retval; /* we're good to go. */
+ }
+
+ len *= 2; /* grow buffer, try again. */
+ }
+
+ if (retval != NULL) {
+ SDL_free(retval);
+ }
+ return NULL;
+}
+
+
+char *
+SDL_GetBasePath(void)
+{
+ char *retval = NULL;
+
+ /* is a Linux-style /proc filesystem available? */
+ if (access("/proc", F_OK) {
+ retval = readSymLink("/proc/self/exe");
+ if (retval == NULL) {
+ /* older kernels don't have /proc/self ... try PID version... */
+ char path[64];
+ const int rc = (int) SDL_snprintf(path, sizeof(path),
+ "/proc/%llu/exe",
+ (unsigned long long) getpid());
+ if ( (rc > 0) && (rc < sizeof(path)) ) {
+ retval = readSymLink(path);
+ }
+ }
+ }
+
+ /* If we had access to argv[0] here, we could check it for a path,
+ or troll through $PATH looking for it, too. */
+
+ if (retval != NULL) { /* chop off filename. */
+ char *ptr = SDL_strrchr(retval, '/');
+ if (ptr != NULL) {
+ *(ptr+1) = '\0';
+ } else { /* shouldn't happen, but just in case... */
+ SDL_free(retval);
+ retval = NULL;
+ }
+ }
+
+ if (retval != NULL) {
+ /* try to shrink buffer... */
+ char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
+ if (ptr != NULL)
+ retval = ptr; /* oh well if it failed. */
+ }
+
+ return retval;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ /*
+ * We use XDG's base directory spec, even if you're not on Linux.
+ * This isn't strictly correct, but the results are relatively sane
+ * in any case.
+ *
+ * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+ */
+ const char *envr = SDL_getenv("XDG_DATA_HOME");
+ const char *append = "/";
+ char *retval = NULL;
+ char *ptr = NULL;
+ size_t len = 0;
+
+ if (!envr) {
+ /* You end up with "$HOME/.local/share/Game Name 2" */
+ envr = SDL_getenv("HOME");
+ if (!envr) {
+ /* we could take heroic measures with /etc/passwd, but oh well. */
+ SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
+ return NULL;
+ }
+ append = ".local/share/";
+ } /* if */
+
+ len = SDL_strlen(envr) + SDL_strlen(append) + SDL_strlen(app) + 2;
+ retval = (char *) SDL_malloc(len);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
+
+ for (ptr = retval+1; *ptr; ptr++) {
+ if (*ptr == '/') {
+ *ptr = '\0';
+ mkdir(retval, 0700);
+ *ptr = '/';
+ }
+ }
+ mkdir(retval, 0700);
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_UNIX */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c
new file mode 100644
index 0000000..fc17d5e
--- /dev/null
+++ b/src/filesystem/windows/SDL_sysfilesystem.c
@@ -0,0 +1,96 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_FILESYSTEM_WINDOWS
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include "SDL_error.h"
+#include "SDL_windows.h"
+#include "SDL_stdinc.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ TCHAR path[MAX_PATH];
+ const DWORD len = GetModuleFileName(NULL, path, SDL_arraysize(path));
+ size_t i;
+
+ SDL_assert(len < SDL_arraysize(path));
+
+ if (len == 0) {
+ WIN_SetError("Couldn't locate our .exe");
+ return NULL;
+ }
+
+ for (i = len-1; i > 0; i--) {
+ if (path[i] == '\\') {
+ break;
+ }
+ }
+
+ SDL_assert(i > 0); /* Should have been an absolute path. */
+ path[i+1] = '\0'; /* chop off filename. */
+ return WIN_StringToUTF8(path);
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ /*
+ * Vista and later has a new API for this, but SHGetFolderPath works there,
+ * and apparently just wraps the new API. This is the new way to do it:
+ *
+ * SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
+ * NULL, &wszPath);
+ */
+
+ TCHAR path[MAX_PATH];
+ char *utf8 = NULL;
+ char *retval = NULL;
+
+ if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
+ WIN_SetError("Couldn't locate our prefpath");
+ return NULL;
+ }
+
+ utf8 = WIN_StringToUTF8(path);
+ if (utf8) {
+ const size_t len = SDL_strlen(utf8) + SDL_strlen(org) + SDL_strlen(app) + 4;
+ retval = (char *) SDL_malloc(len);
+ if (!retval) {
+ SDL_free(utf8);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
+ SDL_free(utf8);
+ }
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/test/Makefile.in b/test/Makefile.in
index 2a39afc..ed0fce3 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -36,6 +36,7 @@ TARGETS = \
testoverlay2$(EXE) \
testplatform$(EXE) \
testpower$(EXE) \
+ testfilesystem$(EXE) \
testrendertarget$(EXE) \
testresample$(EXE) \
testscale$(EXE) \
@@ -180,6 +181,9 @@ testplatform$(EXE): $(srcdir)/testplatform.c
testpower$(EXE): $(srcdir)/testpower.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+testfilesystem$(EXE): $(srcdir)/testfilesystem.c
+ $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+
testrendertarget$(EXE): $(srcdir)/testrendertarget.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
diff --git a/test/testfilesystem.c b/test/testfilesystem.c
new file mode 100644
index 0000000..e1f2513
--- /dev/null
+++ b/test/testfilesystem.c
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely.
+*/
+/* Simple test of power subsystem. */
+
+#include <stdio.h>
+#include "SDL.h"
+
+int
+main(int argc, char *argv[])
+{
+ /* Enable standard application logging */
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+
+ if (SDL_Init(0) == -1) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
+ return 1;
+ }
+
+ SDL_Log("base path: '%s'\n", SDL_GetBasePath());
+ SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
+
+ SDL_Quit();
+ return 0;
+}