Compare commits
58 Commits
main
...
stable-3.0
Author | SHA1 | Date |
---|---|---|
Ryan C. Gordon | 119f182c8b | |
Ryan C. Gordon | aa4165c3c7 | |
Ozkan Sezer | 8c02d53f69 | |
Ryan C. Gordon | c743450d86 | |
Ryan C. Gordon | ee956e0e5c | |
Ryan C. Gordon | 2bb0d5c5f7 | |
Ryan C. Gordon | 395cccbd24 | |
Ryan C. Gordon | ca34091863 | |
Ozkan Sezer | 9e2be90470 | |
Ozkan Sezer | d024ca24de | |
Ozkan Sezer | 3bc65f1613 | |
Ozkan Sezer | 40ff5dba86 | |
Ozkan Sezer | 268d9e6266 | |
Ozkan Sezer | 4e91208cc3 | |
Ozkan Sezer | c27c67123c | |
alfadur | 7f4dbec16e | |
alfadur | 4d66ea5946 | |
pastdue | 543a1ae037 | |
pastdue | 3c32cd5600 | |
James Le Cuirot | 52c3f19e17 | |
Ryan C. Gordon | 21b4ccfc53 | |
Ryan C. Gordon | 751be263bf | |
Ryan C. Gordon | a4dc0a7129 | |
Matthew Albrecht | 99d0fef19e | |
Ryan C. Gordon | f3eb059e57 | |
Ryan C. Gordon | 911e253e00 | |
Ryan C. Gordon | 48ffe8ddf5 | |
Ryan C. Gordon | db2a4a5807 | |
Ryan C. Gordon | 6421738346 | |
Ryan C. Gordon | 557d1c58d5 | |
Ryan C. Gordon | fcfc99941f | |
Ryan C. Gordon | 0e38afca9b | |
Ryan C. Gordon | f5458fbc6c | |
Kevin d'Orange | 95fd951c57 | |
Ryan C. Gordon | 2ae6fe8833 | |
Ryan C. Gordon | f8f89035c4 | |
Ryan C. Gordon | 2dc2dd1b04 | |
Ryan C. Gordon | 81bb11ddbc | |
Ryan C. Gordon | fa34bb479d | |
Ryan C. Gordon | 9a825fcd77 | |
Ryan C. Gordon | 3ba1e363d1 | |
Ryan C. Gordon | 0d3d0afc9a | |
Ryan C. Gordon | 20da8fab65 | |
Ryan C. Gordon | 9ef9a06db3 | |
Ryan C. Gordon | 4a56820f1d | |
Ryan C. Gordon | b1c6c7f4a8 | |
Ryan C. Gordon | a828a91feb | |
Ryan C. Gordon | be0afe31e3 | |
Ryan C. Gordon | d08188c1e0 | |
Ryan C. Gordon | e216897cb9 | |
Ryan C. Gordon | ac1ee1a3f2 | |
Ryan C. Gordon | 9ea364e46e | |
Ryan C. Gordon | 179bd1d40a | |
Ryan C. Gordon | a80261989e | |
Ryan C. Gordon | b8aa7dab87 | |
Ryan C. Gordon | b9fd9e8100 | |
Ryan C. Gordon | e290b8d0a0 | |
Ryan C. Gordon | 12b7a80640 |
|
@ -1,2 +0,0 @@
|
||||||
github: [icculus]
|
|
||||||
patreon: icculus
|
|
|
@ -1,30 +0,0 @@
|
||||||
name: Build
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Build:
|
|
||||||
name: ${{ matrix.platform.name }}
|
|
||||||
runs-on: ${{ matrix.platform.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
platform: # !!! FIXME: figure out an efficient way to get SDL2 on the Windows/Mac bots.
|
|
||||||
- { name: Linux, os: ubuntu-20.04, flags: -GNinja }
|
|
||||||
- { name: MinGW, os: windows-latest, flags: -GNinja -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_SYSTEM_NAME=Windows }
|
|
||||||
- { name: Windows, os: windows-latest }
|
|
||||||
- { name: MacOS, os: macos-latest }
|
|
||||||
steps:
|
|
||||||
- name: Setup Linux dependencies
|
|
||||||
if: runner.os == 'Linux'
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install ninja-build
|
|
||||||
- name: Setup MinGW dependencies
|
|
||||||
if: contains(matrix.platform.name, 'MinGW')
|
|
||||||
run: choco install ninja
|
|
||||||
- name: Get PhysicsFS sources
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Configure CMake
|
|
||||||
run: cmake -B build ${{ matrix.platform.flags }}
|
|
||||||
- name: Build
|
|
||||||
run: cmake --build build/
|
|
|
@ -1,20 +0,0 @@
|
||||||
name: Build (OS/2)
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
os2:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: open-watcom/setup-watcom@v0
|
|
||||||
- name: Build physfs.dll
|
|
||||||
run: |
|
|
||||||
cd src
|
|
||||||
wmake -f Makefile.os2
|
|
||||||
cd ..
|
|
||||||
- name: distclean
|
|
||||||
run: |
|
|
||||||
cd src
|
|
||||||
wmake -f Makefile.os2 distclean
|
|
||||||
cd ..
|
|
|
@ -9,29 +9,29 @@
|
||||||
# compile, using preprocessor checks for platform-specific bits instead of
|
# compile, using preprocessor checks for platform-specific bits instead of
|
||||||
# testing in here.
|
# testing in here.
|
||||||
|
|
||||||
set(PHYSFS_VERSION 3.3.0)
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.0)
|
project(PhysicsFS)
|
||||||
|
set(PHYSFS_VERSION 3.0.3)
|
||||||
project(PhysicsFS VERSION ${PHYSFS_VERSION} LANGUAGES C )
|
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
# Increment this if/when we break backwards compatibility.
|
# Increment this if/when we break backwards compatibility.
|
||||||
set(PHYSFS_SOVERSION 1)
|
set(PHYSFS_SOVERSION 1)
|
||||||
|
|
||||||
set(PHYSFS_M_SRCS)
|
|
||||||
set(PHYSFS_CPP_SRCS)
|
|
||||||
|
|
||||||
# I hate that they define "WIN32" ... we're about to move to Win64...I hope!
|
# I hate that they define "WIN32" ... we're about to move to Win64...I hope!
|
||||||
|
if(WIN32 AND NOT WINDOWS)
|
||||||
|
set(WINDOWS TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(./src)
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework IOKit -framework Foundation")
|
set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework IOKit -framework Foundation")
|
||||||
list(APPEND PHYSFS_M_SRCS src/physfs_platform_apple.m)
|
set(PHYSFS_M_SRCS src/physfs_platform_apple.m)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
add_compile_options(-Wall)
|
|
||||||
# Don't use -rpath.
|
# Don't use -rpath.
|
||||||
set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
|
set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
@ -44,10 +44,10 @@ endif()
|
||||||
if(HAIKU)
|
if(HAIKU)
|
||||||
# We add this explicitly, since we don't want CMake to think this
|
# We add this explicitly, since we don't want CMake to think this
|
||||||
# is a C++ project unless we're on Haiku.
|
# is a C++ project unless we're on Haiku.
|
||||||
list(APPEND PHYSFS_CPP_SRCS src/physfs_platform_haiku.cpp)
|
set(PHYSFS_CPP_SRCS src/physfs_platform_haiku.cpp)
|
||||||
find_library(BE_LIBRARY be)
|
find_library(BE_LIBRARY be)
|
||||||
find_library(ROOT_LIBRARY root)
|
find_library(ROOT_LIBRARY root)
|
||||||
list(APPEND OPTIONAL_LIBRARY_LIBS ${BE_LIBRARY} ${ROOT_LIBRARY})
|
set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||||
|
@ -55,20 +55,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "Wind
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WINRT)
|
if(WINRT)
|
||||||
list(APPEND PHYSFS_CPP_SRCS src/physfs_platform_winrt.cpp)
|
set(PHYSFS_CPP_SRCS src/physfs_platform_winrt.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(UNIX AND NOT WIN32 AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!)
|
if(UNIX AND NOT WINDOWS AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!)
|
||||||
find_library(PTHREAD_LIBRARY pthread)
|
find_library(PTHREAD_LIBRARY pthread)
|
||||||
if(PTHREAD_LIBRARY)
|
if(PTHREAD_LIBRARY)
|
||||||
set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
|
set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PHYSFS_CPP_SRCS)
|
|
||||||
enable_language(CXX)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Almost everything is "compiled" here, but things that don't apply to the
|
# Almost everything is "compiled" here, but things that don't apply to the
|
||||||
# build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
|
# build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
|
||||||
# another project or bring up a new build system: just compile all the source
|
# another project or bring up a new build system: just compile all the source
|
||||||
|
@ -82,7 +78,6 @@ set(PHYSFS_SRCS
|
||||||
src/physfs_platform_windows.c
|
src/physfs_platform_windows.c
|
||||||
src/physfs_platform_os2.c
|
src/physfs_platform_os2.c
|
||||||
src/physfs_platform_qnx.c
|
src/physfs_platform_qnx.c
|
||||||
src/physfs_platform_android.c
|
|
||||||
src/physfs_archiver_dir.c
|
src/physfs_archiver_dir.c
|
||||||
src/physfs_archiver_unpacked.c
|
src/physfs_archiver_unpacked.c
|
||||||
src/physfs_archiver_grp.c
|
src/physfs_archiver_grp.c
|
||||||
|
@ -158,8 +153,6 @@ endif()
|
||||||
option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
|
option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
|
||||||
if(PHYSFS_BUILD_STATIC)
|
if(PHYSFS_BUILD_STATIC)
|
||||||
add_library(physfs-static STATIC ${PHYSFS_SRCS})
|
add_library(physfs-static STATIC ${PHYSFS_SRCS})
|
||||||
add_library(PhysFS::PhysFS-static ALIAS physfs-static)
|
|
||||||
set_target_properties(physfs-static PROPERTIES EXPORT_NAME PhysFS-static)
|
|
||||||
# Don't rename this on Windows, since DLLs will also produce an import
|
# Don't rename this on Windows, since DLLs will also produce an import
|
||||||
# library named "physfs.lib" which would conflict; Unix tend to like the
|
# library named "physfs.lib" which would conflict; Unix tend to like the
|
||||||
# same library name with a different extension for static libs, but
|
# same library name with a different extension for static libs, but
|
||||||
|
@ -176,30 +169,26 @@ if(PHYSFS_BUILD_STATIC)
|
||||||
# no dll exports from the static library
|
# no dll exports from the static library
|
||||||
target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
|
target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
|
||||||
endif()
|
endif()
|
||||||
target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
|
|
||||||
target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
|
|
||||||
set(PHYSFS_LIB_TARGET physfs-static)
|
set(PHYSFS_LIB_TARGET physfs-static)
|
||||||
list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
|
set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs-static")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
|
option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
|
||||||
if(PHYSFS_BUILD_SHARED)
|
if(PHYSFS_BUILD_SHARED)
|
||||||
add_library(physfs SHARED ${PHYSFS_SRCS})
|
add_library(physfs SHARED ${PHYSFS_SRCS})
|
||||||
add_library(PhysFS::PhysFS ALIAS physfs)
|
|
||||||
set_target_properties(physfs PROPERTIES MACOSX_RPATH 1)
|
set_target_properties(physfs PROPERTIES MACOSX_RPATH 1)
|
||||||
set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
|
set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
|
||||||
set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
|
set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
|
||||||
set_target_properties(physfs PROPERTIES EXPORT_NAME PhysFS)
|
|
||||||
if(WINRT)
|
if(WINRT)
|
||||||
set_target_properties(physfs PROPERTIES VS_WINRT_COMPONENT True)
|
set_target_properties(physfs PROPERTIES VS_WINRT_COMPONENT True)
|
||||||
endif()
|
endif()
|
||||||
if(OS2) # OS/2 does not support a DLL name longer than 8 characters.
|
if(OS2) # OS/2 does not support a DLL name longer than 8 characters.
|
||||||
set_target_properties(physfs PROPERTIES OUTPUT_NAME "physfs")
|
set_target_properties(physfs PROPERTIES OUTPUT_NAME "physfs")
|
||||||
endif()
|
endif()
|
||||||
target_include_directories(physfs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
|
target_link_libraries(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
|
||||||
target_link_libraries(physfs PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
|
|
||||||
set(PHYSFS_LIB_TARGET physfs)
|
set(PHYSFS_LIB_TARGET physfs)
|
||||||
list(APPEND PHYSFS_INSTALL_TARGETS "physfs")
|
set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
|
if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
|
||||||
|
@ -207,7 +196,7 @@ if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# CMake FAQ says I need this...
|
# CMake FAQ says I need this...
|
||||||
if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC AND NOT WIN32)
|
if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC AND NOT WINDOWS)
|
||||||
set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
endif()
|
endif()
|
||||||
|
@ -224,20 +213,17 @@ if(PHYSFS_BUILD_TEST)
|
||||||
find_library(READLINE_LIBRARY readline)
|
find_library(READLINE_LIBRARY readline)
|
||||||
if(READLINE_LIBRARY)
|
if(READLINE_LIBRARY)
|
||||||
set(HAVE_SYSTEM_READLINE TRUE)
|
set(HAVE_SYSTEM_READLINE TRUE)
|
||||||
list(APPEND TEST_PHYSFS_LIBS ${READLINE_LIBRARY} ${CURSES_LIBRARY})
|
set(TEST_PHYSFS_LIBS ${TEST_PHYSFS_LIBS} ${READLINE_LIBRARY} ${CURSES_LIBRARY})
|
||||||
include_directories(SYSTEM ${READLINE_H} ${HISTORY_H})
|
include_directories(SYSTEM ${READLINE_H} ${HISTORY_H})
|
||||||
add_definitions(-DPHYSFS_HAVE_READLINE=1)
|
add_definitions(-DPHYSFS_HAVE_READLINE=1)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
add_executable(test_physfs test/test_physfs.c)
|
add_executable(test_physfs test/test_physfs.c)
|
||||||
target_link_libraries(test_physfs PRIVATE ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
|
target_link_libraries(test_physfs ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
|
||||||
list(APPEND PHYSFS_INSTALL_TARGETS test_physfs)
|
set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";test_physfs")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(PHYSFS_DISABLE_INSTALL "Disable installing PhysFS" OFF)
|
|
||||||
if(NOT PHYSFS_DISABLE_INSTALL)
|
|
||||||
|
|
||||||
install(TARGETS ${PHYSFS_INSTALL_TARGETS} EXPORT PhysFSExport
|
install(TARGETS ${PHYSFS_INSTALL_TARGETS} EXPORT PhysFSExport
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
@ -248,25 +234,9 @@ if(NOT PHYSFS_DISABLE_INSTALL)
|
||||||
install(EXPORT PhysFSExport
|
install(EXPORT PhysFSExport
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/PhysFS"
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/PhysFS"
|
||||||
FILE PhysFSConfig.cmake
|
FILE PhysFSConfig.cmake
|
||||||
NAMESPACE PhysFS::
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT MSVC)
|
|
||||||
configure_file(
|
|
||||||
"extras/physfs.pc.in"
|
|
||||||
"extras/physfs.pc"
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
|
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" TRUE)
|
|
||||||
if(PHYSFS_BUILD_DOCS)
|
|
||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
if(DOXYGEN_FOUND)
|
if(DOXYGEN_FOUND)
|
||||||
set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
|
set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
|
||||||
|
@ -281,18 +251,15 @@ if(PHYSFS_BUILD_DOCS)
|
||||||
file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
|
file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
|
||||||
|
|
||||||
set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target")
|
set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target")
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
${PHYSFS_TARGETNAME_DOCS}
|
${PHYSFS_TARGETNAME_DOCS}
|
||||||
${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
|
${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
COMMENT "Building documentation in 'docs' directory..."
|
COMMENT "Building documentation in 'docs' directory..."
|
||||||
)
|
)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
message(STATUS "Doxygen not found. You won't be able to build documentation.")
|
message(STATUS "Doxygen not found. You won't be able to build documentation.")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.gz")
|
set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.gz")
|
||||||
|
@ -314,6 +281,17 @@ if(UNIX)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
|
configure_file(
|
||||||
|
"extras/physfs.pc.in"
|
||||||
|
"extras/physfs.pc"
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
macro(message_bool_option _NAME _VALUE)
|
macro(message_bool_option _NAME _VALUE)
|
||||||
if(${_VALUE})
|
if(${_VALUE})
|
||||||
|
@ -337,7 +315,6 @@ message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
|
||||||
message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
|
message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
|
||||||
message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
|
message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
|
||||||
message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
|
message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
|
||||||
message_bool_option("Build Doxygen documentation" PHYSFS_BUILD_DOCS)
|
|
||||||
if(PHYSFS_BUILD_TEST)
|
if(PHYSFS_BUILD_TEST)
|
||||||
message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
|
message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -208,13 +208,13 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (!PHYSFS_init(argv[0]))
|
if (!PHYSFS_init(argv[0]))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_addToSearchPath(".", 1))
|
if (!PHYSFS_addToSearchPath(".", 1))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
|
@ -105,34 +105,34 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (!PHYSFS_init(argv[0]))
|
if (!PHYSFS_init(argv[0]))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_addToSearchPath(".", 1))
|
if (!PHYSFS_addToSearchPath(".", 1))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_setWriteDir("."))
|
if (!PHYSFS_setWriteDir("."))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_mkdir("/a/b/c"))
|
if (!PHYSFS_mkdir("/a/b/c"))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_mkdir("/a/b/C"))
|
if (!PHYSFS_mkdir("/a/b/C"))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -141,7 +141,7 @@ int main(int argc, char **argv)
|
||||||
PHYSFS_close(f);
|
PHYSFS_close(f);
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -150,7 +150,7 @@ int main(int argc, char **argv)
|
||||||
PHYSFS_close(f);
|
PHYSFS_close(f);
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
|
@ -70,7 +70,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
|
||||||
if (current == -1)
|
if (current == -1)
|
||||||
{
|
{
|
||||||
SDL_SetError("Can't find position in file: %s",
|
SDL_SetError("Can't find position in file: %s",
|
||||||
PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
PHYSFS_getLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
|
||||||
const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
|
const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
{
|
{
|
||||||
SDL_SetError("Can't find end of file: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
|
||||||
|
|
||||||
if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
|
if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
|
||||||
{
|
{
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
|
||||||
{
|
{
|
||||||
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
|
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
|
||||||
{
|
{
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -167,7 +167,7 @@ static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
|
||||||
const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
|
const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
|
||||||
const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
|
const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
|
||||||
if (rc != ((PHYSFS_sint64) writelen))
|
if (rc != ((PHYSFS_sint64) writelen))
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
return (size_t) rc;
|
return (size_t) rc;
|
||||||
|
@ -182,7 +182,7 @@ static int physfsrwops_close(SDL_RWops *rw)
|
||||||
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
||||||
if (!PHYSFS_close(handle))
|
if (!PHYSFS_close(handle))
|
||||||
{
|
{
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ static SDL_RWops *create_rwops(PHYSFS_File *handle)
|
||||||
SDL_RWops *retval = NULL;
|
SDL_RWops *retval = NULL;
|
||||||
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retval = SDL_AllocRW();
|
retval = SDL_AllocRW();
|
||||||
|
|
|
@ -28,7 +28,7 @@ static void modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
|
||||||
static void fail(const char *what, const char *why)
|
static void fail(const char *what, const char *why)
|
||||||
{
|
{
|
||||||
if (why == NULL)
|
if (why == NULL)
|
||||||
why = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
|
why = PHYSFS_getLastError();
|
||||||
fprintf(stderr, "%s failed: %s\n", what, why);
|
fprintf(stderr, "%s failed: %s\n", what, why);
|
||||||
failure = 1;
|
failure = 1;
|
||||||
} /* fail */
|
} /* fail */
|
||||||
|
@ -150,21 +150,21 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (!PHYSFS_init(argv[0]))
|
if (!PHYSFS_init(argv[0]))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_init() failed: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
fprintf(stderr, "PHYSFS_init() failed: %s\n", PHYSFS_getLastError());
|
||||||
return 2;
|
return 2;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_setWriteDir(argv[2]))
|
if (!PHYSFS_setWriteDir(argv[2]))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_setWriteDir('%s') failed: %s\n",
|
fprintf(stderr, "PHYSFS_setWriteDir('%s') failed: %s\n",
|
||||||
argv[2], PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
argv[2], PHYSFS_getLastError());
|
||||||
return 3;
|
return 3;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (!PHYSFS_mount(argv[1], NULL, 1))
|
if (!PHYSFS_mount(argv[1], NULL, 1))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PHYSFS_mount('%s') failed: %s\n",
|
fprintf(stderr, "PHYSFS_mount('%s') failed: %s\n",
|
||||||
argv[1], PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
argv[1], PHYSFS_getLastError());
|
||||||
return 4;
|
return 4;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,14 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (!PHYSFS_init(argv[0]))
|
if (!PHYSFS_init(argv[0]))
|
||||||
{
|
{
|
||||||
printf("PHYSFS_init() failed: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
printf("PHYSFS_init() failed: %s\n", PHYSFS_getLastError());
|
||||||
return 42;
|
return 42;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
rc = PHYSFS_addToSearchPath(argv[0], 0);
|
rc = PHYSFS_addToSearchPath(argv[0], 0);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
printf("Couldn't find self-extract data: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
printf("Couldn't find self-extract data: %s\n", PHYSFS_getLastError());
|
||||||
printf("This might mean you didn't append a zipfile to the binary.\n");
|
printf("This might mean you didn't append a zipfile to the binary.\n");
|
||||||
return 42;
|
return 42;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# wmake -f Makefile.os2
|
# wmake -f Makefile.os2
|
||||||
|
|
||||||
LIBNAME = physfs
|
LIBNAME = physfs
|
||||||
VERSION = 3.3.0
|
VERSION = 3.0.3
|
||||||
|
|
||||||
LIBFILE = $(LIBNAME).lib
|
LIBFILE = $(LIBNAME).lib
|
||||||
DLLFILE = $(LIBNAME).dll
|
DLLFILE = $(LIBNAME).dll
|
||||||
|
|
323
src/physfs.c
323
src/physfs.c
|
@ -44,8 +44,6 @@ typedef struct __PHYSFS_DIRHANDLE__
|
||||||
void *opaque; /* Instance data unique to the archiver. */
|
void *opaque; /* Instance data unique to the archiver. */
|
||||||
char *dirName; /* Path to archive in platform-dependent notation. */
|
char *dirName; /* Path to archive in platform-dependent notation. */
|
||||||
char *mountPoint; /* Mountpoint in virtual file tree. */
|
char *mountPoint; /* Mountpoint in virtual file tree. */
|
||||||
char *root; /* subdirectory of archiver to use as root of archive (NULL for actual root) */
|
|
||||||
size_t rootlen; /* subdirectory of archiver to use as root of archive (NULL for actual root) */
|
|
||||||
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
|
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
|
||||||
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */
|
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */
|
||||||
} DirHandle;
|
} DirHandle;
|
||||||
|
@ -86,7 +84,6 @@ static int allowSymLinks = 0;
|
||||||
static PHYSFS_Archiver **archivers = NULL;
|
static PHYSFS_Archiver **archivers = NULL;
|
||||||
static PHYSFS_ArchiveInfo **archiveInfo = NULL;
|
static PHYSFS_ArchiveInfo **archiveInfo = NULL;
|
||||||
static volatile size_t numArchivers = 0;
|
static volatile size_t numArchivers = 0;
|
||||||
static size_t longest_root = 0;
|
|
||||||
|
|
||||||
/* mutexes ... */
|
/* mutexes ... */
|
||||||
static void *errorLock = NULL; /* protects error message list. */
|
static void *errorLock = NULL; /* protects error message list. */
|
||||||
|
@ -921,12 +918,12 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting)
|
||||||
retval = tryOpenDir(io, *i, d, forWriting, &claimed);
|
retval = tryOpenDir(io, *i, d, forWriting, &claimed);
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
errcode = claimed ? currentErrorCode() : PHYSFS_ERR_UNSUPPORTED;
|
errcode = currentErrorCode();
|
||||||
|
|
||||||
if ((!retval) && (created_io))
|
if ((!retval) && (created_io))
|
||||||
io->destroy(io);
|
io->destroy(io);
|
||||||
|
|
||||||
BAIL_IF(!retval, errcode, NULL);
|
BAIL_IF(!retval, claimed ? errcode : PHYSFS_ERR_UNSUPPORTED, NULL);
|
||||||
return retval;
|
return retval;
|
||||||
} /* openDirectory */
|
} /* openDirectory */
|
||||||
|
|
||||||
|
@ -981,18 +978,6 @@ static int sanitizePlatformIndependentPath(const char *src, char *dst)
|
||||||
} /* sanitizePlatformIndependentPath */
|
} /* sanitizePlatformIndependentPath */
|
||||||
|
|
||||||
|
|
||||||
static inline size_t dirHandleRootLen(const DirHandle *h)
|
|
||||||
{
|
|
||||||
return h ? h->rootlen : 0;
|
|
||||||
} /* dirHandleRootLen */
|
|
||||||
|
|
||||||
static inline int sanitizePlatformIndependentPathWithRoot(const DirHandle *h, const char *src, char *dst)
|
|
||||||
{
|
|
||||||
return sanitizePlatformIndependentPath(src, dst + dirHandleRootLen(h));
|
|
||||||
} /* sanitizePlatformIndependentPathWithRoot */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Figure out if (fname) is part of (h)'s mountpoint. (fname) must be an
|
* Figure out if (fname) is part of (h)'s mountpoint. (fname) must be an
|
||||||
* output from sanitizePlatformIndependentPath(), so that it is in a known
|
* output from sanitizePlatformIndependentPath(), so that it is in a known
|
||||||
|
@ -1093,8 +1078,6 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)
|
||||||
BAIL_IF(i->dirHandle == dh, PHYSFS_ERR_FILES_STILL_OPEN, 0);
|
BAIL_IF(i->dirHandle == dh, PHYSFS_ERR_FILES_STILL_OPEN, 0);
|
||||||
|
|
||||||
dh->funcs->closeArchive(dh->opaque);
|
dh->funcs->closeArchive(dh->opaque);
|
||||||
|
|
||||||
if (dh->root) allocator.Free(dh->root);
|
|
||||||
allocator.Free(dh->dirName);
|
allocator.Free(dh->dirName);
|
||||||
allocator.Free(dh->mountPoint);
|
allocator.Free(dh->mountPoint);
|
||||||
allocator.Free(dh);
|
allocator.Free(dh);
|
||||||
|
@ -1233,9 +1216,7 @@ int PHYSFS_init(const char *argv0)
|
||||||
if (!userDir) goto initFailed;
|
if (!userDir) goto initFailed;
|
||||||
|
|
||||||
/* Platform layer is required to append a dirsep. */
|
/* Platform layer is required to append a dirsep. */
|
||||||
#ifndef __ANDROID__ /* it's an APK file, not a directory, on Android. */
|
|
||||||
assert(baseDir[strlen(baseDir) - 1] == __PHYSFS_platformDirSeparator);
|
assert(baseDir[strlen(baseDir) - 1] == __PHYSFS_platformDirSeparator);
|
||||||
#endif
|
|
||||||
assert(userDir[strlen(userDir) - 1] == __PHYSFS_platformDirSeparator);
|
assert(userDir[strlen(userDir) - 1] == __PHYSFS_platformDirSeparator);
|
||||||
|
|
||||||
if (!initStaticArchivers()) goto initFailed;
|
if (!initStaticArchivers()) goto initFailed;
|
||||||
|
@ -1395,7 +1376,6 @@ static int doDeinit(void)
|
||||||
archivers = NULL;
|
archivers = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
longest_root = 0;
|
|
||||||
allowSymLinks = 0;
|
allowSymLinks = 0;
|
||||||
initialized = 0;
|
initialized = 0;
|
||||||
|
|
||||||
|
@ -1435,60 +1415,15 @@ char *__PHYSFS_strdup(const char *str)
|
||||||
} /* __PHYSFS_strdup */
|
} /* __PHYSFS_strdup */
|
||||||
|
|
||||||
|
|
||||||
PHYSFS_uint32 __PHYSFS_hashString(const char *str)
|
PHYSFS_uint32 __PHYSFS_hashString(const char *str, size_t len)
|
||||||
{
|
{
|
||||||
PHYSFS_uint32 hash = 5381;
|
PHYSFS_uint32 hash = 5381;
|
||||||
while (1)
|
while (len--)
|
||||||
{
|
hash = ((hash << 5) + hash) ^ *(str++);
|
||||||
const char ch = *(str++);
|
|
||||||
if (ch == 0)
|
|
||||||
break;
|
|
||||||
hash = ((hash << 5) + hash) ^ ch;
|
|
||||||
} /* while */
|
|
||||||
return hash;
|
return hash;
|
||||||
} /* __PHYSFS_hashString */
|
} /* __PHYSFS_hashString */
|
||||||
|
|
||||||
|
|
||||||
PHYSFS_uint32 __PHYSFS_hashStringCaseFold(const char *str)
|
|
||||||
{
|
|
||||||
PHYSFS_uint32 hash = 5381;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
const PHYSFS_uint32 cp = __PHYSFS_utf8codepoint(&str);
|
|
||||||
if (cp == 0)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PHYSFS_uint32 folded[3];
|
|
||||||
const int numbytes = (int) (PHYSFS_caseFold(cp, folded) * sizeof (PHYSFS_uint32));
|
|
||||||
const char *bytes = (const char *) folded;
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < numbytes; i++)
|
|
||||||
hash = ((hash << 5) + hash) ^ *(bytes++);
|
|
||||||
} /* else */
|
|
||||||
} /* while */
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
} /* __PHYSFS_hashStringCaseFold */
|
|
||||||
|
|
||||||
|
|
||||||
PHYSFS_uint32 __PHYSFS_hashStringCaseFoldUSAscii(const char *str)
|
|
||||||
{
|
|
||||||
PHYSFS_uint32 hash = 5381;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
char ch = *(str++);
|
|
||||||
if (ch == 0)
|
|
||||||
break;
|
|
||||||
else if ((ch >= 'A') && (ch <= 'Z'))
|
|
||||||
ch -= ('A' - 'a');
|
|
||||||
|
|
||||||
hash = ((hash << 5) + hash) ^ ch;
|
|
||||||
} /* while */
|
|
||||||
return hash;
|
|
||||||
} /* __PHYSFS_hashStringCaseFoldUSAscii */
|
|
||||||
|
|
||||||
|
|
||||||
/* MAKE SURE you hold stateLock before calling this! */
|
/* MAKE SURE you hold stateLock before calling this! */
|
||||||
static int doRegisterArchiver(const PHYSFS_Archiver *_archiver)
|
static int doRegisterArchiver(const PHYSFS_Archiver *_archiver)
|
||||||
{
|
{
|
||||||
|
@ -1747,54 +1682,6 @@ int PHYSFS_setWriteDir(const char *newDir)
|
||||||
} /* PHYSFS_setWriteDir */
|
} /* PHYSFS_setWriteDir */
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_setRoot(const char *archive, const char *subdir)
|
|
||||||
{
|
|
||||||
DirHandle *i;
|
|
||||||
|
|
||||||
BAIL_IF(!archive, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
|
||||||
|
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
|
||||||
|
|
||||||
for (i = searchPath; i != NULL; i = i->next)
|
|
||||||
{
|
|
||||||
if ((i->dirName != NULL) && (strcmp(archive, i->dirName) == 0))
|
|
||||||
{
|
|
||||||
if (!subdir || (strcmp(subdir, "/") == 0))
|
|
||||||
{
|
|
||||||
if (i->root)
|
|
||||||
allocator.Free(i->root);
|
|
||||||
i->root = NULL;
|
|
||||||
i->rootlen = 0;
|
|
||||||
} /* if */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const size_t len = strlen(subdir) + 1;
|
|
||||||
char *ptr = (char *) allocator.Malloc(len);
|
|
||||||
BAIL_IF_MUTEX(!ptr, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
|
||||||
if (!sanitizePlatformIndependentPath(subdir, ptr))
|
|
||||||
{
|
|
||||||
allocator.Free(ptr);
|
|
||||||
BAIL_MUTEX_ERRPASS(stateLock, 0);
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
if (i->root)
|
|
||||||
allocator.Free(i->root);
|
|
||||||
i->root = ptr;
|
|
||||||
i->rootlen = strlen(i->root); /* in case sanitizePlatformIndependentPath changed subdir */
|
|
||||||
|
|
||||||
if (longest_root < i->rootlen)
|
|
||||||
longest_root = i->rootlen;
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
break;
|
|
||||||
} /* if */
|
|
||||||
} /* for */
|
|
||||||
|
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
|
||||||
return 1;
|
|
||||||
} /* PHYSFS_setRoot */
|
|
||||||
|
|
||||||
|
|
||||||
static int doMount(PHYSFS_Io *io, const char *fname,
|
static int doMount(PHYSFS_Io *io, const char *fname,
|
||||||
const char *mountPoint, int appendToPath)
|
const char *mountPoint, int appendToPath)
|
||||||
{
|
{
|
||||||
|
@ -2112,9 +1999,6 @@ int PHYSFS_symbolicLinksPermitted(void)
|
||||||
* like ".." which should be done once instead of once per archive. This also
|
* like ".." which should be done once instead of once per archive. This also
|
||||||
* gives us license to treat (fname) as scratch space in this function.
|
* gives us license to treat (fname) as scratch space in this function.
|
||||||
*
|
*
|
||||||
* (fname)'s buffer must have enough space available before it for this
|
|
||||||
* function to prepend any root directory for this DirHandle.
|
|
||||||
*
|
|
||||||
* Returns non-zero if string is safe, zero if there's a security issue.
|
* Returns non-zero if string is safe, zero if there's a security issue.
|
||||||
* PHYSFS_getLastError() will specify what was wrong. (*fname) will be
|
* PHYSFS_getLastError() will specify what was wrong. (*fname) will be
|
||||||
* updated to point past any mount point elements so it is prepared to
|
* updated to point past any mount point elements so it is prepared to
|
||||||
|
@ -2127,7 +2011,7 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing)
|
||||||
char *start;
|
char *start;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
if ((*fname == '\0') && (!h->root)) /* quick rejection. */
|
if (*fname == '\0') /* quick rejection. */
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* !!! FIXME: This codeblock sucks. */
|
/* !!! FIXME: This codeblock sucks. */
|
||||||
|
@ -2150,17 +2034,6 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing)
|
||||||
retval = 1; /* may be reset, below. */
|
retval = 1; /* may be reset, below. */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* prepend the root directory, if any. */
|
|
||||||
if (h->root)
|
|
||||||
{
|
|
||||||
const int isempty = (*fname == '\0');
|
|
||||||
fname -= h->rootlen + (isempty ? 0 : 1);
|
|
||||||
strcpy(fname, h->root);
|
|
||||||
if (!isempty)
|
|
||||||
fname[h->rootlen] = '/';
|
|
||||||
*_fname = fname;
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
start = fname;
|
start = fname;
|
||||||
if (!allowSymLinks)
|
if (!allowSymLinks)
|
||||||
{
|
{
|
||||||
|
@ -2206,19 +2079,20 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing)
|
||||||
} /* verifyPath */
|
} /* verifyPath */
|
||||||
|
|
||||||
|
|
||||||
/* This must hold the stateLock before calling. */
|
|
||||||
static int doMkdir(const char *_dname, char *dname)
|
static int doMkdir(const char *_dname, char *dname)
|
||||||
{
|
{
|
||||||
DirHandle *h = writeDir;
|
DirHandle *h;
|
||||||
char *start;
|
char *start;
|
||||||
char *end;
|
char *end;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
int exists = 1; /* force existance check on first path element. */
|
int exists = 1; /* force existance check on first path element. */
|
||||||
|
|
||||||
assert(h != NULL);
|
BAIL_IF_ERRPASS(!sanitizePlatformIndependentPath(_dname, dname), 0);
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!sanitizePlatformIndependentPathWithRoot(h, _dname, dname), 0);
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
BAIL_IF_ERRPASS(!verifyPath(h, &dname, 1), 0);
|
BAIL_IF_MUTEX(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0);
|
||||||
|
h = writeDir;
|
||||||
|
BAIL_IF_MUTEX_ERRPASS(!verifyPath(h, &dname, 1), stateLock, 0);
|
||||||
|
|
||||||
start = dname;
|
start = dname;
|
||||||
while (1)
|
while (1)
|
||||||
|
@ -2255,6 +2129,7 @@ static int doMkdir(const char *_dname, char *dname)
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
return retval;
|
return retval;
|
||||||
} /* doMkdir */
|
} /* doMkdir */
|
||||||
|
|
||||||
|
@ -2266,26 +2141,30 @@ int PHYSFS_mkdir(const char *_dname)
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
BAIL_IF(!_dname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!_dname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
|
len = strlen(_dname) + 1;
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
|
||||||
BAIL_IF_MUTEX(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0);
|
|
||||||
len = strlen(_dname) + dirHandleRootLen(writeDir) + 1;
|
|
||||||
dname = (char *) __PHYSFS_smallAlloc(len);
|
dname = (char *) __PHYSFS_smallAlloc(len);
|
||||||
BAIL_IF_MUTEX(!dname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
BAIL_IF(!dname, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
retval = doMkdir(_dname, dname);
|
retval = doMkdir(_dname, dname);
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
|
||||||
__PHYSFS_smallFree(dname);
|
__PHYSFS_smallFree(dname);
|
||||||
return retval;
|
return retval;
|
||||||
} /* PHYSFS_mkdir */
|
} /* PHYSFS_mkdir */
|
||||||
|
|
||||||
|
|
||||||
/* This must hold the stateLock before calling. */
|
|
||||||
static int doDelete(const char *_fname, char *fname)
|
static int doDelete(const char *_fname, char *fname)
|
||||||
{
|
{
|
||||||
DirHandle *h = writeDir;
|
int retval;
|
||||||
BAIL_IF_ERRPASS(!sanitizePlatformIndependentPathWithRoot(h, _fname, fname), 0);
|
DirHandle *h;
|
||||||
BAIL_IF_ERRPASS(!verifyPath(h, &fname, 0), 0);
|
BAIL_IF_ERRPASS(!sanitizePlatformIndependentPath(_fname, fname), 0);
|
||||||
return h->funcs->remove(h->opaque, fname);
|
|
||||||
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
|
|
||||||
|
BAIL_IF_MUTEX(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0);
|
||||||
|
h = writeDir;
|
||||||
|
BAIL_IF_MUTEX_ERRPASS(!verifyPath(h, &fname, 0), stateLock, 0);
|
||||||
|
retval = h->funcs->remove(h->opaque, fname);
|
||||||
|
|
||||||
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
|
return retval;
|
||||||
} /* doDelete */
|
} /* doDelete */
|
||||||
|
|
||||||
|
|
||||||
|
@ -2295,13 +2174,11 @@ int PHYSFS_delete(const char *_fname)
|
||||||
char *fname;
|
char *fname;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
BAIL_IF_MUTEX(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0);
|
len = strlen(_fname) + 1;
|
||||||
len = strlen(_fname) + dirHandleRootLen(writeDir) + 1;
|
|
||||||
fname = (char *) __PHYSFS_smallAlloc(len);
|
fname = (char *) __PHYSFS_smallAlloc(len);
|
||||||
BAIL_IF_MUTEX(!fname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
retval = doDelete(_fname, fname);
|
retval = doDelete(_fname, fname);
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
|
||||||
__PHYSFS_smallFree(fname);
|
__PHYSFS_smallFree(fname);
|
||||||
return retval;
|
return retval;
|
||||||
} /* PHYSFS_delete */
|
} /* PHYSFS_delete */
|
||||||
|
@ -2310,20 +2187,17 @@ int PHYSFS_delete(const char *_fname)
|
||||||
static DirHandle *getRealDirHandle(const char *_fname)
|
static DirHandle *getRealDirHandle(const char *_fname)
|
||||||
{
|
{
|
||||||
DirHandle *retval = NULL;
|
DirHandle *retval = NULL;
|
||||||
char *allocated_fname = NULL;
|
|
||||||
char *fname = NULL;
|
char *fname = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, NULL);
|
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, NULL);
|
||||||
|
len = strlen(_fname) + 1;
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
fname = __PHYSFS_smallAlloc(len);
|
||||||
len = strlen(_fname) + longest_root + 2;
|
BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
||||||
allocated_fname = __PHYSFS_smallAlloc(len);
|
|
||||||
BAIL_IF_MUTEX(!allocated_fname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, NULL);
|
|
||||||
fname = allocated_fname + longest_root + 1;
|
|
||||||
if (sanitizePlatformIndependentPath(_fname, fname))
|
if (sanitizePlatformIndependentPath(_fname, fname))
|
||||||
{
|
{
|
||||||
DirHandle *i;
|
DirHandle *i;
|
||||||
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
for (i = searchPath; i != NULL; i = i->next)
|
for (i = searchPath; i != NULL; i = i->next)
|
||||||
{
|
{
|
||||||
char *arcfname = fname;
|
char *arcfname = fname;
|
||||||
|
@ -2342,10 +2216,10 @@ static DirHandle *getRealDirHandle(const char *_fname)
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* for */
|
} /* for */
|
||||||
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_smallFree(fname);
|
||||||
__PHYSFS_smallFree(allocated_fname);
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* getRealDirHandle */
|
} /* getRealDirHandle */
|
||||||
|
|
||||||
|
@ -2540,18 +2414,15 @@ int PHYSFS_enumerate(const char *_fn, PHYSFS_EnumerateCallback cb, void *data)
|
||||||
{
|
{
|
||||||
PHYSFS_EnumerateCallbackResult retval = PHYSFS_ENUM_OK;
|
PHYSFS_EnumerateCallbackResult retval = PHYSFS_ENUM_OK;
|
||||||
size_t len;
|
size_t len;
|
||||||
char *allocated_fname;
|
|
||||||
char *fname;
|
char *fname;
|
||||||
|
|
||||||
BAIL_IF(!_fn, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!_fn, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
BAIL_IF(!cb, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!cb, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
|
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
len = strlen(_fn) + 1;
|
||||||
|
fname = (char *) __PHYSFS_smallAlloc(len);
|
||||||
|
BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
|
|
||||||
len = strlen(_fn) + longest_root + 2;
|
|
||||||
allocated_fname = (char *) __PHYSFS_smallAlloc(len);
|
|
||||||
BAIL_IF_MUTEX(!allocated_fname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
|
||||||
fname = allocated_fname + longest_root + 1;
|
|
||||||
if (!sanitizePlatformIndependentPath(_fn, fname))
|
if (!sanitizePlatformIndependentPath(_fn, fname))
|
||||||
retval = PHYSFS_ENUM_STOP;
|
retval = PHYSFS_ENUM_STOP;
|
||||||
else
|
else
|
||||||
|
@ -2559,6 +2430,8 @@ int PHYSFS_enumerate(const char *_fn, PHYSFS_EnumerateCallback cb, void *data)
|
||||||
DirHandle *i;
|
DirHandle *i;
|
||||||
SymlinkFilterData filterdata;
|
SymlinkFilterData filterdata;
|
||||||
|
|
||||||
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
|
|
||||||
if (!allowSymLinks)
|
if (!allowSymLinks)
|
||||||
{
|
{
|
||||||
memset(&filterdata, '\0', sizeof (filterdata));
|
memset(&filterdata, '\0', sizeof (filterdata));
|
||||||
|
@ -2607,11 +2480,10 @@ int PHYSFS_enumerate(const char *_fn, PHYSFS_EnumerateCallback cb, void *data)
|
||||||
} /* else if */
|
} /* else if */
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_smallFree(fname);
|
||||||
|
|
||||||
__PHYSFS_smallFree(allocated_fname);
|
|
||||||
|
|
||||||
return (retval == PHYSFS_ENUM_ERROR) ? 0 : 1;
|
return (retval == PHYSFS_ENUM_ERROR) ? 0 : 1;
|
||||||
} /* PHYSFS_enumerate */
|
} /* PHYSFS_enumerate */
|
||||||
|
@ -2672,43 +2544,43 @@ int PHYSFS_isSymbolicLink(const char *fname)
|
||||||
} /* PHYSFS_isSymbolicLink */
|
} /* PHYSFS_isSymbolicLink */
|
||||||
|
|
||||||
|
|
||||||
static PHYSFS_File *doOpenWrite(const char *_fname, const int appending)
|
static PHYSFS_File *doOpenWrite(const char *_fname, int appending)
|
||||||
{
|
{
|
||||||
FileHandle *fh = NULL;
|
FileHandle *fh = NULL;
|
||||||
DirHandle *h;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
char *fname;
|
char *fname;
|
||||||
|
|
||||||
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
|
len = strlen(_fname) + 1;
|
||||||
|
fname = (char *) __PHYSFS_smallAlloc(len);
|
||||||
|
BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
|
|
||||||
|
if (sanitizePlatformIndependentPath(_fname, fname))
|
||||||
|
{
|
||||||
|
PHYSFS_Io *io = NULL;
|
||||||
|
DirHandle *h = NULL;
|
||||||
|
const PHYSFS_Archiver *f;
|
||||||
|
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
|
|
||||||
|
GOTO_IF(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, doOpenWriteEnd);
|
||||||
|
|
||||||
h = writeDir;
|
h = writeDir;
|
||||||
BAIL_IF_MUTEX(!h, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0);
|
GOTO_IF_ERRPASS(!verifyPath(h, &fname, 0), doOpenWriteEnd);
|
||||||
|
|
||||||
len = strlen(_fname) + dirHandleRootLen(h) + 1;
|
f = h->funcs;
|
||||||
fname = (char *) __PHYSFS_smallAlloc(len);
|
|
||||||
BAIL_IF_MUTEX(!fname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
|
||||||
|
|
||||||
if (sanitizePlatformIndependentPathWithRoot(h, _fname, fname))
|
|
||||||
{
|
|
||||||
PHYSFS_Io *io = NULL;
|
|
||||||
char *arcfname = fname;
|
|
||||||
if (verifyPath(h, &arcfname, 0))
|
|
||||||
{
|
|
||||||
const PHYSFS_Archiver *f = h->funcs;
|
|
||||||
if (appending)
|
if (appending)
|
||||||
io = f->openAppend(h->opaque, arcfname);
|
io = f->openAppend(h->opaque, fname);
|
||||||
else
|
else
|
||||||
io = f->openWrite(h->opaque, arcfname);
|
io = f->openWrite(h->opaque, fname);
|
||||||
|
|
||||||
|
GOTO_IF_ERRPASS(!io, doOpenWriteEnd);
|
||||||
|
|
||||||
if (io)
|
|
||||||
{
|
|
||||||
fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
|
fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
|
||||||
if (fh == NULL)
|
if (fh == NULL)
|
||||||
{
|
{
|
||||||
io->destroy(io);
|
io->destroy(io);
|
||||||
PHYSFS_setErrorCode(PHYSFS_ERR_OUT_OF_MEMORY);
|
GOTO(PHYSFS_ERR_OUT_OF_MEMORY, doOpenWriteEnd);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2718,11 +2590,10 @@ static PHYSFS_File *doOpenWrite(const char *_fname, const int appending)
|
||||||
fh->next = openWriteList;
|
fh->next = openWriteList;
|
||||||
openWriteList = fh;
|
openWriteList = fh;
|
||||||
} /* else */
|
} /* else */
|
||||||
} /* if */
|
|
||||||
} /* if */
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
|
doOpenWriteEnd:
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
|
} /* if */
|
||||||
|
|
||||||
__PHYSFS_smallFree(fname);
|
__PHYSFS_smallFree(fname);
|
||||||
return ((PHYSFS_File *) fh);
|
return ((PHYSFS_File *) fh);
|
||||||
|
@ -2744,25 +2615,22 @@ PHYSFS_File *PHYSFS_openAppend(const char *filename)
|
||||||
PHYSFS_File *PHYSFS_openRead(const char *_fname)
|
PHYSFS_File *PHYSFS_openRead(const char *_fname)
|
||||||
{
|
{
|
||||||
FileHandle *fh = NULL;
|
FileHandle *fh = NULL;
|
||||||
char *allocated_fname;
|
|
||||||
char *fname;
|
char *fname;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
|
len = strlen(_fname) + 1;
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
fname = (char *) __PHYSFS_smallAlloc(len);
|
||||||
|
BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
BAIL_IF_MUTEX(!searchPath, PHYSFS_ERR_NOT_FOUND, stateLock, 0);
|
|
||||||
|
|
||||||
len = strlen(_fname) + longest_root + 2;
|
|
||||||
allocated_fname = (char *) __PHYSFS_smallAlloc(len);
|
|
||||||
BAIL_IF_MUTEX(!allocated_fname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
|
||||||
fname = allocated_fname + longest_root + 1;
|
|
||||||
|
|
||||||
if (sanitizePlatformIndependentPath(_fname, fname))
|
if (sanitizePlatformIndependentPath(_fname, fname))
|
||||||
{
|
{
|
||||||
|
DirHandle *i = NULL;
|
||||||
PHYSFS_Io *io = NULL;
|
PHYSFS_Io *io = NULL;
|
||||||
DirHandle *i;
|
|
||||||
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
|
|
||||||
|
GOTO_IF(!searchPath, PHYSFS_ERR_NOT_FOUND, openReadEnd);
|
||||||
|
|
||||||
for (i = searchPath; i != NULL; i = i->next)
|
for (i = searchPath; i != NULL; i = i->next)
|
||||||
{
|
{
|
||||||
|
@ -2775,28 +2643,27 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname)
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
if (io)
|
GOTO_IF_ERRPASS(!io, openReadEnd);
|
||||||
{
|
|
||||||
fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
|
fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
|
||||||
if (fh == NULL)
|
if (fh == NULL)
|
||||||
{
|
{
|
||||||
io->destroy(io);
|
io->destroy(io);
|
||||||
PHYSFS_setErrorCode(PHYSFS_ERR_OUT_OF_MEMORY);
|
GOTO(PHYSFS_ERR_OUT_OF_MEMORY, openReadEnd);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(fh, '\0', sizeof (FileHandle));
|
memset(fh, '\0', sizeof (FileHandle));
|
||||||
fh->io = io;
|
fh->io = io;
|
||||||
fh->forReading = 1;
|
fh->forReading = 1;
|
||||||
fh->dirHandle = i;
|
fh->dirHandle = i;
|
||||||
fh->next = openReadList;
|
fh->next = openReadList;
|
||||||
openReadList = fh;
|
openReadList = fh;
|
||||||
} /* else */
|
|
||||||
} /* if */
|
openReadEnd:
|
||||||
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_smallFree(fname);
|
||||||
__PHYSFS_smallFree(allocated_fname);
|
|
||||||
return ((PHYSFS_File *) fh);
|
return ((PHYSFS_File *) fh);
|
||||||
} /* PHYSFS_openRead */
|
} /* PHYSFS_openRead */
|
||||||
|
|
||||||
|
@ -3129,12 +2996,14 @@ int PHYSFS_flush(PHYSFS_File *handle)
|
||||||
int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
|
int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
char *allocated_fname;
|
|
||||||
char *fname;
|
char *fname;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
BAIL_IF(!stat, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!stat, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
|
len = strlen(_fname) + 1;
|
||||||
|
fname = (char *) __PHYSFS_smallAlloc(len);
|
||||||
|
BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
|
|
||||||
/* set some sane defaults... */
|
/* set some sane defaults... */
|
||||||
stat->filesize = -1;
|
stat->filesize = -1;
|
||||||
|
@ -3144,12 +3013,6 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
|
||||||
stat->filetype = PHYSFS_FILETYPE_OTHER;
|
stat->filetype = PHYSFS_FILETYPE_OTHER;
|
||||||
stat->readonly = 1;
|
stat->readonly = 1;
|
||||||
|
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
|
||||||
len = strlen(_fname) + longest_root + 2;
|
|
||||||
allocated_fname = (char *) __PHYSFS_smallAlloc(len);
|
|
||||||
BAIL_IF_MUTEX(!allocated_fname, PHYSFS_ERR_OUT_OF_MEMORY, stateLock, 0);
|
|
||||||
fname = allocated_fname + longest_root + 1;
|
|
||||||
|
|
||||||
if (sanitizePlatformIndependentPath(_fname, fname))
|
if (sanitizePlatformIndependentPath(_fname, fname))
|
||||||
{
|
{
|
||||||
if (*fname == '\0')
|
if (*fname == '\0')
|
||||||
|
@ -3162,6 +3025,7 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
|
||||||
{
|
{
|
||||||
DirHandle *i;
|
DirHandle *i;
|
||||||
int exists = 0;
|
int exists = 0;
|
||||||
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
for (i = searchPath; ((i != NULL) && (!exists)); i = i->next)
|
for (i = searchPath; ((i != NULL) && (!exists)); i = i->next)
|
||||||
{
|
{
|
||||||
char *arcfname = fname;
|
char *arcfname = fname;
|
||||||
|
@ -3179,11 +3043,11 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
|
||||||
exists = 1;
|
exists = 1;
|
||||||
} /* else if */
|
} /* else if */
|
||||||
} /* for */
|
} /* for */
|
||||||
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
} /* else */
|
} /* else */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_smallFree(fname);
|
||||||
__PHYSFS_smallFree(allocated_fname);
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* PHYSFS_stat */
|
} /* PHYSFS_stat */
|
||||||
|
|
||||||
|
@ -3281,7 +3145,7 @@ static void setDefaultAllocator(void)
|
||||||
} /* setDefaultAllocator */
|
} /* setDefaultAllocator */
|
||||||
|
|
||||||
|
|
||||||
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen, const int case_sensitive, const int only_usascii)
|
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen)
|
||||||
{
|
{
|
||||||
static char rootpath[2] = { '/', '\0' };
|
static char rootpath[2] = { '/', '\0' };
|
||||||
size_t alloclen;
|
size_t alloclen;
|
||||||
|
@ -3289,8 +3153,6 @@ int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen, const int
|
||||||
assert(entrylen >= sizeof (__PHYSFS_DirTreeEntry));
|
assert(entrylen >= sizeof (__PHYSFS_DirTreeEntry));
|
||||||
|
|
||||||
memset(dt, '\0', sizeof (*dt));
|
memset(dt, '\0', sizeof (*dt));
|
||||||
dt->case_sensitive = case_sensitive;
|
|
||||||
dt->only_usascii = only_usascii;
|
|
||||||
|
|
||||||
dt->root = (__PHYSFS_DirTreeEntry *) allocator.Malloc(entrylen);
|
dt->root = (__PHYSFS_DirTreeEntry *) allocator.Malloc(entrylen);
|
||||||
BAIL_IF(!dt->root, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF(!dt->root, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
|
@ -3311,10 +3173,9 @@ int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen, const int
|
||||||
} /* __PHYSFS_DirTreeInit */
|
} /* __PHYSFS_DirTreeInit */
|
||||||
|
|
||||||
|
|
||||||
static PHYSFS_uint32 hashPathName(__PHYSFS_DirTree *dt, const char *name)
|
static inline PHYSFS_uint32 hashPathName(__PHYSFS_DirTree *dt, const char *name)
|
||||||
{
|
{
|
||||||
const PHYSFS_uint32 hashval = dt->case_sensitive ? __PHYSFS_hashString(name) : dt->only_usascii ? __PHYSFS_hashStringCaseFoldUSAscii(name) : __PHYSFS_hashStringCaseFold(name);
|
return __PHYSFS_hashString(name, strlen(name)) % dt->hashBuckets;
|
||||||
return hashval % dt->hashBuckets;
|
|
||||||
} /* hashPathName */
|
} /* hashPathName */
|
||||||
|
|
||||||
|
|
||||||
|
@ -3375,7 +3236,6 @@ void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir)
|
||||||
/* Find the __PHYSFS_DirTreeEntry for a path in platform-independent notation. */
|
/* Find the __PHYSFS_DirTreeEntry for a path in platform-independent notation. */
|
||||||
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path)
|
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path)
|
||||||
{
|
{
|
||||||
const int cs = dt->case_sensitive;
|
|
||||||
PHYSFS_uint32 hashval;
|
PHYSFS_uint32 hashval;
|
||||||
__PHYSFS_DirTreeEntry *prev = NULL;
|
__PHYSFS_DirTreeEntry *prev = NULL;
|
||||||
__PHYSFS_DirTreeEntry *retval;
|
__PHYSFS_DirTreeEntry *retval;
|
||||||
|
@ -3386,8 +3246,7 @@ void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path)
|
||||||
hashval = hashPathName(dt, path);
|
hashval = hashPathName(dt, path);
|
||||||
for (retval = dt->hash[hashval]; retval; retval = retval->hashnext)
|
for (retval = dt->hash[hashval]; retval; retval = retval->hashnext)
|
||||||
{
|
{
|
||||||
const int cmp = cs ? strcmp(retval->name, path) : PHYSFS_utf8stricmp(retval->name, path);
|
if (strcmp(retval->name, path) == 0)
|
||||||
if (cmp == 0)
|
|
||||||
{
|
{
|
||||||
if (prev != NULL) /* move this to the front of the list */
|
if (prev != NULL) /* move this to the front of the list */
|
||||||
{
|
{
|
||||||
|
|
78
src/physfs.h
78
src/physfs.h
|
@ -145,7 +145,7 @@
|
||||||
* - .ISO (ISO9660 files, CD-ROM images)
|
* - .ISO (ISO9660 files, CD-ROM images)
|
||||||
* - .GRP (Build Engine groupfile archives)
|
* - .GRP (Build Engine groupfile archives)
|
||||||
* - .PAK (Quake I/II archive format)
|
* - .PAK (Quake I/II archive format)
|
||||||
* - .HOG (Descent I/II/III HOG file archives)
|
* - .HOG (Descent I/II HOG file archives)
|
||||||
* - .MVL (Descent II movielib archives)
|
* - .MVL (Descent II movielib archives)
|
||||||
* - .WAD (DOOM engine archives)
|
* - .WAD (DOOM engine archives)
|
||||||
* - .VDF (Gothic I/II engine archives)
|
* - .VDF (Gothic I/II engine archives)
|
||||||
|
@ -435,8 +435,8 @@ typedef struct PHYSFS_Version
|
||||||
|
|
||||||
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
|
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
|
||||||
#define PHYSFS_VER_MAJOR 3
|
#define PHYSFS_VER_MAJOR 3
|
||||||
#define PHYSFS_VER_MINOR 3
|
#define PHYSFS_VER_MINOR 0
|
||||||
#define PHYSFS_VER_PATCH 0
|
#define PHYSFS_VER_PATCH 3
|
||||||
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
|
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
|
||||||
|
|
||||||
|
|
||||||
|
@ -495,14 +495,6 @@ typedef struct PHYSFS_Version
|
||||||
PHYSFS_DECL void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
|
PHYSFS_DECL void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
typedef struct PHYSFS_AndroidInit
|
|
||||||
{
|
|
||||||
void *jnienv;
|
|
||||||
void *context;
|
|
||||||
} PHYSFS_AndroidInit;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int PHYSFS_init(const char *argv0)
|
* \fn int PHYSFS_init(const char *argv0)
|
||||||
* \brief Initialize the PhysicsFS library.
|
* \brief Initialize the PhysicsFS library.
|
||||||
|
@ -512,22 +504,11 @@ typedef struct PHYSFS_AndroidInit
|
||||||
* This should be called prior to any attempts to change your process's
|
* This should be called prior to any attempts to change your process's
|
||||||
* current working directory.
|
* current working directory.
|
||||||
*
|
*
|
||||||
* \warning On Android, argv0 should be a non-NULL pointer to a
|
|
||||||
* PHYSFS_AndroidInit struct. This struct must hold a valid JNIEnv *
|
|
||||||
* and a JNI jobject of a Context (either the application context or
|
|
||||||
* the current Activity is fine). Both are cast to a void * so we
|
|
||||||
* don't need jni.h included wherever physfs.h is. PhysicsFS
|
|
||||||
* uses these objects to query some system details. PhysicsFS does
|
|
||||||
* not hold a reference to the JNIEnv or Context past the call to
|
|
||||||
* PHYSFS_init(). If you pass a NULL here, PHYSFS_init can still
|
|
||||||
* succeed, but PHYSFS_getBaseDir() and PHYSFS_getPrefDir() will be
|
|
||||||
* incorrect.
|
|
||||||
*
|
|
||||||
* \param argv0 the argv[0] string passed to your program's mainline.
|
* \param argv0 the argv[0] string passed to your program's mainline.
|
||||||
* This may be NULL on most platforms (such as ones without a
|
* This may be NULL on most platforms (such as ones without a
|
||||||
* standard main() function), but you should always try to pass
|
* standard main() function), but you should always try to pass
|
||||||
* something in here. Many Unix-like systems _need_ to pass argv[0]
|
* something in here. Unix-like systems such as Linux _need_ to
|
||||||
* from main() in here. See warning about Android, too!
|
* pass argv[0] from main() in here.
|
||||||
* \return nonzero on success, zero on error. Specifics of the error can be
|
* \return nonzero on success, zero on error. Specifics of the error can be
|
||||||
* gleaned from PHYSFS_getLastError().
|
* gleaned from PHYSFS_getLastError().
|
||||||
*
|
*
|
||||||
|
@ -783,15 +764,6 @@ PHYSFS_DECL char **PHYSFS_getCdRomDirs(void);
|
||||||
*
|
*
|
||||||
* You should probably use the base dir in your search path.
|
* You should probably use the base dir in your search path.
|
||||||
*
|
*
|
||||||
* \warning On most platforms, this is a directory; on Android, this gives
|
|
||||||
* you the path to the app's package (APK) file. As APK files are
|
|
||||||
* just .zip files, you can mount them in PhysicsFS like regular
|
|
||||||
* directories. You'll probably want to call
|
|
||||||
* PHYSFS_setRoot(basedir, "/assets") after mounting to make your
|
|
||||||
* app's actual data available directly without all the Android
|
|
||||||
* metadata and directory offset. Note that if you passed a NULL to
|
|
||||||
* PHYSFS_init(), you will not get the APK file here.
|
|
||||||
*
|
|
||||||
* \return READ ONLY string of base dir in platform-dependent notation.
|
* \return READ ONLY string of base dir in platform-dependent notation.
|
||||||
*
|
*
|
||||||
* \sa PHYSFS_getPrefDir
|
* \sa PHYSFS_getPrefDir
|
||||||
|
@ -3874,46 +3846,6 @@ PHYSFS_DECL int PHYSFS_deregisterArchiver(const char *ext);
|
||||||
|
|
||||||
/* Everything above this line is part of the PhysicsFS 2.1 API. */
|
/* Everything above this line is part of the PhysicsFS 2.1 API. */
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \fn int PHYSFS_setRoot(const char *archive, const char *subdir)
|
|
||||||
* \brief Make a subdirectory of an archive its root directory.
|
|
||||||
*
|
|
||||||
* This lets you narrow down the accessible files in a specific archive. For
|
|
||||||
* example, if you have x.zip with a file in y/z.txt, mounted to /a, if you
|
|
||||||
* call PHYSFS_setRoot("x.zip", "/y"), then the call
|
|
||||||
* PHYSFS_openRead("/a/z.txt") will succeed.
|
|
||||||
*
|
|
||||||
* You can change an archive's root at any time, altering the interpolated
|
|
||||||
* file tree (depending on where paths shift, a different archive may be
|
|
||||||
* providing various files). If you set the root to NULL or "/", the
|
|
||||||
* archive will be treated as if no special root was set (as if the archive
|
|
||||||
* was just mounted normally).
|
|
||||||
*
|
|
||||||
* Changing the root only affects future operations on pathnames; a file
|
|
||||||
* that was opened from a path that changed due to a setRoot will not be
|
|
||||||
* affected.
|
|
||||||
*
|
|
||||||
* Setting a new root is not limited to archives in the search path; you may
|
|
||||||
* set one on the write dir, too, which might be useful if you have files
|
|
||||||
* open for write and thus can't change the write dir at the moment.
|
|
||||||
*
|
|
||||||
* It is not an error to set a subdirectory that does not exist to be the
|
|
||||||
* root of an archive; however, no files will be visible in this case. If
|
|
||||||
* the missing directories end up getting created (a mkdir to the physical
|
|
||||||
* filesystem, etc) then this will be reflected in the interpolated tree.
|
|
||||||
*
|
|
||||||
* \param archive dir/archive on which to change root.
|
|
||||||
* \param subdir new subdirectory to make the root of this archive.
|
|
||||||
* \return nonzero on success, zero on failure. Use
|
|
||||||
* PHYSFS_getLastErrorCode() to obtain the specific error.
|
|
||||||
*/
|
|
||||||
PHYSFS_DECL int PHYSFS_setRoot(const char *archive, const char *subdir);
|
|
||||||
|
|
||||||
|
|
||||||
/* Everything above this line is part of the PhysicsFS 3.1 API. */
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -185,7 +185,7 @@ static int szipLoadEntries(SZIPinfo *info)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if (__PHYSFS_DirTreeInit(&info->tree, sizeof (SZIPentry), 1, 0))
|
if (__PHYSFS_DirTreeInit(&info->tree, sizeof (SZIPentry)))
|
||||||
{
|
{
|
||||||
const PHYSFS_uint32 count = info->db.NumFiles;
|
const PHYSFS_uint32 count = info->db.NumFiles;
|
||||||
PHYSFS_uint32 i;
|
PHYSFS_uint32 i;
|
||||||
|
@ -285,15 +285,12 @@ static PHYSFS_Io *SZIP_openRead(void *opaque, const char *path)
|
||||||
&blockIndex, &outBuffer, &outBufferSize, &offset,
|
&blockIndex, &outBuffer, &outBufferSize, &offset,
|
||||||
&outSizeProcessed, alloc, alloc);
|
&outSizeProcessed, alloc, alloc);
|
||||||
GOTO_IF(rc != SZ_OK, szipErrorCode(rc), SZIP_openRead_failed);
|
GOTO_IF(rc != SZ_OK, szipErrorCode(rc), SZIP_openRead_failed);
|
||||||
GOTO_IF(outBuffer == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
|
|
||||||
|
|
||||||
io->destroy(io);
|
io->destroy(io);
|
||||||
io = NULL;
|
io = NULL;
|
||||||
|
|
||||||
buf = allocator.Malloc(outSizeProcessed ? outSizeProcessed : 1);
|
buf = allocator.Malloc(outSizeProcessed);
|
||||||
GOTO_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
|
GOTO_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
|
||||||
|
|
||||||
if (outSizeProcessed > 0)
|
|
||||||
memcpy(buf, outBuffer + offset, outSizeProcessed);
|
memcpy(buf, outBuffer + offset, outSizeProcessed);
|
||||||
|
|
||||||
alloc->Free(alloc, outBuffer);
|
alloc->Free(alloc, outBuffer);
|
||||||
|
|
|
@ -76,7 +76,7 @@ static void *GRP_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
||||||
count = PHYSFS_swapULE32(count);
|
count = PHYSFS_swapULE32(count);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, 0, 1);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!grpLoadEntries(io, count, unpkarc))
|
if (!grpLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* HOG support routines for PhysicsFS.
|
* HOG support routines for PhysicsFS.
|
||||||
*
|
*
|
||||||
* This driver handles Descent I/II/III HOG archives.
|
* This driver handles Descent I/II HOG archives.
|
||||||
*
|
*
|
||||||
* The Descent I/II format is very simple:
|
* The format is very simple:
|
||||||
*
|
*
|
||||||
* The file always starts with the 3-byte signature "DHF" (Descent
|
* The file always starts with the 3-byte signature "DHF" (Descent
|
||||||
* HOG file). After that the files of a HOG are just attached after
|
* HOG file). After that the files of a HOG are just attached after
|
||||||
|
@ -23,23 +23,10 @@
|
||||||
*
|
*
|
||||||
* (That info is from http://www.descent2.com/ddn/specs/hog/)
|
* (That info is from http://www.descent2.com/ddn/specs/hog/)
|
||||||
*
|
*
|
||||||
* Descent 3 moved to HOG2 format, which starts with the chars "HOG2",
|
|
||||||
* then 32-bits for the number of contained files, 32 bits for the offset
|
|
||||||
* to the first file's data, then 56 bytes of 0xFF (reserved?). Then for
|
|
||||||
* each file, there's 36 bytes for filename (null-terminated, rest of bytes
|
|
||||||
* are garbage), 32-bits unknown/reserved (always zero?), 32-bits of length
|
|
||||||
* of file data, 32-bits of time since Unix epoch. Then immediately following,
|
|
||||||
* for each file is their uncompressed content, you can find its offset
|
|
||||||
* by starting at the initial data offset and adding the filesize of each
|
|
||||||
* prior file.
|
|
||||||
*
|
|
||||||
* This information was found at:
|
|
||||||
* https://web.archive.org/web/20020213004051/http://descent-3.com/ddn/specs/hog/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Please see the file LICENSE.txt in the source's root directory.
|
* Please see the file LICENSE.txt in the source's root directory.
|
||||||
*
|
*
|
||||||
* This file written by Bradley Bell and Ryan C. Gordon.
|
* This file written by Bradley Bell.
|
||||||
|
* Based on grp.c by Ryan C. Gordon.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define __PHYSICSFS_INTERNAL__
|
#define __PHYSICSFS_INTERNAL__
|
||||||
|
@ -47,15 +34,7 @@
|
||||||
|
|
||||||
#if PHYSFS_SUPPORTS_HOG
|
#if PHYSFS_SUPPORTS_HOG
|
||||||
|
|
||||||
static int readui32(PHYSFS_Io *io, PHYSFS_uint32 *val)
|
static int hogLoadEntries(PHYSFS_Io *io, void *arc)
|
||||||
{
|
|
||||||
PHYSFS_uint32 v;
|
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &v, sizeof (v)), 0);
|
|
||||||
*val = PHYSFS_swapULE32(v);
|
|
||||||
return 1;
|
|
||||||
} /* readui32 */
|
|
||||||
|
|
||||||
static int hog1LoadEntries(PHYSFS_Io *io, void *arc)
|
|
||||||
{
|
{
|
||||||
const PHYSFS_uint64 iolen = io->length(io);
|
const PHYSFS_uint64 iolen = io->length(io);
|
||||||
PHYSFS_uint32 pos = 3;
|
PHYSFS_uint32 pos = 3;
|
||||||
|
@ -66,10 +45,11 @@ static int hog1LoadEntries(PHYSFS_Io *io, void *arc)
|
||||||
char name[13];
|
char name[13];
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
|
||||||
BAIL_IF_ERRPASS(!readui32(io, &size), 0);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
|
||||||
name[12] = '\0'; /* just in case. */
|
name[12] = '\0'; /* just in case. */
|
||||||
pos += 13 + 4;
|
pos += 13 + 4;
|
||||||
|
|
||||||
|
size = PHYSFS_swapULE32(size);
|
||||||
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
|
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
|
||||||
pos += size;
|
pos += size;
|
||||||
|
|
||||||
|
@ -80,60 +60,24 @@ static int hog1LoadEntries(PHYSFS_Io *io, void *arc)
|
||||||
return 1;
|
return 1;
|
||||||
} /* hogLoadEntries */
|
} /* hogLoadEntries */
|
||||||
|
|
||||||
static int hog2LoadEntries(PHYSFS_Io *io, void *arc)
|
|
||||||
{
|
|
||||||
PHYSFS_uint32 numfiles;
|
|
||||||
PHYSFS_uint32 pos;
|
|
||||||
PHYSFS_uint32 i;
|
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!readui32(io, &numfiles), 0);
|
|
||||||
BAIL_IF_ERRPASS(!readui32(io, &pos), 0);
|
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, 68), 0); /* skip to end of header. */
|
|
||||||
|
|
||||||
for (i = 0; i < numfiles; i++) {
|
|
||||||
char name[37];
|
|
||||||
PHYSFS_uint32 reserved;
|
|
||||||
PHYSFS_uint32 size;
|
|
||||||
PHYSFS_uint32 mtime;
|
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 36), 0);
|
|
||||||
BAIL_IF_ERRPASS(!readui32(io, &reserved), 0);
|
|
||||||
BAIL_IF_ERRPASS(!readui32(io, &size), 0);
|
|
||||||
BAIL_IF_ERRPASS(!readui32(io, &mtime), 0);
|
|
||||||
name[36] = '\0'; /* just in case */
|
|
||||||
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, mtime, mtime, pos, size), 0);
|
|
||||||
pos += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
} /* hog2LoadEntries */
|
|
||||||
|
|
||||||
|
|
||||||
static void *HOG_openArchive(PHYSFS_Io *io, const char *name,
|
static void *HOG_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
int forWriting, int *claimed)
|
int forWriting, int *claimed)
|
||||||
{
|
{
|
||||||
PHYSFS_uint8 buf[3];
|
PHYSFS_uint8 buf[3];
|
||||||
void *unpkarc = NULL;
|
void *unpkarc = NULL;
|
||||||
int hog1 = 0;
|
|
||||||
|
|
||||||
assert(io != NULL); /* shouldn't ever happen. */
|
assert(io != NULL); /* shouldn't ever happen. */
|
||||||
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
|
||||||
|
BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
|
||||||
if (memcmp(buf, "DHF", 3) == 0)
|
|
||||||
hog1 = 1; /* original HOG (Descent 1 and 2) archive */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BAIL_IF(memcmp(buf, "HOG", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL); /* Not HOG2 */
|
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 1), NULL);
|
|
||||||
BAIL_IF(buf[0] != '2', PHYSFS_ERR_UNSUPPORTED, NULL); /* Not HOG2 */
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
*claimed = 1;
|
*claimed = 1;
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, 0, 1);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!(hog1 ? hog1LoadEntries(io, unpkarc) : hog2LoadEntries(io, unpkarc)))
|
if (!hogLoadEntries(io, unpkarc))
|
||||||
{
|
{
|
||||||
UNPK_abandonArchive(unpkarc);
|
UNPK_abandonArchive(unpkarc);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -148,7 +92,7 @@ const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
|
||||||
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
|
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
|
||||||
{
|
{
|
||||||
"HOG",
|
"HOG",
|
||||||
"Descent I/II/III HOG file format",
|
"Descent I/II HOG file format",
|
||||||
"Bradley Bell <btb@icculus.org>",
|
"Bradley Bell <btb@icculus.org>",
|
||||||
"https://icculus.org/physfs/",
|
"https://icculus.org/physfs/",
|
||||||
0, /* supportsSymlinks */
|
0, /* supportsSymlinks */
|
||||||
|
|
|
@ -251,7 +251,7 @@ static int parseVolumeDescriptor(PHYSFS_Io *io, PHYSFS_uint64 *_rootpos,
|
||||||
pos += 2048; /* each volume descriptor is 2048 bytes */
|
pos += 2048; /* each volume descriptor is 2048 bytes */
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &type, 1), 0);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &type, 1), 0);
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, identifier, 5), 0);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &identifier, 5), 0);
|
||||||
|
|
||||||
if (memcmp(identifier, "CD001", 5) != 0) /* maybe not an iso? */
|
if (memcmp(identifier, "CD001", 5) != 0) /* maybe not an iso? */
|
||||||
{
|
{
|
||||||
|
@ -346,8 +346,7 @@ static void *ISO9660_openArchive(PHYSFS_Io *io, const char *filename,
|
||||||
if (!parseVolumeDescriptor(io, &rootpos, &len, &joliet, claimed))
|
if (!parseVolumeDescriptor(io, &rootpos, &len, &joliet, claimed))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* !!! FIXME: check case_sensitive and only_usascii params for this archive. */
|
unpkarc = UNPK_openArchive(io);
|
||||||
unpkarc = UNPK_openArchive(io, 1, 0);
|
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!iso9660LoadEntries(io, joliet, "", rootpos, rootpos + len, unpkarc))
|
if (!iso9660LoadEntries(io, joliet, "", rootpos, rootpos + len, unpkarc))
|
||||||
|
|
|
@ -70,7 +70,7 @@ static void *MVL_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
||||||
count = PHYSFS_swapULE32(count);
|
count = PHYSFS_swapULE32(count);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, 0, 1);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!mvlLoadEntries(io, count, unpkarc))
|
if (!mvlLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -86,8 +86,7 @@ static void *QPAK_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
|
BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
|
||||||
|
|
||||||
/* !!! FIXME: check case_sensitive and only_usascii params for this archive. */
|
unpkarc = UNPK_openArchive(io);
|
||||||
unpkarc = UNPK_openArchive(io, 1, 0);
|
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!qpakLoadEntries(io, count, unpkarc))
|
if (!qpakLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -36,7 +36,7 @@ static int slbLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
|
||||||
BAIL_IF(backslash != '\\', PHYSFS_ERR_CORRUPT, 0);
|
BAIL_IF(backslash != '\\', PHYSFS_ERR_CORRUPT, 0);
|
||||||
|
|
||||||
/* read the rest of the buffer, 63 bytes */
|
/* read the rest of the buffer, 63 bytes */
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 63), 0);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &name, 63), 0);
|
||||||
name[63] = '\0'; /* in case the name lacks the null terminator */
|
name[63] = '\0'; /* in case the name lacks the null terminator */
|
||||||
|
|
||||||
/* convert backslashes */
|
/* convert backslashes */
|
||||||
|
@ -94,8 +94,7 @@ static void *SLB_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
/* seek to the table of contents */
|
/* seek to the table of contents */
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
|
BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
|
||||||
|
|
||||||
/* !!! FIXME: check case_sensitive and only_usascii params for this archive. */
|
unpkarc = UNPK_openArchive(io);
|
||||||
unpkarc = UNPK_openArchive(io, 1, 0);
|
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!slbLoadEntries(io, count, unpkarc))
|
if (!slbLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -285,12 +285,12 @@ void *UNPK_addEntry(void *opaque, char *name, const int isdir,
|
||||||
} /* UNPK_addEntry */
|
} /* UNPK_addEntry */
|
||||||
|
|
||||||
|
|
||||||
void *UNPK_openArchive(PHYSFS_Io *io, const int case_sensitive, const int only_usascii)
|
void *UNPK_openArchive(PHYSFS_Io *io)
|
||||||
{
|
{
|
||||||
UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
|
UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
|
||||||
BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (UNPKentry), case_sensitive, only_usascii))
|
if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (UNPKentry)))
|
||||||
{
|
{
|
||||||
allocator.Free(info);
|
allocator.Free(info);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -129,8 +129,7 @@ static void *VDF_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, rootCatOffset), NULL);
|
BAIL_IF_ERRPASS(!io->seek(io, rootCatOffset), NULL);
|
||||||
|
|
||||||
/* !!! FIXME: check case_sensitive and only_usascii params for this archive. */
|
unpkarc = UNPK_openArchive(io);
|
||||||
unpkarc = UNPK_openArchive(io, 1, 0);
|
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!vdfLoadEntries(io, count, vdfDosTimeToEpoch(timestamp), unpkarc))
|
if (!vdfLoadEntries(io, count, vdfDosTimeToEpoch(timestamp), unpkarc))
|
||||||
|
|
|
@ -95,7 +95,7 @@ static void *WAD_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
|
BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, 0, 1);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!wadLoadEntries(io, count, unpkarc))
|
if (!wadLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#if (PHYSFS_BYTEORDER == PHYSFS_LIL_ENDIAN)
|
|
||||||
#define MINIZ_LITTLE_ENDIAN 1
|
|
||||||
#else
|
|
||||||
#define MINIZ_LITTLE_ENDIAN 0
|
|
||||||
#endif
|
|
||||||
#include "physfs_miniz.h"
|
#include "physfs_miniz.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -573,7 +568,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *l
|
||||||
{
|
{
|
||||||
if (!__PHYSFS_readAll(io, buf, maxread - 4))
|
if (!__PHYSFS_readAll(io, buf, maxread - 4))
|
||||||
return -1;
|
return -1;
|
||||||
memcpy(&buf[maxread - 4], extra, sizeof (extra));
|
memcpy(&buf[maxread - 4], &extra, sizeof (extra));
|
||||||
totalread += maxread - 4;
|
totalread += maxread - 4;
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
|
@ -583,7 +578,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *l
|
||||||
totalread += maxread;
|
totalread += maxread;
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
memcpy(extra, buf, sizeof (extra));
|
memcpy(&extra, buf, sizeof (extra));
|
||||||
|
|
||||||
for (i = maxread - 4; i > 0; i--)
|
for (i = maxread - 4; i > 0; i--)
|
||||||
{
|
{
|
||||||
|
@ -1490,7 +1485,7 @@ static void *ZIP_openArchive(PHYSFS_Io *io, const char *name,
|
||||||
|
|
||||||
if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &count))
|
if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &count))
|
||||||
goto ZIP_openarchive_failed;
|
goto ZIP_openarchive_failed;
|
||||||
else if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (ZIPentry), 1, 0))
|
else if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (ZIPentry)))
|
||||||
goto ZIP_openarchive_failed;
|
goto ZIP_openarchive_failed;
|
||||||
|
|
||||||
root = (ZIPentry *) info->tree.root;
|
root = (ZIPentry *) info->tree.root;
|
||||||
|
|
|
@ -224,7 +224,6 @@ extern void SZIP_global_init(void);
|
||||||
/* The latest supported PHYSFS_Archiver::version value. */
|
/* The latest supported PHYSFS_Archiver::version value. */
|
||||||
#define CURRENT_PHYSFS_ARCHIVER_API_VERSION 0
|
#define CURRENT_PHYSFS_ARCHIVER_API_VERSION 0
|
||||||
|
|
||||||
|
|
||||||
/* This byteorder stuff was lifted from SDL. https://www.libsdl.org/ */
|
/* This byteorder stuff was lifted from SDL. https://www.libsdl.org/ */
|
||||||
#define PHYSFS_LIL_ENDIAN 1234
|
#define PHYSFS_LIL_ENDIAN 1234
|
||||||
#define PHYSFS_BIG_ENDIAN 4321
|
#define PHYSFS_BIG_ENDIAN 4321
|
||||||
|
@ -232,26 +231,11 @@ extern void SZIP_global_init(void);
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#define PHYSFS_BYTEORDER __BYTE_ORDER
|
#define PHYSFS_BYTEORDER __BYTE_ORDER
|
||||||
#elif defined(__OpenBSD__) || defined(__DragonFly__)
|
#else /* __linux__ */
|
||||||
#include <endian.h>
|
|
||||||
#define PHYSFS_BYTEORDER BYTE_ORDER
|
|
||||||
#elif defined(__FreeBSD__) || defined(__NetBSD__)
|
|
||||||
#include <sys/endian.h>
|
|
||||||
#define PHYSFS_BYTEORDER BYTE_ORDER
|
|
||||||
/* predefs from newer gcc and clang versions: */
|
|
||||||
#elif defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__BYTE_ORDER__)
|
|
||||||
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
|
||||||
#define PHYSFS_BYTEORDER PHYSFS_LIL_ENDIAN
|
|
||||||
#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
|
||||||
#define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN
|
|
||||||
#else
|
|
||||||
#error Unsupported endianness
|
|
||||||
#endif /**/
|
|
||||||
#else
|
|
||||||
#if defined(__hppa__) || \
|
#if defined(__hppa__) || \
|
||||||
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
|
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
|
||||||
(defined(__MIPS__) && defined(__MIPSEB__)) || \
|
(defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||||
defined(__ppc__) || defined(__POWERPC__) || defined(__powerpc__) || defined(__PPC__) || \
|
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
|
||||||
defined(__sparc__)
|
defined(__sparc__)
|
||||||
#define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN
|
#define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN
|
||||||
#else
|
#else
|
||||||
|
@ -339,18 +323,7 @@ char *__PHYSFS_strdup(const char *str);
|
||||||
/*
|
/*
|
||||||
* Give a hash value for a C string (uses djb's xor hashing algorithm).
|
* Give a hash value for a C string (uses djb's xor hashing algorithm).
|
||||||
*/
|
*/
|
||||||
PHYSFS_uint32 __PHYSFS_hashString(const char *str);
|
PHYSFS_uint32 __PHYSFS_hashString(const char *str, size_t len);
|
||||||
|
|
||||||
/*
|
|
||||||
* Give a hash value for a C string (uses djb's xor hashing algorithm), case folding as it goes.
|
|
||||||
*/
|
|
||||||
PHYSFS_uint32 __PHYSFS_hashStringCaseFold(const char *str);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Give a hash value for a C string (uses djb's xor hashing algorithm), case folding as it goes,
|
|
||||||
* assuming that this is only US-ASCII chars (one byte per char, only 'A' through 'Z' need folding).
|
|
||||||
*/
|
|
||||||
PHYSFS_uint32 __PHYSFS_hashStringCaseFoldUSAscii(const char *str);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -386,10 +359,9 @@ int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const size_t len);
|
||||||
|
|
||||||
/* These are shared between some archivers. */
|
/* These are shared between some archivers. */
|
||||||
|
|
||||||
/* LOTS of legacy formats that only use US ASCII, not actually UTF-8, so let them optimize here. */
|
|
||||||
void *UNPK_openArchive(PHYSFS_Io *io, const int case_sensitive, const int only_usascii);
|
|
||||||
void UNPK_abandonArchive(void *opaque);
|
void UNPK_abandonArchive(void *opaque);
|
||||||
void UNPK_closeArchive(void *opaque);
|
void UNPK_closeArchive(void *opaque);
|
||||||
|
void *UNPK_openArchive(PHYSFS_Io *io);
|
||||||
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
|
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
|
||||||
const PHYSFS_sint64 ctime, const PHYSFS_sint64 mtime,
|
const PHYSFS_sint64 ctime, const PHYSFS_sint64 mtime,
|
||||||
const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
|
const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
|
||||||
|
@ -421,13 +393,10 @@ typedef struct __PHYSFS_DirTree
|
||||||
__PHYSFS_DirTreeEntry **hash; /* all entries hashed for fast lookup. */
|
__PHYSFS_DirTreeEntry **hash; /* all entries hashed for fast lookup. */
|
||||||
size_t hashBuckets; /* number of buckets in hash. */
|
size_t hashBuckets; /* number of buckets in hash. */
|
||||||
size_t entrylen; /* size in bytes of entries (including subclass). */
|
size_t entrylen; /* size in bytes of entries (including subclass). */
|
||||||
int case_sensitive; /* non-zero to treat entries as case-sensitive in DirTreeFind */
|
|
||||||
int only_usascii; /* non-zero to treat paths as US ASCII only (one byte per char, only 'A' through 'Z' are considered for case folding). */
|
|
||||||
} __PHYSFS_DirTree;
|
} __PHYSFS_DirTree;
|
||||||
|
|
||||||
|
|
||||||
/* LOTS of legacy formats that only use US ASCII, not actually UTF-8, so let them optimize here. */
|
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen);
|
||||||
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen, const int case_sensitive, const int only_usascii);
|
|
||||||
void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
|
void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
|
||||||
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
|
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
|
||||||
PHYSFS_EnumerateCallbackResult __PHYSFS_DirTreeEnumerate(void *opaque,
|
PHYSFS_EnumerateCallbackResult __PHYSFS_DirTreeEnumerate(void *opaque,
|
||||||
|
@ -757,11 +726,6 @@ int __PHYSFS_platformGrabMutex(void *mutex);
|
||||||
*/
|
*/
|
||||||
void __PHYSFS_platformReleaseMutex(void *mutex);
|
void __PHYSFS_platformReleaseMutex(void *mutex);
|
||||||
|
|
||||||
|
|
||||||
/* !!! FIXME: move to public API? */
|
|
||||||
PHYSFS_uint32 __PHYSFS_utf8codepoint(const char **_str);
|
|
||||||
|
|
||||||
|
|
||||||
#if PHYSFS_HAVE_PRAGMA_VISIBILITY
|
#if PHYSFS_HAVE_PRAGMA_VISIBILITY
|
||||||
#pragma GCC visibility pop
|
#pragma GCC visibility pop
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -506,7 +506,6 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MY_CPU_AMD64) \
|
#if defined(MY_CPU_AMD64) \
|
||||||
|| defined(_M_ARM64) \
|
|
||||||
|| defined(_M_IA64) \
|
|| defined(_M_IA64) \
|
||||||
|| defined(__AARCH64EL__) \
|
|| defined(__AARCH64EL__) \
|
||||||
|| defined(__AARCH64EB__)
|
|| defined(__AARCH64EB__)
|
||||||
|
@ -532,8 +531,6 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(_M_ARM)
|
#if defined(_WIN32) && defined(_M_ARM)
|
||||||
#define MY_CPU_ARM_LE
|
#define MY_CPU_ARM_LE
|
||||||
#elif defined(_WIN64) && defined(_M_ARM64)
|
|
||||||
#define MY_CPU_ARM_LE
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(_M_IA64)
|
#if defined(_WIN32) && defined(_M_IA64)
|
||||||
|
|
|
@ -22,14 +22,12 @@ typedef unsigned long mz_ulong;
|
||||||
typedef void *(*mz_alloc_func)(void *opaque, unsigned int items, unsigned int size);
|
typedef void *(*mz_alloc_func)(void *opaque, unsigned int items, unsigned int size);
|
||||||
typedef void (*mz_free_func)(void *opaque, void *address);
|
typedef void (*mz_free_func)(void *opaque, void *address);
|
||||||
|
|
||||||
#ifndef MINIZ_LITTLE_ENDIAN /* if not defined by PHYSFS */
|
|
||||||
#if defined(_M_IX86) || defined(_M_X64)
|
#if defined(_M_IX86) || defined(_M_X64)
|
||||||
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 if integer loads and stores to unaligned addresses are acceptable on the target platform (slightly faster). */
|
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 if integer loads and stores to unaligned addresses are acceptable on the target platform (slightly faster). */
|
||||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
|
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
|
||||||
/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
|
/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
|
||||||
#define MINIZ_LITTLE_ENDIAN 1
|
#define MINIZ_LITTLE_ENDIAN 1
|
||||||
#endif
|
#endif
|
||||||
#endif /**/
|
|
||||||
|
|
||||||
#if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
|
#if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
|
||||||
/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if the processor has 64-bit general purpose registers (enables 64-bit bitbuffer in inflator) */
|
/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if the processor has 64-bit general purpose registers (enables 64-bit bitbuffer in inflator) */
|
||||||
|
@ -119,8 +117,6 @@ struct tinfl_decompressor_tag
|
||||||
#define MZ_MAX(a,b) (((a)>(b))?(a):(b))
|
#define MZ_MAX(a,b) (((a)>(b))?(a):(b))
|
||||||
#define MZ_MIN(a,b) (((a)<(b))?(a):(b))
|
#define MZ_MIN(a,b) (((a)<(b))?(a):(b))
|
||||||
#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
|
#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
|
||||||
#define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj))
|
|
||||||
#define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj))
|
|
||||||
|
|
||||||
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
||||||
#define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
|
#define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
|
||||||
|
@ -175,12 +171,8 @@ struct tinfl_decompressor_tag
|
||||||
code_len = TINFL_FAST_LOOKUP_BITS; \
|
code_len = TINFL_FAST_LOOKUP_BITS; \
|
||||||
do { \
|
do { \
|
||||||
temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
|
temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
|
||||||
} while ((temp < 0) && (num_bits >= (code_len + 1))); \
|
} while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
|
||||||
if (temp >= 0) break; \
|
} TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
|
||||||
} \
|
|
||||||
TINFL_GET_BYTE(state_index, c); \
|
|
||||||
bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
|
|
||||||
num_bits += 8; \
|
|
||||||
} while (num_bits < 15);
|
} while (num_bits < 15);
|
||||||
|
|
||||||
/* TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read */
|
/* TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read */
|
||||||
|
@ -282,13 +274,13 @@ static tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
|
for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
|
||||||
MZ_CLEAR_ARR(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
|
MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
|
||||||
r->m_table_sizes[2] = 19;
|
r->m_table_sizes[2] = 19;
|
||||||
}
|
}
|
||||||
for ( ; (int)r->m_type >= 0; r->m_type--)
|
for ( ; (int)r->m_type >= 0; r->m_type--)
|
||||||
{
|
{
|
||||||
int tree_next, tree_cur; tinfl_huff_table *pTable;
|
int tree_next, tree_cur; tinfl_huff_table *pTable;
|
||||||
mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_ARR(total_syms); MZ_CLEAR_ARR(pTable->m_look_up); MZ_CLEAR_ARR(pTable->m_tree);
|
mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
|
||||||
for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
|
for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
|
||||||
used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
|
used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
|
||||||
for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
|
for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
|
||||||
|
@ -707,4 +699,3 @@ static int mz_inflateEnd(mz_streamp pStream)
|
||||||
|
|
||||||
For more information, please refer to <https://unlicense.org/>
|
For more information, please refer to <https://unlicense.org/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -1,117 +0,0 @@
|
||||||
/*
|
|
||||||
* Android support routines for PhysicsFS.
|
|
||||||
*
|
|
||||||
* Please see the file LICENSE.txt in the source's root directory.
|
|
||||||
*
|
|
||||||
* This file written by Ryan C. Gordon.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define __PHYSICSFS_INTERNAL__
|
|
||||||
#include "physfs_platforms.h"
|
|
||||||
|
|
||||||
#ifdef PHYSFS_PLATFORM_ANDROID
|
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
#include <android/log.h>
|
|
||||||
#include "physfs_internal.h"
|
|
||||||
|
|
||||||
static char *prefpath = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
int __PHYSFS_platformInit(void)
|
|
||||||
{
|
|
||||||
return 1; /* always succeed. */
|
|
||||||
} /* __PHYSFS_platformInit */
|
|
||||||
|
|
||||||
|
|
||||||
void __PHYSFS_platformDeinit(void)
|
|
||||||
{
|
|
||||||
if (prefpath)
|
|
||||||
{
|
|
||||||
allocator.Free(prefpath);
|
|
||||||
prefpath = NULL;
|
|
||||||
} /* if */
|
|
||||||
} /* __PHYSFS_platformDeinit */
|
|
||||||
|
|
||||||
|
|
||||||
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
|
|
||||||
{
|
|
||||||
/* no-op. */
|
|
||||||
} /* __PHYSFS_platformDetectAvailableCDs */
|
|
||||||
|
|
||||||
|
|
||||||
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
|
||||||
{
|
|
||||||
/* as a cheat, we expect argv0 to be a PHYSFS_AndroidInit* on Android. */
|
|
||||||
PHYSFS_AndroidInit *ainit = (PHYSFS_AndroidInit *) argv0;
|
|
||||||
char *retval = NULL;
|
|
||||||
JNIEnv *jenv = NULL;
|
|
||||||
jobject jcontext;
|
|
||||||
|
|
||||||
if (ainit == NULL)
|
|
||||||
return __PHYSFS_strdup("/"); /* oh well. */
|
|
||||||
|
|
||||||
jenv = (JNIEnv *) ainit->jnienv;
|
|
||||||
jcontext = (jobject) ainit->context;
|
|
||||||
|
|
||||||
if ((*jenv)->PushLocalFrame(jenv, 16) >= 0)
|
|
||||||
{
|
|
||||||
jobject jfileobj = 0;
|
|
||||||
jmethodID jmeth = 0;
|
|
||||||
jthrowable jexception = 0;
|
|
||||||
jstring jstr = 0;
|
|
||||||
|
|
||||||
jmeth = (*jenv)->GetMethodID(jenv, (*jenv)->GetObjectClass(jenv, jcontext), "getPackageResourcePath", "()Ljava/lang/String;");
|
|
||||||
jstr = (jstring)(*jenv)->CallObjectMethod(jenv, jcontext, jmeth);
|
|
||||||
jexception = (*jenv)->ExceptionOccurred(jenv); /* this can't throw an exception, right? Just in case. */
|
|
||||||
if (jexception != NULL)
|
|
||||||
(*jenv)->ExceptionClear(jenv);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const char *path = (*jenv)->GetStringUTFChars(jenv, jstr, NULL);
|
|
||||||
retval = __PHYSFS_strdup(path);
|
|
||||||
(*jenv)->ReleaseStringUTFChars(jenv, jstr, path);
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
/* We only can rely on the Activity being valid during this function call,
|
|
||||||
so go ahead and grab the prefpath too. */
|
|
||||||
jmeth = (*jenv)->GetMethodID(jenv, (*jenv)->GetObjectClass(jenv, jcontext), "getFilesDir", "()Ljava/io/File;");
|
|
||||||
jfileobj = (*jenv)->CallObjectMethod(jenv, jcontext, jmeth);
|
|
||||||
if (jfileobj)
|
|
||||||
{
|
|
||||||
jmeth = (*jenv)->GetMethodID(jenv, (*jenv)->GetObjectClass(jenv, jfileobj), "getCanonicalPath", "()Ljava/lang/String;");
|
|
||||||
jstr = (jstring)(*jenv)->CallObjectMethod(jenv, jfileobj, jmeth);
|
|
||||||
jexception = (*jenv)->ExceptionOccurred(jenv);
|
|
||||||
if (jexception != NULL)
|
|
||||||
(*jenv)->ExceptionClear(jenv);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const char *path = (*jenv)->GetStringUTFChars(jenv, jstr, NULL);
|
|
||||||
const size_t len = strlen(path) + 2;
|
|
||||||
prefpath = allocator.Malloc(len);
|
|
||||||
if (prefpath)
|
|
||||||
snprintf(prefpath, len, "%s/", path);
|
|
||||||
(*jenv)->ReleaseStringUTFChars(jenv, jstr, path);
|
|
||||||
} /* else */
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
(*jenv)->PopLocalFrame(jenv, NULL);
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
/* we can't return NULL because then PhysicsFS will treat argv0 as a string, but it's a non-NULL jobject! */
|
|
||||||
if (retval == NULL)
|
|
||||||
retval = __PHYSFS_strdup("/"); /* we pray this works. */
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
} /* __PHYSFS_platformCalcBaseDir */
|
|
||||||
|
|
||||||
|
|
||||||
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
|
|
||||||
{
|
|
||||||
return __PHYSFS_strdup(prefpath ? prefpath : "/");
|
|
||||||
} /* __PHYSFS_platformCalcPrefDir */
|
|
||||||
|
|
||||||
#endif /* PHYSFS_PLATFORM_ANDROID */
|
|
||||||
|
|
||||||
/* end of physfs_platform_android.c ... */
|
|
||||||
|
|
|
@ -155,22 +155,13 @@ int __PHYSFS_platformMkDir(const char *path)
|
||||||
} /* __PHYSFS_platformMkDir */
|
} /* __PHYSFS_platformMkDir */
|
||||||
|
|
||||||
|
|
||||||
#if !defined(O_CLOEXEC) && defined(FD_CLOEXEC)
|
|
||||||
static inline void set_CLOEXEC(int fildes)
|
|
||||||
{
|
|
||||||
int flags = fcntl(fildes, F_GETFD);
|
|
||||||
if (flags != -1) {
|
|
||||||
fcntl(fildes, F_SETFD, flags | FD_CLOEXEC);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void *doOpen(const char *filename, int mode)
|
static void *doOpen(const char *filename, int mode)
|
||||||
{
|
{
|
||||||
const int appending = (mode & O_APPEND);
|
const int appending = (mode & O_APPEND);
|
||||||
int fd;
|
int fd;
|
||||||
int *retval;
|
int *retval;
|
||||||
|
int flags;
|
||||||
|
flags = -1;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
/* O_APPEND doesn't actually behave as we'd like. */
|
/* O_APPEND doesn't actually behave as we'd like. */
|
||||||
|
@ -187,7 +178,10 @@ static void *doOpen(const char *filename, int mode)
|
||||||
BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
|
BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
|
||||||
|
|
||||||
#if !defined(O_CLOEXEC) && defined(FD_CLOEXEC)
|
#if !defined(O_CLOEXEC) && defined(FD_CLOEXEC)
|
||||||
set_CLOEXEC(fd);
|
flags = fcntl(fd, F_GETFD);
|
||||||
|
if (flags != -1) {
|
||||||
|
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (appending)
|
if (appending)
|
||||||
|
|
|
@ -261,6 +261,12 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1)
|
if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1)
|
||||||
retval = __PHYSFS_strdup(fullpath);
|
retval = __PHYSFS_strdup(fullpath);
|
||||||
}
|
}
|
||||||
|
#elif defined(PHYSFS_PLATFORM_SOLARIS)
|
||||||
|
{
|
||||||
|
const char *path = getexecname();
|
||||||
|
if ((path != NULL) && (path[0] == '/')) /* must be absolute path... */
|
||||||
|
retval = __PHYSFS_strdup(path);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If there's a Linux-like /proc filesystem, you can get the full path to
|
/* If there's a Linux-like /proc filesystem, you can get the full path to
|
||||||
|
@ -272,7 +278,6 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
retval = readSymLink("/proc/self/exe");
|
retval = readSymLink("/proc/self/exe");
|
||||||
if (!retval) retval = readSymLink("/proc/curproc/file");
|
if (!retval) retval = readSymLink("/proc/curproc/file");
|
||||||
if (!retval) retval = readSymLink("/proc/curproc/exe");
|
if (!retval) retval = readSymLink("/proc/curproc/exe");
|
||||||
if (!retval) retval = readSymLink("/proc/self/path/a.out");
|
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
/* older kernels don't have /proc/self ... try PID version... */
|
/* older kernels don't have /proc/self ... try PID version... */
|
||||||
|
@ -284,15 +289,6 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
#if defined(PHYSFS_PLATFORM_SOLARIS)
|
|
||||||
if (!retval) /* try getexecname() if /proc didn't pan out. This may not be an absolute path! */
|
|
||||||
{
|
|
||||||
const char *path = getexecname();
|
|
||||||
if ((path != NULL) && (path[0] == '/')) /* must be absolute path... */
|
|
||||||
retval = __PHYSFS_strdup(path);
|
|
||||||
} /* if */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (retval != NULL) /* chop off filename. */
|
if (retval != NULL) /* chop off filename. */
|
||||||
{
|
{
|
||||||
char *ptr = strrchr(retval, '/');
|
char *ptr = strrchr(retval, '/');
|
||||||
|
|
|
@ -101,7 +101,7 @@ static char *unicodeToUtf8Heap(const WCHAR *w_str)
|
||||||
|
|
||||||
static inline HANDLE winFindFirstFileW(const WCHAR *path, LPWIN32_FIND_DATAW d)
|
static inline HANDLE winFindFirstFileW(const WCHAR *path, LPWIN32_FIND_DATAW d)
|
||||||
{
|
{
|
||||||
#if defined(PHYSFS_PLATFORM_WINRT) || (_WIN32_WINNT >= 0x0501) // Windows XP+
|
#ifdef PHYSFS_PLATFORM_WINRT
|
||||||
return FindFirstFileExW(path, FindExInfoStandard, d,
|
return FindFirstFileExW(path, FindExInfoStandard, d,
|
||||||
FindExSearchNameMatch, NULL, 0);
|
FindExSearchNameMatch, NULL, 0);
|
||||||
#else
|
#else
|
||||||
|
@ -111,7 +111,7 @@ static inline HANDLE winFindFirstFileW(const WCHAR *path, LPWIN32_FIND_DATAW d)
|
||||||
|
|
||||||
static inline BOOL winInitializeCriticalSection(LPCRITICAL_SECTION lpcs)
|
static inline BOOL winInitializeCriticalSection(LPCRITICAL_SECTION lpcs)
|
||||||
{
|
{
|
||||||
#if defined(PHYSFS_PLATFORM_WINRT) || (_WIN32_WINNT >= 0x0600) // Windows Vista+
|
#ifdef PHYSFS_PLATFORM_WINRT
|
||||||
return InitializeCriticalSectionEx(lpcs, 2000, 0);
|
return InitializeCriticalSectionEx(lpcs, 2000, 0);
|
||||||
#else
|
#else
|
||||||
InitializeCriticalSection(lpcs);
|
InitializeCriticalSection(lpcs);
|
||||||
|
@ -123,7 +123,7 @@ static inline HANDLE winCreateFileW(const WCHAR *wfname, const DWORD mode,
|
||||||
const DWORD creation)
|
const DWORD creation)
|
||||||
{
|
{
|
||||||
const DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
const DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||||
#if defined(PHYSFS_PLATFORM_WINRT) || (_WIN32_WINNT >= 0x0602) // Windows 8+
|
#ifdef PHYSFS_PLATFORM_WINRT
|
||||||
return CreateFile2(wfname, mode, share, creation, NULL);
|
return CreateFile2(wfname, mode, share, creation, NULL);
|
||||||
#else
|
#else
|
||||||
return CreateFileW(wfname, mode, share, NULL, creation,
|
return CreateFileW(wfname, mode, share, NULL, creation,
|
||||||
|
@ -134,7 +134,7 @@ static inline HANDLE winCreateFileW(const WCHAR *wfname, const DWORD mode,
|
||||||
static BOOL winSetFilePointer(HANDLE h, const PHYSFS_sint64 pos,
|
static BOOL winSetFilePointer(HANDLE h, const PHYSFS_sint64 pos,
|
||||||
PHYSFS_sint64 *_newpos, const DWORD whence)
|
PHYSFS_sint64 *_newpos, const DWORD whence)
|
||||||
{
|
{
|
||||||
#if defined(PHYSFS_PLATFORM_WINRT) || (_WIN32_WINNT >= 0x0501) // Windows XP+
|
#ifdef PHYSFS_PLATFORM_WINRT
|
||||||
LARGE_INTEGER lipos;
|
LARGE_INTEGER lipos;
|
||||||
LARGE_INTEGER linewpos;
|
LARGE_INTEGER linewpos;
|
||||||
BOOL rc;
|
BOOL rc;
|
||||||
|
@ -158,7 +158,7 @@ static BOOL winSetFilePointer(HANDLE h, const PHYSFS_sint64 pos,
|
||||||
|
|
||||||
static PHYSFS_sint64 winGetFileSize(HANDLE h)
|
static PHYSFS_sint64 winGetFileSize(HANDLE h)
|
||||||
{
|
{
|
||||||
#if defined(PHYSFS_PLATFORM_WINRT) || (_WIN32_WINNT >= 0x0600) // Windows Vista+
|
#ifdef PHYSFS_PLATFORM_WINRT
|
||||||
FILE_STANDARD_INFO info;
|
FILE_STANDARD_INFO info;
|
||||||
const BOOL rc = GetFileInformationByHandleEx(h, FileStandardInfo,
|
const BOOL rc = GetFileInformationByHandleEx(h, FileStandardInfo,
|
||||||
&info, sizeof (info));
|
&info, sizeof (info));
|
||||||
|
|
|
@ -40,9 +40,9 @@
|
||||||
# define PHYSFS_PLATFORM_POSIX 1
|
# define PHYSFS_PLATFORM_POSIX 1
|
||||||
#elif defined(macintosh)
|
#elif defined(macintosh)
|
||||||
# error Classic Mac OS support was dropped from PhysicsFS 2.0. Move to OS X.
|
# error Classic Mac OS support was dropped from PhysicsFS 2.0. Move to OS X.
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(ANDROID)
|
||||||
# define PHYSFS_PLATFORM_LINUX 1
|
# define PHYSFS_PLATFORM_LINUX 1
|
||||||
# define PHYSFS_PLATFORM_ANDROID 1
|
# define PHYSFS_PLATFORM_UNIX 1
|
||||||
# define PHYSFS_PLATFORM_POSIX 1
|
# define PHYSFS_PLATFORM_POSIX 1
|
||||||
# define PHYSFS_NO_CDROM_SUPPORT 1
|
# define PHYSFS_NO_CDROM_SUPPORT 1
|
||||||
#elif defined(__linux)
|
#elif defined(__linux)
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
/*
|
/*
|
||||||
* This may not be the best value, but it's one that isn't represented
|
* This may not be the best value, but it's one that isn't represented
|
||||||
* in Unicode (0x10FFFF is the largest codepoint value). We return this
|
* in Unicode (0x10FFFF is the largest codepoint value). We return this
|
||||||
* value from __PHYSFS_utf8codepoint() if there's bogus bits in the
|
* value from utf8codepoint() if there's bogus bits in the
|
||||||
* stream. __PHYSFS_utf8codepoint() will turn this value into something
|
* stream. utf8codepoint() will turn this value into something
|
||||||
* reasonable (like a question mark), for text that wants to try to recover,
|
* reasonable (like a question mark), for text that wants to try to recover,
|
||||||
* whereas utf8valid() will use the value to determine if a string has bad
|
* whereas utf8valid() will use the value to determine if a string has bad
|
||||||
* bits.
|
* bits.
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
*/
|
*/
|
||||||
#define UNICODE_BOGUS_CHAR_CODEPOINT '?'
|
#define UNICODE_BOGUS_CHAR_CODEPOINT '?'
|
||||||
|
|
||||||
PHYSFS_uint32 __PHYSFS_utf8codepoint(const char **_str)
|
static PHYSFS_uint32 utf8codepoint(const char **_str)
|
||||||
{
|
{
|
||||||
const char *str = *_str;
|
const char *str = *_str;
|
||||||
PHYSFS_uint32 retval = 0;
|
PHYSFS_uint32 retval = 0;
|
||||||
|
@ -188,11 +188,6 @@ PHYSFS_uint32 __PHYSFS_utf8codepoint(const char **_str)
|
||||||
} /* else if */
|
} /* else if */
|
||||||
|
|
||||||
return UNICODE_BOGUS_CHAR_VALUE;
|
return UNICODE_BOGUS_CHAR_VALUE;
|
||||||
} /* __PHYSFS_utf8codepoint */
|
|
||||||
|
|
||||||
static inline PHYSFS_uint32 utf8codepoint(const char **_str)
|
|
||||||
{
|
|
||||||
return __PHYSFS_utf8codepoint(_str);
|
|
||||||
} /* utf8codepoint */
|
} /* utf8codepoint */
|
||||||
|
|
||||||
static PHYSFS_uint32 utf16codepoint(const PHYSFS_uint16 **_str)
|
static PHYSFS_uint32 utf16codepoint(const PHYSFS_uint16 **_str)
|
||||||
|
@ -243,7 +238,7 @@ void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
|
||||||
len -= sizeof (PHYSFS_uint32); /* save room for null char. */
|
len -= sizeof (PHYSFS_uint32); /* save room for null char. */
|
||||||
while (len >= sizeof (PHYSFS_uint32))
|
while (len >= sizeof (PHYSFS_uint32))
|
||||||
{
|
{
|
||||||
PHYSFS_uint32 cp = __PHYSFS_utf8codepoint(&src);
|
PHYSFS_uint32 cp = utf8codepoint(&src);
|
||||||
if (cp == 0)
|
if (cp == 0)
|
||||||
break;
|
break;
|
||||||
else if (cp == UNICODE_BOGUS_CHAR_VALUE)
|
else if (cp == UNICODE_BOGUS_CHAR_VALUE)
|
||||||
|
@ -261,7 +256,7 @@ void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
|
||||||
len -= sizeof (PHYSFS_uint16); /* save room for null char. */
|
len -= sizeof (PHYSFS_uint16); /* save room for null char. */
|
||||||
while (len >= sizeof (PHYSFS_uint16))
|
while (len >= sizeof (PHYSFS_uint16))
|
||||||
{
|
{
|
||||||
PHYSFS_uint32 cp = __PHYSFS_utf8codepoint(&src);
|
PHYSFS_uint32 cp = utf8codepoint(&src);
|
||||||
if (cp == 0)
|
if (cp == 0)
|
||||||
break;
|
break;
|
||||||
else if (cp == UNICODE_BOGUS_CHAR_VALUE)
|
else if (cp == UNICODE_BOGUS_CHAR_VALUE)
|
||||||
|
@ -283,7 +278,7 @@ void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
|
||||||
len -= sizeof (PHYSFS_uint16); /* save room for null char. */
|
len -= sizeof (PHYSFS_uint16); /* save room for null char. */
|
||||||
while (len >= sizeof (PHYSFS_uint16))
|
while (len >= sizeof (PHYSFS_uint16))
|
||||||
{
|
{
|
||||||
PHYSFS_uint32 cp = __PHYSFS_utf8codepoint(&src);
|
PHYSFS_uint32 cp = utf8codepoint(&src);
|
||||||
if (cp == 0)
|
if (cp == 0)
|
||||||
break;
|
break;
|
||||||
else if (cp == UNICODE_BOGUS_CHAR_VALUE)
|
else if (cp == UNICODE_BOGUS_CHAR_VALUE)
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
#include "physfs.h"
|
#include "physfs.h"
|
||||||
|
|
||||||
#define TEST_VERSION_MAJOR 3
|
#define TEST_VERSION_MAJOR 3
|
||||||
#define TEST_VERSION_MINOR 3
|
#define TEST_VERSION_MINOR 0
|
||||||
#define TEST_VERSION_PATCH 0
|
#define TEST_VERSION_PATCH 3
|
||||||
|
|
||||||
static FILE *history_file = NULL;
|
static FILE *history_file = NULL;
|
||||||
static PHYSFS_uint32 do_buffer_size = 0;
|
static PHYSFS_uint32 do_buffer_size = 0;
|
||||||
|
@ -288,53 +288,6 @@ static int cmd_getmountpoint(char *args)
|
||||||
return 1;
|
return 1;
|
||||||
} /* cmd_getmountpoint */
|
} /* cmd_getmountpoint */
|
||||||
|
|
||||||
|
|
||||||
static int cmd_setroot(char *args)
|
|
||||||
{
|
|
||||||
char *archive;
|
|
||||||
char *subdir;
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
archive = args;
|
|
||||||
if (*archive == '\"')
|
|
||||||
{
|
|
||||||
archive++;
|
|
||||||
ptr = strchr(archive, '\"');
|
|
||||||
if (ptr == NULL)
|
|
||||||
{
|
|
||||||
printf("missing string terminator in argument.\n");
|
|
||||||
return 1;
|
|
||||||
} /* if */
|
|
||||||
*(ptr) = '\0';
|
|
||||||
} /* if */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ptr = strchr(archive, ' ');
|
|
||||||
*ptr = '\0';
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
subdir = ptr + 1;
|
|
||||||
if (*subdir == '\"')
|
|
||||||
{
|
|
||||||
subdir++;
|
|
||||||
ptr = strchr(subdir, '\"');
|
|
||||||
if (ptr == NULL)
|
|
||||||
{
|
|
||||||
printf("missing string terminator in argument.\n");
|
|
||||||
return 1;
|
|
||||||
} /* if */
|
|
||||||
*(ptr) = '\0';
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
if (PHYSFS_setRoot(archive, subdir))
|
|
||||||
printf("Successful.\n");
|
|
||||||
else
|
|
||||||
printf("Failure. reason: %s.\n", PHYSFS_getLastError());
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
} /* cmd_setroot */
|
|
||||||
|
|
||||||
|
|
||||||
static int cmd_removearchive(char *args)
|
static int cmd_removearchive(char *args)
|
||||||
{
|
{
|
||||||
if (*args == '\"')
|
if (*args == '\"')
|
||||||
|
@ -1387,7 +1340,6 @@ static const command_info commands[] =
|
||||||
{ "stressbuffer", cmd_stressbuffer, 1, "<bufferSize>" },
|
{ "stressbuffer", cmd_stressbuffer, 1, "<bufferSize>" },
|
||||||
{ "crc32", cmd_crc32, 1, "<fileToHash>" },
|
{ "crc32", cmd_crc32, 1, "<fileToHash>" },
|
||||||
{ "getmountpoint", cmd_getmountpoint, 1, "<dir>" },
|
{ "getmountpoint", cmd_getmountpoint, 1, "<dir>" },
|
||||||
{ "setroot", cmd_setroot, 2, "<archiveLocation> <root>" },
|
|
||||||
{ NULL, NULL, -1, NULL }
|
{ NULL, NULL, -1, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue