Merge branch 'master' into yoshisuga/ios-metal

This commit is contained in:
Yoshi Sugawara 2020-07-19 00:33:54 -10:00
commit fd9ac64d55
719 changed files with 45870 additions and 43153 deletions

28
.github/workflows/crowdin.yml vendored Normal file
View File

@ -0,0 +1,28 @@
# Upload sources to Crowdin for translation
name: Crowdin Workflow
on:
push:
branches:
- master
paths:
- 'intl/*_us.h'
- 'intl/*_us.json'
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Setup Java JDK
uses: actions/setup-java@v1.3.0
with:
java-version: 1.8
- name: Setup Python
uses: actions/setup-python@v2
- name: Checkout
uses: actions/checkout@v2
- name: Crowdin Sync
run: |
cd intl
python3 crowdin_sync.py

2
.gitignore vendored
View File

@ -76,7 +76,9 @@ convert_rumble.awk
*~
assets
info
content_history.lpl
content_image_history.lpl
content_music_history.lpl
saves
screenshots

View File

@ -63,7 +63,6 @@
"xtree": "c",
"xutility": "c",
"menu_input_dialog.h": "c",
"menu_filebrowser.h": "c",
"ozone_sidebar.h": "c",
"menu_thumbnail_path.h": "c",
"badges.h": "c"

View File

@ -1,4 +1,24 @@
# Future
- BLUETOOTH: Add a Bluetooth driver (Lakka-only for now)
- CHEEVOS: Option to play sound on achievement unlock.
- CHEEVOS: Upgrade to rcheevos 9.1
- CHEEVOS: Restore display of unlocked achievements across hardcore modes
- CHEEVOS: Hash buffered data when available
- CHEEVOS: Fix 'Auto Save State freezes RetroArch while Cheevos is enabled'
- CONFIG FILE: Optimise parsing of configuration files
- D3D9/D3D11: Fix core-initiated D3D9/D3D11 driver switches
- DRIVERS: Implemented protection to avoid setting critical drivers to nothing thus preventing the user from locking him/herself out of the program
- EMSCRIPTEN: Fix input code to ignore unknown keys
- FILE I/O: VFS and NBIO interfaces will now use 64-bit fseek/ftell where possible, should allow for reading/writing to files bigger than 2GB
- IOS: Fixed iOS 6 version
- LOCALIZATION: Updates for several languages (synchronized from Crowdin)
- MENU: Enlarged INT/UINT selection limit from 999 to 9999
- MENU: Fix cursor forced to first entry after displaying lists
- MENU/WIDGETS: Add optional widget-based 'load content' launch feedback animation
- ODROID GO ADVANCE: Video driver - fix race condition with RGUI callback
- SHADERS/SLANG: Increased Slang max Parameters, Textures & Passes
- WINDOWS/RAWINPUT: Fix invalid calls to dinput_handle_message when input driver is not set to dinput
- X11: Add lightgun support
# 1.8.9
- AUTO SAVESTATES: Ensure save states are correctly flushed to disk when quitting RetroArch (fixes broken save states when exiting RetroArch - without first closing content - with 'Auto Save State' enabled)

View File

@ -217,7 +217,7 @@ $(OBJDIR)/%.o: %.m
.FORCE:
$(OBJDIR)/git_version.o: git_version.c .FORCE
$(OBJDIR)/version_git.o: version_git.c .FORCE
@mkdir -p $(dir $@)
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<
@ -233,7 +233,7 @@ $(OBJDIR)/%.o: %.rc $(HEADERS)
$(Q)$(WINDRES) -o $@ $<
install: $(TARGET)
rm -f $(OBJDIR)/git_version.o
rm -f $(OBJDIR)/version_git.o
mkdir -p $(DESTDIR)$(BIN_DIR) 2>/dev/null || /bin/true
mkdir -p $(DESTDIR)$(GLOBAL_CONFIG_DIR) 2>/dev/null || /bin/true
mkdir -p $(DESTDIR)$(DATA_DIR)/applications 2>/dev/null || /bin/true

View File

@ -175,8 +175,14 @@ OBJ += frontend/frontend_driver.o \
msg_hash.o \
intl/msg_hash_us.o \
$(LIBRETRO_COMM_DIR)/queues/task_queue.o \
tasks/task_content.o \
tasks/task_patch.o \
tasks/task_content.o
ifeq ($(HAVE_PATCH), 1)
DEFINES += -DHAVE_PATCH
OBJ += tasks/task_patch.o
endif
OBJ += \
tasks/task_save.o \
tasks/task_file_transfer.o \
tasks/task_image.o \
@ -184,8 +190,13 @@ OBJ += frontend/frontend_driver.o \
tasks/task_manual_content_scan.o \
tasks/task_core_backup.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_base64.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o
ifeq ($(HAVE_TRANSLATE), 1)
OBJ += $(LIBRETRO_COMM_DIR)/encodings/encoding_base64.o
endif
OBJ += \
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.o \
$(LIBRETRO_COMM_DIR)/lists/file_list.o \
$(LIBRETRO_COMM_DIR)/lists/dir_list.o \
@ -195,8 +206,9 @@ OBJ += frontend/frontend_driver.o \
$(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.o \
$(LIBRETRO_COMM_DIR)/streams/interface_stream.o \
$(LIBRETRO_COMM_DIR)/streams/memory_stream.o \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o \
$(LIBRETRO_COMM_DIR)/media/media_detect_cd.o \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o
OBJ += \
$(LIBRETRO_COMM_DIR)/lists/string_list.o \
$(LIBRETRO_COMM_DIR)/string/stdstring.o \
$(LIBRETRO_COMM_DIR)/memmap/memalign.o \
@ -236,34 +248,68 @@ OBJ += \
configuration.o \
$(LIBRETRO_COMM_DIR)/dynamic/dylib.o \
cores/dynamic_dummy.o \
$(LIBRETRO_COMM_DIR)/queues/message_queue.o \
managers/state_manager.o \
$(LIBRETRO_COMM_DIR)/queues/message_queue.o
ifeq ($(HAVE_REWIND), 1)
DEFINES += -DHAVE_REWIND
OBJ += managers/state_manager.o
endif
OBJ += \
gfx/drivers_font_renderer/bitmapfont.o \
tasks/task_autodetect.o \
input/input_autodetect_builtin.o \
input/input_keymaps.o \
$(LIBRETRO_COMM_DIR)/queues/fifo_queue.o \
$(LIBRETRO_COMM_DIR)/compat/compat_fnmatch.o \
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.o \
managers/cheat_manager.o \
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.o
ifeq ($(HAVE_CHEATS), 1)
DEFINES += -DHAVE_CHEATS
OBJ += managers/cheat_manager.o
endif
OBJ += \
core_info.o \
core_backup.o \
$(LIBRETRO_COMM_DIR)/file/config_file.o \
$(LIBRETRO_COMM_DIR)/file/config_file_userdata.o \
runtime_file.o \
disk_index_file.o \
tasks/task_screenshot.o \
disk_index_file.o
ifeq ($(HAVE_SCREENSHOTS), 1)
DEFINES += -DHAVE_SCREENSHOTS
OBJ += tasks/task_screenshot.o
endif
OBJ += \
tasks/task_powerstate.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/scaler.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/pixconv.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/scaler_int.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/scaler_filter.o \
gfx/font_driver.o \
gfx/video_filter.o \
$(LIBRETRO_COMM_DIR)/audio/resampler/audio_resampler.o \
$(LIBRETRO_COMM_DIR)/audio/dsp_filter.o \
$(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler.o \
$(LIBRETRO_COMM_DIR)/audio/resampler/drivers/nearest_resampler.o \
gfx/font_driver.o
ifeq ($(HAVE_VIDEO_FILTER), 1)
DEFINES += -DHAVE_VIDEO_FILTER
OBJ += gfx/video_filter.o
endif
OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/audio_resampler.o
ifeq ($(HAVE_DSP_FILTER), 1)
DEFINES += -DHAVE_DSP_FILTER
OBJ += $(LIBRETRO_COMM_DIR)/audio/dsp_filter.o
endif
OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler.o
ifeq ($(HAVE_NEAREST_RESAMPLER), 1)
DEFINES += -DHAVE_NEAREST_RESAMPLER
OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/nearest_resampler.o
endif
OBJ += \
$(LIBRETRO_COMM_DIR)/utils/md5.o \
playlist.o \
$(LIBRETRO_COMM_DIR)/features/features_cpu.o \
@ -275,7 +321,6 @@ OBJ += \
ifeq ($(HAVE_CONFIGFILE), 1)
DEFINES += -DHAVE_CONFIGFILE
OBJ += input/input_remapping.o
endif
ifeq ($(HAVE_BLISSBOX), 1)
@ -290,6 +335,10 @@ ifeq ($(HAVE_AUDIOMIXER), 1)
$(LIBRETRO_COMM_DIR)/audio/audio_mixer.o
endif
ifeq ($(HAVE_BSV_MOVIE), 1)
DEFINES += -DHAVE_BSV_MOVIE
endif
ifeq ($(HAVE_RUNAHEAD), 1)
DEFINES += -DHAVE_RUNAHEAD
endif
@ -486,27 +535,20 @@ ifeq ($(HAVE_BUILTINMBEDTLS), 1)
deps/mbedtls/ccm.o \
deps/mbedtls/cipher.o \
deps/mbedtls/cipher_wrap.o \
deps/mbedtls/cmac.o \
deps/mbedtls/ctr_drbg.o \
deps/mbedtls/des.o \
deps/mbedtls/dhm.o \
deps/mbedtls/ecdh.o \
deps/mbedtls/ecdsa.o \
deps/mbedtls/ecjpake.o \
deps/mbedtls/ecp.o \
deps/mbedtls/ecp_curves.o \
deps/mbedtls/entropy.o \
deps/mbedtls/entropy_poll.o \
deps/mbedtls/error.o \
deps/mbedtls/gcm.o \
deps/mbedtls/havege.o \
deps/mbedtls/hmac_drbg.o \
deps/mbedtls/md.o \
deps/mbedtls/md2.o \
deps/mbedtls/md4.o \
deps/mbedtls/md5.o \
deps/mbedtls/md_wrap.o \
deps/mbedtls/memory_buffer_alloc.o \
deps/mbedtls/oid.o \
deps/mbedtls/padlock.o \
deps/mbedtls/pem.o \
@ -516,7 +558,6 @@ ifeq ($(HAVE_BUILTINMBEDTLS), 1)
deps/mbedtls/pkcs5.o \
deps/mbedtls/pkparse.o \
deps/mbedtls/pkwrite.o \
deps/mbedtls/platform.o \
deps/mbedtls/ripemd160.o \
deps/mbedtls/rsa.o \
deps/mbedtls/sha1.o \
@ -524,12 +565,9 @@ ifeq ($(HAVE_BUILTINMBEDTLS), 1)
deps/mbedtls/sha512.o \
deps/mbedtls/threading.o \
deps/mbedtls/timing.o \
deps/mbedtls/version.o \
deps/mbedtls/version_features.o \
deps/mbedtls/xtea.o
OBJS_TLS_X509 = deps/mbedtls/certs.o \
deps/mbedtls/pkcs11.o \
deps/mbedtls/x509.o \
deps/mbedtls/x509_create.o \
deps/mbedtls/x509_crl.o \
@ -568,6 +606,16 @@ ifeq ($(HAVE_EMSCRIPTEN), 1)
camera/drivers/rwebcam.o
endif
ifeq ($(HAVE_BLUETOOTH), 1)
OBJ += bluetooth/drivers/bluetoothctl.o
endif
ifeq ($(HAVE_BLUETOOTH), 1)
ifeq ($(HAVE_DBUS), 1)
OBJ += bluetooth/drivers/bluez.o
endif
endif
ifeq ($(HAVE_LAKKA), 1)
OBJ += wifi/drivers/connmanctl.o
endif
@ -720,8 +768,11 @@ ifeq ($(HAVE_NEON),1)
endif
OBJ += $(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float.o \
$(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16.o \
$(LIBRETRO_COMM_DIR)/formats/wav/rwav.o
$(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16.o
ifeq ($(HAVE_RWAV), 1)
OBJ += $(LIBRETRO_COMM_DIR)/formats/wav/rwav.o
endif
ifeq ($(HAVE_NEON),1)
OBJ += $(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float_neon.o \
@ -810,6 +861,10 @@ ifeq ($(HAVE_MENU), 1)
endif
endif
ifeq ($(HAVE_BLUETOOTH), 1)
DEFINES += -DHAVE_BLUETOOTH
endif
ifeq ($(HAVE_LAKKA), 1)
DEFINES += -DHAVE_LAKKA
endif
@ -820,9 +875,6 @@ endif
ifeq ($(HAVE_MENU_COMMON), 1)
OBJ += menu/menu_setting.o \
menu/widgets/menu_filebrowser.o \
menu/widgets/menu_dialog.o \
menu/widgets/menu_input_bind_dialog.o \
menu/cbs/menu_cbs_ok.o \
menu/cbs/menu_cbs_cancel.o \
menu/cbs/menu_cbs_select.o \
@ -844,11 +896,18 @@ ifeq ($(HAVE_MENU_COMMON), 1)
endif
ifeq ($(HAVE_GFX_WIDGETS), 1)
OBJ += gfx/gfx_widgets.o \
gfx/widgets/gfx_widget_screenshot.o \
OBJ += gfx/gfx_widgets.o
ifeq ($(HAVE_SCREENSHOTS), 1)
OBJ += gfx/widgets/gfx_widget_screenshot.o
endif
OBJ += \
gfx/widgets/gfx_widget_volume.o \
gfx/widgets/gfx_widget_generic_message.o \
gfx/widgets/gfx_widget_libretro_message.o
gfx/widgets/gfx_widget_libretro_message.o \
gfx/widgets/gfx_widget_progress_message.o \
gfx/widgets/gfx_widget_load_content_animation.o
ifeq ($(HAVE_CHEEVOS), 1)
OBJ += gfx/widgets/gfx_widget_achievement_popup.o
endif
@ -993,11 +1052,17 @@ endif
ifeq ($(HAVE_WAYLAND), 1)
OBJ += gfx/drivers_context/wayland_ctx.o \
input/common/wayland_common.o \
input/drivers/wayland_input.o \
gfx/common/wayland/xdg-shell.o \
gfx/common/wayland/xdg-shell-unstable-v6.o \
gfx/common/wayland/idle-inhibit-unstable-v1.o \
gfx/common/wayland/xdg-decoration-unstable-v1.o
ifeq ($(HAVE_VULKAN), 1)
OBJ += gfx/drivers_context/wayland_vk_ctx.o
endif
DEF_FLAGS += $(WAYLAND_CFLAGS) $(WAYLAND_CURSOR_CFLAGS)
LIBS += $(WAYLAND_LIBS) $(WAYLAND_CURSOR_LIBS)
@ -1044,6 +1109,9 @@ ifeq ($(HAVE_X11), 1)
ifneq ($(HAVE_OPENGLES), 1)
OBJ += gfx/drivers_context/x_ctx.o
endif
ifeq ($(HAVE_VULKAN), 1)
OBJ += gfx/drivers_context/x_vk_ctx.o
endif
endif
ifeq ($(HAVE_XCB),1)
@ -1106,7 +1174,10 @@ ifeq ($(HAVE_PARPORT), 1)
endif
ifneq ($(findstring Win32,$(OS)),)
OBJ += input/drivers/winraw_input.o
ifeq ($(HAVE_WINRAWINPUT), 1)
DEFINES += -DHAVE_WINRAWINPUT
OBJ += input/drivers/winraw_input.o
endif
endif
# Companion UI
@ -1145,8 +1216,8 @@ endif
ifeq ($(HAVE_SIXEL), 1)
DEFINES += -DHAVE_SIXEL
INCLUDE_DIRS += -I/usr/include/sixel
OBJ += gfx/drivers/sixel_gfx.o gfx/drivers_font/sixel_font.o \
gfx/drivers_context/sixel_ctx.o
OBJ += gfx/drivers/sixel_gfx.o \
gfx/drivers_font/sixel_font.o
LIBS += $(SIXEL_LIBS)
DEF_FLAGS += $(SIXEL_CFLAGS)
endif
@ -1165,8 +1236,7 @@ ifeq ($(HAVE_NETWORK_VIDEO), 1)
endif
DEFINES += -DHAVE_NETWORK_VIDEO
OBJ += gfx/drivers/network_gfx.o \
gfx/drivers_context/network_ctx.o
OBJ += gfx/drivers/network_gfx.o
endif
ifeq ($(HAVE_PLAIN_DRM), 1)
@ -1550,12 +1620,15 @@ ifeq ($(HAVE_BUILTINGLSLANG), 1)
GLSLANG_SOURCES := \
gfx/drivers_shader/glslang.cpp \
$(wildcard $(DEPS_DIR)/glslang/glslang/SPIRV/*.cpp) \
$(DEPS_DIR)/glslang/glslang/SPIRV/GlslangToSpv.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/InReadableOrder.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/Logger.cpp \
$(DEPS_DIR)/glslang/glslang/SPIRV/SpvBuilder.cpp \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/GenericCodeGen/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/OGLCompilersDLL/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/preprocessor/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/OSDependent/$(GLSLANG_PLATFORM)/*.cpp)
$(DEPS_DIR)/glslang/glslang/glslang/OSDependent/$(GLSLANG_PLATFORM)/ossource.cpp
ifneq ($(findstring Win32,$(OS)),)
DEFINES += -DENABLE_HLSL
@ -1594,6 +1667,9 @@ endif
ifeq ($(WANT_WGL), 1)
OBJ += gfx/drivers_context/wgl_ctx.o
ifeq ($(HAVE_VULKAN),1)
OBJ += gfx/drivers_context/w_vk_ctx.o
endif
LIBS += -lcomctl32
endif
@ -1665,7 +1741,6 @@ endif
ifeq ($(HAVE_BUILTINZLIB), 1)
HAVE_ZLIB_COMMON = 1
OBJ += $(DEPS_DIR)/libz/adler32.o \
$(DEPS_DIR)/libz/compress.o \
$(DEPS_DIR)/libz/libz-crc32.o \
$(DEPS_DIR)/libz/deflate.o \
$(DEPS_DIR)/libz/gzclose.o \
@ -1676,7 +1751,6 @@ ifeq ($(HAVE_BUILTINZLIB), 1)
$(DEPS_DIR)/libz/inflate.o \
$(DEPS_DIR)/libz/inftrees.o \
$(DEPS_DIR)/libz/trees.o \
$(DEPS_DIR)/libz/uncompr.o \
$(DEPS_DIR)/libz/zutil.o
INCLUDE_DIRS += -I$(LIBRETRO_COMM_DIR)/include/compat/zlib
else ifeq ($(HAVE_ZLIB),1)
@ -1719,7 +1793,8 @@ ifeq ($(HAVE_CDROM), 1)
DEFINES += -DHAVE_CDROM
OBJ += $(LIBRETRO_COMM_DIR)/cdrom/cdrom.o \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation_cdrom.o
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation_cdrom.o \
$(LIBRETRO_COMM_DIR)/media/media_detect_cd.o
endif
ifeq ($(HAVE_RTGA), 1)
@ -1795,6 +1870,7 @@ ifeq ($(HAVE_NETWORKING), 1)
tasks/task_http.o \
tasks/task_netplay_lan_scan.o \
tasks/task_netplay_nat_traversal.o \
tasks/task_bluetooth.o \
tasks/task_wifi.o \
tasks/task_pl_thumbnail_download.o \
tasks/task_netplay_find_content.o
@ -1965,8 +2041,7 @@ ifeq ($(HAVE_NETWORKING), 1)
endif
ifneq ($(findstring FPGA,$(OS)),)
OBJ += gfx/drivers/fpga_gfx.o \
gfx/drivers_context/fpga_ctx.o
OBJ += gfx/drivers/fpga_gfx.o
endif
ifneq ($(findstring Win32,$(OS)),)
@ -1977,7 +2052,6 @@ ifneq ($(findstring Win32,$(OS)),)
ifeq ($(HAVE_GDI), 1)
OBJ += gfx/drivers/gdi_gfx.o \
gfx/drivers_context/gdi_ctx.o \
gfx/drivers_font/gdi_font.o \
gfx/drivers_display/gfx_display_gdi.o
LIBS += -lmsimg32
@ -2093,8 +2167,14 @@ ifeq ($(HAVE_MATH_NEON), 1)
endif
ifeq ($(HAVE_VITAGL), 1)
DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING
INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source
INCLUDE_DIRS += -I$(DEPS_DIR)/vitaShaRK/source
SOURCES := $(DEPS_DIR)/vitaShaRK/source
OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
endif
ifeq ($(HAVE_VITAGL), 1)
DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING -DHAVE_SHARK
INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source -I$(DEPS_DIR)/vitaShaRK/include
SOURCES := $(DEPS_DIR)/vitaGL/source $(DEPS_DIR)/vitaGL/source/utils
OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
endif

View File

@ -53,6 +53,9 @@ ifeq ($(GRIFFIN_BUILD), 1)
DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_RGUI -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_ZLIB -DHAVE_7ZIP -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA
DEFINES += -DHAVE_NETWORKING -DHAVE_CHEEVOS -DRC_DISABLE_LUA
DEFINES += -DHAVE_PATCH -DHAVE_RWAV
DEFINES += -DHAVE_SCREENSHOTS
DEFINES += -DHAVE_REWIND
#DEFINES += -DHAVE_SOCKET_LEGACY -DHAVE_THREADS
#-DHAVE_SSL -DHAVE_BUILTINMBEDTLS -DMBEDTLS_SSL_DEBUG_ALL
#ssl is currently incompatible with griffin due to use of the "static" flag on repeating functions that will conflict when included in one file
@ -73,6 +76,11 @@ else
HAVE_XMB = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_PATCH = 1
HAVE_SCREENSHOTS = 1
HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_RWAV = 1
#HAVE_NETWORKING = 1
#HAVE_CHEEVOS = 1
#HAVE_SOCKET_LEGACY = 1
@ -141,7 +149,10 @@ CFLAGS += -I. \
-Ilibretro-common/include/compat/zlib
CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE
CFLAGS += -DHAVE_DSP_FILTER
CFLAGS += -DHAVE_VIDEO_FILTER
CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES)
CFLAGS += -DHAVE_CHEATS
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

View File

@ -4,10 +4,14 @@ PACKAGE_NAME = retroarch
DEBUG ?= 0
HAVE_SCREENSHOTS = 1
HAVE_REWIND = 1
HAVE_7ZIP = 1
HAVE_AL = 1
# this freezes when switching back from menu
HAVE_ALSA = 0
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_BUILTINMBEDTLS = 1
HAVE_BUILTINZLIB = 1
HAVE_C99 = 1
@ -62,6 +66,8 @@ HAVE_VIDEO_LAYOUT = 1
HAVE_XMB = 1
HAVE_ZLIB = 1
HAVE_CONFIGFILE = 1
HAVE_PATCH = 1
HAVE_CHEATS = 1
OS = Linux
TARGET = retroarch
@ -160,7 +166,7 @@ $(OBJDIR)/%.o: %.m
.FORCE:
$(OBJDIR)/git_version.o: git_version.c .FORCE
$(OBJDIR)/version_git.o: version_git.c .FORCE
@mkdir -p $(dir $@)
@$(if $(Q), $(shell echo echo CC $<),)
$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<

View File

@ -9,8 +9,12 @@ OBJ :=
DEFINES := -DRARCH_INTERNAL -DHAVE_MAIN -s USE_PTHREADS=$(PTHREAD)
DEFINES += -DHAVE_FILTERS_BUILTIN
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_OVERLAY = 1
HAVE_GLSL = 1
HAVE_SCREENSHOTS = 1
HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_VIDEO_LAYOUT = 0
HAVE_CC_RESAMPLER = 1
@ -30,6 +34,7 @@ HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_STB_FONT = 1
HAVE_CONFIGFILE = 1
HAVE_CHEATS = 1
MEMORY = 134217728

View File

@ -191,8 +191,9 @@ else ifeq ($(libogc_platform), 1)
CFLAGS += -DGEKKO -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
HAVE_AUDIOMIXER := 1
HAVE_RUNAHEAD := 1
HAVE_DSP_FILTER := 1
HAVE_VIDEO_FILTER := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_THREADS := 1
HAVE_RPNG := 1
@ -204,11 +205,16 @@ else ifeq ($(libogc_platform), 1)
HAVE_VIDEO_LAYOUT := 0
HAVE_ZLIB := 1
HAVE_7ZIP := 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
RARCH_CONSOLE = 1
ifeq ($(platform), wii)
HAVE_AUDIOMIXER := 1
#HAVE_LANGEXTRA := 1
HAVE_WIIUSB_HID := 1
HAVE_RARCH_EXEC := 1
@ -244,7 +250,9 @@ else ifeq ($(platform), xenon360)
HAVE_THREADS := 1
HAVE_GETOPT_LONG := 1
RARCH_CONSOLE = 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
# PSP
else ifeq ($(platform), psp1)
@ -269,7 +277,9 @@ else ifeq ($(platform), psp1)
HAVE_KERNEL_PRX := 1
#HAVE_LANGEXTRA := 1
RARCH_CONSOLE = 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
ifeq ($(BUILD_PRX), 1)
LDFLAGS += $(addprefix -L,$(PSPSDK)/lib) -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx $(LDFLAGS)
@ -309,6 +319,8 @@ else ifeq ($(platform), vita)
LIBDIRS += -L.
LDFLAGS += -Wl,-q
HAVE_DSP_FILTER := 1
HAVE_VIDEO_FILTER := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_LANGEXTRA := 1
HAVE_RPNG := 1
@ -327,7 +339,9 @@ else ifeq ($(platform), vita)
HAVE_THREADS := 1
HAVE_LIBRETRODB := 1
RARCH_CONSOLE = 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
else ifeq ($(platform), windows_msvc6_x86)
HAVE_RPNG := 1
HAVE_RJPEG := 1
@ -351,7 +365,9 @@ else ifeq ($(platform), windows_msvc6_x86)
HAVE_DYLIB := 1
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -395,7 +411,9 @@ else ifeq ($(platform), windows_msvc2003_x86)
HAVE_DYLIB := 1
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -445,7 +463,9 @@ else ifeq ($(platform), windows_msvc2005_x86)
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
HAVE_DIRECTX ?= 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -472,7 +492,10 @@ else ifeq ($(platform), windows_msvc2005_x86)
endif
else ifneq (,$(findstring windows_msvc2010,$(platform)))
HAVE_GDI := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -497,7 +520,9 @@ else ifneq (,$(findstring windows_msvc2010,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -547,7 +572,10 @@ else ifneq (,$(findstring windows_msvc2010,$(platform)))
endif
else ifneq (,$(findstring windows_msvc2012,$(platform)))
HAVE_GDI := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -572,7 +600,9 @@ else ifneq (,$(findstring windows_msvc2012,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -626,7 +656,10 @@ else ifneq (,$(findstring windows_msvc2012,$(platform)))
endif
else ifneq (,$(findstring windows_msvc2013,$(platform)))
HAVE_GDI := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -651,7 +684,9 @@ else ifneq (,$(findstring windows_msvc2013,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -705,7 +740,10 @@ else ifneq (,$(findstring windows_msvc2013,$(platform)))
endif
else ifneq (,$(findstring windows_msvc2015,$(platform)))
HAVE_GDI := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -730,7 +768,9 @@ else ifneq (,$(findstring windows_msvc2015,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -799,7 +839,10 @@ else ifneq (,$(findstring windows_msvc2015,$(platform)))
export LIB := $(LIB)
endif
else ifeq (qnx,$(platform))
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -823,7 +866,10 @@ else ifeq (qnx,$(platform))
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 0
WANT_GLSLANG := 0
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
CC=qcc -Vgcc_ntoarmv7le
CXX=QCC -Vgcc_ntoarmv7le
@ -831,13 +877,16 @@ else ifeq (qnx,$(platform))
LDFLAGS += -g
endif
PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_XCB -DHAVE_EGL -DHAVE_BB10 -DHAVE_GLSL -DHAVE_AL -DRARCH_MOBILE
PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_XCB -DHAVE_EGL -DHAVE_BB10 -DHAVE_GLSL -DHAVE_AL -DHAVE_BSV_MOVIE -DRARCH_MOBILE
EXT_TARGET := $(TARGET_NAME)
EXT_INTER_TARGET := $(TARGET_NAME)
INCLUDE += -Ilibretro-common/include -Igfx/include -Ideps -Ideps/stb -Ideps/rcheevos/include -Ideps/SPIRV-Cross -Ideps/glslang -I.
LIBS += -lEGL -lbps -lscreen -lsocket -lm -lGLESv2 -lOpenAL
else ifneq (,$(findstring unix,$(platform)))
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -861,15 +910,16 @@ else ifneq (,$(findstring unix,$(platform)))
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
WANT_GLSLANG := 1
HAVE_CONFIGFILE := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
PLATCFLAGS += -D__MMX__ -D__SSE__ -DHAVE_OPENGL -DHAVE_OPENGL1 -DHAVE_GLSL -DHAVE_SHADERPIPELINE -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_SLANG -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_VULKAN -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_X11 -DHAVE_XCB -DHAVE_UDEV -DHAVE_PULSE
PLATCFLAGS += -D__MMX__ -D__SSE__ -DHAVE_OPENGL -DHAVE_OPENGL1 -DHAVE_GLSL -DHAVE_SHADERPIPELINE -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_SLANG -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_VULKAN -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_X11 -DHAVE_XCB -DHAVE_UDEV -DHAVE_BSV_MOVIE -DHAVE_PULSE
EXT_TARGET := $(TARGET_NAME)
EXT_INTER_TARGET := $(TARGET_NAME)
INCLUDE += -Ilibretro-common/include -Igfx/include -Ideps -Ideps/stb -Ideps/rcheevos/include -Ideps/SPIRV-Cross -Ideps/glslang -I.
LIBS += -ldl -lm -lpthread -lGL -ludev -lpulse -lX11 -lX11-xcb -lXxf86vm
else ifeq (dos,$(platform))
HAVE_AUDIOMIXER := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@ -881,7 +931,7 @@ else ifeq (dos,$(platform))
HAVE_NETPLAYDISCOVERY := 0
HAVE_OVERLAY := 1
HAVE_VIDEO_LAYOUT := 0
HAVE_MATERIALUI := 1
HAVE_MATERIALUI := 0
HAVE_XMB := 0
HAVE_STB_FONT := 1
HAVE_THREADS := 0
@ -894,6 +944,8 @@ else ifeq (dos,$(platform))
HAVE_GRIFFIN_CPP := 0
WANT_GLSLANG := 0
HAVE_CONFIGFILE := 1
HAVE_PATCH := 0
HAVE_CHEATS := 0
CC=i586-pc-msdosdjgpp-gcc
CXX=i586-pc-msdosdjgpp-g++
@ -901,7 +953,7 @@ else ifeq (dos,$(platform))
LDFLAGS += -g
endif
PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_CC_RESAMPLER -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DRARCH_INTERNAL -DHAVE_XCB
PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_CC_RESAMPLER -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DRARCH_INTERNAL -DHAVE_XCB
TARGET_NAME := retrodos
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@ -995,6 +1047,10 @@ ifeq ($(HAVE_IMAGEVIEWER), 1)
CFLAGS += -DHAVE_IMAGEVIEWER
endif
ifeq ($(HAVE_BSV_MOVIE), 1)
CFLAGS += -DHAVE_BSV_MOVIE
endif
ifeq ($(HAVE_RUNAHEAD), 1)
CFLAGS += -DHAVE_RUNAHEAD
endif
@ -1003,10 +1059,22 @@ ifeq ($(HAVE_7ZIP), 1)
CFLAGS += -DHAVE_7ZIP
endif
ifeq ($(HAVE_SCREENSHOTS), 1)
CFLAGS += -DHAVE_SCREENSHOTS
endif
ifeq ($(HAVE_REWIND), 1)
CFLAGS += -DHAVE_REWIND
endif
ifeq ($(HAVE_AUDIOMIXER), 1)
CFLAGS += -DHAVE_AUDIOMIXER
endif
ifeq ($(HAVE_RWAV), 1)
CFLAGS += -DHAVE_RWAV
endif
ifeq ($(HAVE_OVERLAY), 1)
CFLAGS += -DHAVE_OVERLAY
endif
@ -1053,6 +1121,14 @@ ifeq ($(HAVE_LANGEXTRA), 1)
CFLAGS += -DHAVE_LANGEXTRA
endif
ifeq ($(HAVE_DSP_FILTER), 1)
CFLAGS += -DHAVE_DSP_FILTER
endif
ifeq ($(HAVE_VIDEO_FILTER), 1)
CFLAGS += -DHAVE_VIDEO_FILTER
endif
ifeq ($(HAVE_FILTERS_BUILTIN), 1)
CFLAGS += -DHAVE_FILTERS_BUILTIN
endif
@ -1073,6 +1149,14 @@ ifeq ($(HAVE_CONFIGFILE), 1)
CFLAGS += -DHAVE_CONFIGFILE
endif
ifeq ($(HAVE_PATCH), 1)
CFLAGS += -DHAVE_PATCH
endif
ifeq ($(HAVE_CHEATS), 1)
CFLAGS += -DHAVE_CHEATS
endif
ifeq ($(HAVE_RSOUND), 1)
CFLAGS += -DHAVE_RSOUND
endif

View File

@ -23,6 +23,8 @@ DEFINES := -D__SWITCH__=1 -U__linux__ -U__linux -DGLM_FORCE_PURE=1 -DRARCH_CONSO
HAVE_DR_MP3 = 1
HAVE_TRANSLATE = 1
HAVE_SCREENSHOTS = 1
HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_CC_RESAMPLER = 1
HAVE_MENU_COMMON = 1
@ -33,10 +35,14 @@ HAVE_RBMP = 1
HAVE_ZLIB = 1
HAVE_BUILTINZLIB = 1
HAVE_LIBRETRODB = 1
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_MENU = 1
HAVE_CONFIGFILE = 1
HAVE_PATCH = 1
HAVE_CHEATS = 1
HAVE_RUNAHEAD = 1
HAVE_NETWORKING = 1
HAVE_NETPLAYDISCOVERY = 1

View File

@ -11,6 +11,10 @@ WindowsSdkDir = C:\Program Files (x86)\Windows Kits\10\$(NOTHING)
WindowsSDKVersion := 10.0.14393.0\$(NOTHING)
VCINSTALLDIR := C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\$(NOTHING)
HAVE_DSP_FILTER := 1
HAVE_VIDEO_FILTER := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_D3DX := 1
HAVE_D3D8 := 0
@ -32,6 +36,7 @@ HAVE_WINMM := 1
HAVE_RPNG := 1
HAVE_ZLIB := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_MENU := 1
HAVE_RGUI := 1
HAVE_XMB := 1
@ -60,6 +65,8 @@ HAVE_LANGEXTRA := 1
HAVE_CHEEVOS := 1
HAVE_SHADERPIPELINE := 1
HAVE_IMAGEVIEWER := 1
HAVE_BSV_MOVIE := 1
HAVE_CHEATS := 1
ifeq ($(HAVE_D3D8), 1)
D3D8_LIBS := -ld3d8
@ -192,7 +199,7 @@ else
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
endif
DEFINES += -DRARCH_INTERNAL -DHAVE_DYNAMIC -DJSON_STATIC
DEFINES += -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_DYNAMIC -DJSON_STATIC
INCLUDE_DIRS += -I. -Igfx/include
#OBJ := version_git.o

View File

@ -15,7 +15,9 @@ LDFLAGS = -L$(PNDSDK)/usr/lib -Wl,-rpath,$(PNDSDK)/usr/lib
LIBS = -lGLESv2 -lEGL -ldl -lm -lpthread -lrt -lasound
DEFINES = -std=gnu99 -DHAVE_THREADS -DHAVE_GETOPT_LONG=1 -DHAVE_GRIFFIN -DRARCH_INTERNAL
DEFINES += -DHAVE_CONFIGFILE -D__ARM_ARCH_6__ -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_GLSL -DHAVE_DYNAMIC -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_OVERLAY -DHAVE_VIDEO_LAYOUT -DHAVE_ALSA -DHAVE_ZLIB -D__linux__
DEFINES += -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SCREENSHOTS -DHAVE_REWIND -D__ARM_ARCH_6__ -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_GLSL -DHAVE_DYNAMIC -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_OVERLAY -DHAVE_VIDEO_LAYOUT -DHAVE_ALSA -DHAVE_ZLIB -D__linux__
DEFINES += -DHAVE_DSP_FILTER
DEFINES += -DHAVE_VIDEO_FILTER
DEFINES += $(INCDIRS)
DEFINES += -D__OPENPANDORA__ -DPANDORA
DEFINES += -marm -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize

View File

@ -16,13 +16,16 @@ DEFINES :=
ifeq ($(GRIFFIN_BUILD), 1)
OBJ += griffin/griffin.o
DEFINES += -DHAVE_GRIFFIN=1
DEFINES += -DHAVE_MENU -DHAVE_LIBRETRODB -DHAVE_CONFIGFILE
DEFINES += -DHAVE_MENU -DHAVE_LIBRETRODB -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SCREENSHOTS -DHAVE_CHEATS
DEFINES += -DHAVE_REWIND
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER
ifeq ($(DEBUG), 1)
DEFINES += -DHAVE_NETLOGGER
endif
else
HAVE_DSP_FILTER := 1
HAVE_VIDEO_FILTER := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_LANGEXTRA := 0
HAVE_RPNG := 1
@ -42,6 +45,10 @@ else
HAVE_MENU := 1
HAVE_MENU_COMMON := 1
HAVE_CONFIGFILE := 1
HAVE_SCREENSHOTS := 1
HAVE_REWIND := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
HAVE_RGUI := 0
HAVE_MATERIALUI := 0
HAVE_XMB := 1

View File

@ -6,12 +6,11 @@ HAVE_THREADS = 0
MUTE_WARNINGS = 1
PS2_IP = 192.168.1.150
TARGET = retroarchps2.elf
TARGET_RELEASE = retroarchps2-release.elf
TARGET = retroarchps2-debug.elf
TARGET_RELEASE = retroarchps2.elf
# Compile the IRXs first
IRX_DIR = ps2/irx
IRX_FILES = $(wildcard ps2/irx/*.c)
ifeq ($(DEBUG), 1)
OPTIMIZE_LV := -O0 -g
@ -31,12 +30,14 @@ INCDIR += -Ideps/pthreads -Ideps/pthreads/platform/ps2 -Ideps/pthreads/platform/
CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant
ASFLAGS = $(CFLAGS)
RARCH_DEFINES += -DPS2 -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_RGUI
RARCH_DEFINES += -DPS2 -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI
RARCH_DEFINES += -DHAVE_ZLIB -DHAVE_NO_BUILTINZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -DHAVE_CC_RESAMPLER
RARCH_DEFINES += -DHAVE_DSP_FILTER
RARCH_DEFINES += -DHAVE_VIDEO_FILTER
LDFLAGS += -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ports/lib -L.
# Lib cdvd is needed to get proper time
LIBS += -lretro_ps2 -lpatches -lpoweroff -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd
LIBS += -lretro_ps2 -lpatches -lpoweroff -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd -lelf-loader
ifeq ($(BUILD_FOR_PCSX2), 1)
RARCH_DEFINES += -DBUILD_FOR_PCSX2

103
Makefile.ps2.salamander Normal file
View File

@ -0,0 +1,103 @@
BUILD_FOR_PCSX2 = 0
DEBUG = 0
HAVE_FILE_LOGGER = 0
MUTE_WARNINGS = 1
PS2_IP = 192.168.1.150
TARGET = raboot-debug.elf
TARGET_RELEASE = raboot.elf
# Compile the IRXs first
IRX_DIR = ps2/irx
ifeq ($(DEBUG), 1)
OPTIMIZE_LV := -O0 -g
RARCH_DEFINES += -DDEBUG
else
OPTIMIZE_LV := -O3
LDFLAGS := -s
endif
ifeq ($(MUTE_WARNINGS), 1)
DISABLE_WARNINGS := -Wno-sign-compare -Wno-unused -Wno-parentheses
endif
INCDIR = -Ilibretro-common/include
INCDIR += -Ips2/include
CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant
ASFLAGS = $(CFLAGS)
RARCH_DEFINES += -DPS2 -DIS_SALAMANDER -DRARCH_CONSOLE
LIBDIR =
LDFLAGS =
LIBS = -lm -lelf-loader -lpatches -lpoweroff
ifeq ($(BUILD_FOR_PCSX2), 1)
RARCH_DEFINES += -DBUILD_FOR_PCSX2
endif
ifeq ($(HAVE_FILE_LOGGER), 1)
CFLAGS += -DHAVE_FILE_LOGGER
endif
CFLAGS += $(RARCH_DEFINES)
EE_OBJS = frontend/frontend_salamander.o \
frontend/frontend_driver.o \
frontend/drivers/platform_ps2.o \
libretro-common/file/file_path.o \
libretro-common/file/file_path_io.o \
libretro-common/string/stdstring.o \
libretro-common/lists/string_list.o \
libretro-common/lists/dir_list.o \
libretro-common/file/retro_dirent.o \
libretro-common/encodings/encoding_utf.o \
libretro-common/compat/fopen_utf8.o \
libretro-common/compat/compat_strl.o \
libretro-common/compat/compat_strcasestr.o \
libretro-common/file/config_file.o \
libretro-common/streams/file_stream.o \
libretro-common/vfs/vfs_implementation.o \
libretro-common/hash/rhash.o \
libretro-common/time/rtime.o \
file_path_str.o \
verbosity.o \
ps2/compat_files/ps2_devices.o
# Needed IRX objects
EE_OBJS += $(IRX_DIR)/freesio2_irx.o $(IRX_DIR)/iomanX_irx.o $(IRX_DIR)/cdfs_irx.o
EE_OBJS += $(IRX_DIR)/fileXio_irx.o $(IRX_DIR)/mcman_irx.o $(IRX_DIR)/mcserv_irx.o $(IRX_DIR)/usbd_irx.o
EE_OBJS += $(IRX_DIR)/usbhdfsd_irx.o $(IRX_DIR)/freesd_irx.o $(IRX_DIR)/poweroff_irx.o
EE_CFLAGS = $(CFLAGS)
EE_CXXFLAGS = $(CFLAGS)
EE_LDFLAGS = $(LDFLAGS)
EE_LIBS = $(LIBS)
EE_ASFLAGS = $(ASFLAGS)
EE_INCS = $(INCDIR)
EE_BIN = $(TARGET)
EE_GPVAL = $(GPVAL)
all: irxdir $(EE_BIN)
irxdir:
$(MAKE) -C $(IRX_DIR)
clean:
rm -f $(EE_BIN) $(EE_OBJS)
$(MAKE) -C $(IRX_DIR) clean
debug: clean all run
run:
ps2client -h $(PS2_IP) execee host:$(EE_BIN)
package:
ps2-packer $(EE_BIN) $(TARGET_RELEASE)
release: clean all package
#Include preferences
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal_cpp

View File

@ -70,7 +70,7 @@ endif
PPU_SRCS = griffin/griffin.c
DEFINES += -DHAVE_VIDEO_LAYOUT
DEFINES += -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_GFX_WIDGETS -DHAVE_RGUI -DHAVE_XMB -DHAVE_OZONE -DHAVE_LIBRETRODB -DHAVE_MATERIALUI -DHAVE_SHADERPIPELINE -DRARCH_INTERNAL -DHAVE_OVERLAY -DHAVE_CC_RESAMPLER -DHAVE_STB_VORBIS -DHAVE_STB_FONT -DHAVE_RUNAHEAD -DHAVE_DR_MP3 -DHAVE_DR_FLAC
DEFINES += -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_GFX_WIDGETS -DHAVE_RGUI -DHAVE_XMB -DHAVE_OZONE -DHAVE_LIBRETRODB -DHAVE_MATERIALUI -DHAVE_SHADERPIPELINE -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_OVERLAY -DHAVE_CC_RESAMPLER -DHAVE_STB_VORBIS -DHAVE_STB_FONT -DHAVE_RUNAHEAD -DHAVE_DR_MP3 -DHAVE_DR_FLAC
DEFINES += -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES
ifeq ($(DEX_BUILD), 1)
@ -117,7 +117,7 @@ PPU_LDLIBS = $(FONT_LIBS) $(GL_LIBS) $(WHOLE_START) -lretro_ps3 $(WHOLE_END) -l
PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe
DEFINES += -DHAVE_THREADS -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_HEADSET -DHAVE_LANGEXTRA -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_7Z -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_FILTERS_BUILTIN -DHAVE_CHEEVOS -DRC_DISABLE_LUA
DEFINES += -DHAVE_THREADS -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_HEADSET -DHAVE_LANGEXTRA -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_7Z -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_FILTERS_BUILTIN -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_DSP_FILTER -DHAVE_VIDEO_FILTER
#DEFINES += -DHAVE_IMAGEVIEWER

View File

@ -108,7 +108,7 @@ PPU_LDLIBS = $(FONT_LIBS) $(GL_LIBS) $(WHOLE_START) -lretro_ps3 $(WHOLE_END) -l
PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe
#DEFINES += -DHAVE_VIDEO_LAYOUT
DEFINES += -DHAVE_THREADS -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=0 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_STB_VORBIS
DEFINES += -DHAVE_THREADS -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_PATCH -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=0 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_STB_VORBIS
ifeq ($(DEBUG), 1)
PPU_OPTIMIZE_LV := -O0 -g

View File

@ -66,7 +66,7 @@ endif
SHARED_FLAGS :=
SHARED_FLAGS += -DHAVE_VIDEO_LAYOUT
SHARED_FLAGS += -DHAVE_MENU -DHAVE_CONFIGFILE -DRARCH_CONSOLE -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_GCMGL -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_MOUSE -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_GRIFFIN=1 -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -Wno-char-subscripts -DHAVE_CC_RESAMPLER -DRARCH_INTERNAL -DHAVE_MULTIMAN -DHAVE_RGUI
SHARED_FLAGS += -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DRARCH_CONSOLE -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_GCMGL -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_MOUSE -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_GRIFFIN=1 -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -Wno-char-subscripts -DHAVE_CC_RESAMPLER -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_MULTIMAN -DHAVE_RGUI
CFLAGS += -std=gnu99 $(SHARED_FLAGS)
CXXFLAGS += $(SHARED_FLAGS)

View File

@ -25,7 +25,7 @@ INCDIR = deps deps/stb deps/7zip deps/pthreads deps/pthreads/platform/psp deps/p
CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math -fsingle-precision-constant
ASFLAGS = $(CFLAGS)
RARCH_DEFINES = -DPSP -D_MIPS_ARCH_ALLEGREX -DHAVE_LANGEXTRA -DHAVE_ZLIB -DHAVE_AUDIOMIXER -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_RGUI -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -DHAVE_CC_RESAMPLER
RARCH_DEFINES = -DPSP -D_MIPS_ARCH_ALLEGREX -DHAVE_LANGEXTRA -DHAVE_ZLIB -DHAVE_AUDIOMIXER -DHAVE_RWAV -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI -DHAVE_FILTERS_BUILTIN -DHAVE_DSP_FILTER -DHAVE_VIDEO_FILTER -DHAVE_7ZIP -DHAVE_CC_RESAMPLER
LIBDIR =
LDFLAGS =

View File

@ -6,16 +6,18 @@ WHOLE_ARCHIVE_LINK = 0
OBJ :=
DEFINES := -DSWITCH=1 -U__linux__ -U__linux -DRARCH_INTERNAL -DHAVE_DYNAMIC
DEFINES := -DSWITCH=1 -U__linux__ -U__linux -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_DYNAMIC -DHAVE_REWIND
ifeq ($(GRIFFIN_BUILD), 1)
OBJ += griffin/griffin.o
DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_NEON -DHAVE_MATERIALUI -DHAVE_LIBRETRODB -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA
DEFINES += -DHAVE_RUNAHEAD -DHAVE_DYNAMIC
DEFINES += -DHAVE_CONFIGFILE
DEFINES += -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS
else
HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_RWAV = 1
HAVE_CC_RESAMPLER = 1
HAVE_MENU_COMMON = 1
HAVE_RTGA = 1
@ -24,6 +26,8 @@ else
HAVE_RBMP = 1
HAVE_RGUI = 1
HAVE_ZLIB = 1
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_BUILTINZLIB = 1
HAVE_LIBRETRODB = 1
HAVE_MATERIALUI = 0 # enable later?
@ -34,6 +38,8 @@ else
HAVE_CONFIGFILE = 1
HAVE_RUNAHEAD = 1
HAVE_DYNAMIC = 1
HAVE_PATCH = 1
HAVE_CHEATS = 1
include Makefile.common
CFLAGS += $(DEF_FLAGS)

View File

@ -18,18 +18,22 @@ INCDIRS :=
ifeq ($(GRIFFIN_BUILD), 1)
OBJ += griffin/griffin.o
DEFINES += -DHAVE_GRIFFIN=1
DEFINES += -DHAVE_NEON -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB DEFINES -DHAVE_KEYMAPPER
DEFINES += -DHAVE_REWIND
DEFINES += -DHAVE_NEON -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB DEFINES -DHAVE_KEYMAPPER
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER
ifeq ($(DEBUG), 1)
DEFINES += -DHAVE_NETLOGGER
endif
INCDIRS += -I. -Ideps/7zip -Ilibretro-common/include -Ilibretro-common/include/compat/zlib -Ideps/stb
else
HAVE_REWIND := 1
HAVE_UPDATE_ASSETS := 1
HAVE_ONLINE_UPDATER := 1
HAVE_NEON := 1
HAVE_MATH_NEON := 1
HAVE_DSP_FILTER := 1
HAVE_VIDEO_FILTER := 1
HAVE_SCREENSHOTS := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_LANGEXTRA := 1
HAVE_RPNG := 1
@ -46,6 +50,8 @@ else
HAVE_MENU_COMMON := 1
HAVE_GFX_WIDGETS := 1
HAVE_CONFIGFILE := 1
HAVE_PATCH := 1
HAVE_CHEATS := 1
HAVE_OVERLAY := 1
HAVE_VIDEO_LAYOUT := 0
HAVE_MATERIALUI := 1
@ -61,6 +67,7 @@ else
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_AUDIOMIXER := 1
HAVE_RWAV := 1
ifeq ($(DEBUG), 1)
HAVE_NETLOGGER = 1
@ -103,7 +110,9 @@ ASFLAGS := $(CFLAGS)
LDFLAGS := -Wl,-q
CFLAGS += -Wall -ffast-math -g
CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE
CFLAGS += -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DRARCH_CONSOLE
CFLAGS += -DHAVE_DSP_FILTER
CFLAGS += -DHAVE_VIDEO_FILTER
CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES)
ifneq ($(PC_DEVELOPMENT_IP_ADDRESS),)
@ -123,7 +132,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
VITA_LIBS := -lSceDisplay_stub -lSceGxm_stub -lSceNet_stub -lSceNetCtl_stub -lSceAppUtil_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lSceHid_stub -lSceTouch_stub -lSceAudio_stub \
-lScePower_stub -lSceRtc_stub -lSceCommonDialog_stub -lScePgf_stub -lSceMotion_stub \
-lSceFiber_stub -lSceMotion_stub -lSceAppMgr_stub -lstdc++ -lpthread -lpng -lz
-lSceFiber_stub -lSceMotion_stub -lSceAppMgr_stub -lstdc++ -lpthread -lpng -lz -lSceShaccCg_stub
LIBS := $(WHOLE_START) -lretro_vita $(WHOLE_END) $(VITA_LIBS) -lm -lc
@ -156,7 +165,13 @@ all: $(TARGETS)
%.depend: ;
$(TARGET).elf: $(OBJ) libretro_vita.a
libSceShaccCg_stub.a:
mkdir -p deps/vitaShaRK/SceShaccCg
vita-libs-gen deps/vitaShaRK/SceShaccCg.yml deps/vitaShaRK/SceShaccCg
make -C deps/vitaShaRK/SceShaccCg ARCH=arm-vita-eabi
cp deps/vitaShaRK/SceShaccCg/libSceShaccCg_stub.a .
$(TARGET).elf: $(OBJ) libretro_vita.a libSceShaccCg_stub.a
$(LD) $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@
%.velf: %.elf
@ -172,7 +187,8 @@ $(TARGET).elf: $(OBJ) libretro_vita.a
vita-pack-vpk -s param.sfo -b $< $@
clean:
rm -f $(OBJ) $(TARGET).elf $(TARGET).elf.unstripped.elf $(TARGET).velf $(TARGET).self param.sfo $(TARGET).vpk
rm -f $(OBJ) $(TARGET).elf $(TARGET).elf.unstripped.elf $(TARGET).velf $(TARGET).self param.sfo $(TARGET).vpk libSceShaccCg_stub.a
rm -rf deps/vitaShaRK/SceShaccCg
rm -f $(OBJ:.o=.depend)
# Useful for developers

View File

@ -74,6 +74,7 @@ ifeq ($(SALAMANDER_BUILD),1)
# $(SALAMANDER_BUILD),0
else
DEFINES += -DRARCH_INTERNAL
DEFINES += -DHAVE_SCREENSHOTS
DEFINES += -DHAVE_KEYMAPPER
DEFINES += -DHAVE_ONLINE_UPDATER
DEFINES += -DHAVE_UPDATE_ASSETS
@ -108,7 +109,9 @@ endif
INCDIRS += -Ideps/SPIRV-Cross
DEFINES += -DHAVE_AUDIOMIXER
DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_RGUI -DHAVE_LIBRETRODB
DEFINES += -DHAVE_RWAV
DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI -DHAVE_LIBRETRODB
DEFINES += -DHAVE_REWIND
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_SPIRV_CROSS -DHAVE_SLANG
DEFINES += -DHAVE_STB_FONT -DHAVE_STB_VORBIS -DHAVE_LANGEXTRA -DHAVE_LIBRETRODB -DHAVE_NETWORKING -DHAVE_NETPLAYDISCOVERY
@ -121,7 +124,9 @@ endif
# $(GRIFFIN_BUILD),0
else
HAVE_SCREENSHOTS = 1
HAVE_AUDIOMIXER = 1
HAVE_RWAV = 1
HAVE_MENU_COMMON = 1
HAVE_GFX_WIDGETS = 1
HAVE_RTGA = 1
@ -129,6 +134,9 @@ endif
HAVE_RJPEG = 1
HAVE_RBMP = 1
HAVE_CONFIGFILE = 1
HAVE_PATCH = 1
HAVE_REWIND = 1
HAVE_CHEATS = 1
HAVE_MENU = 1
HAVE_RGUI = 1
HAVE_7ZIP = 1
@ -149,6 +157,8 @@ endif
HAVE_SPIRV_CROSS = 1
HAVE_SLANG = 1
HAVE_VIDEO_LAYOUT = 0
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
WANT_LIBFAT = 1

View File

@ -1,6 +1,8 @@
TARGET = retroarch.exe
HAVE_SCREENSHOTS = 1
HAVE_AUDIOMIXER = 1
HAVE_RWAV = 1
HAVE_DINPUT = 1
HAVE_XAUDIO = 1
HAVE_DSOUND = 1
@ -15,8 +17,13 @@ HAVE_COMMAND = 1
HAVE_THREADS = 1
HAVE_MENU = 1
HAVE_CONFIGFILE = 1
HAVE_PATCH = 1
HAVE_REWIND = 1
HAVE_CHEATS = 1
HAVE_RGUI = 1
HAVE_MATERIALUI = 1
HAVE_DSP_FILTER = 1
HAVE_VIDEO_FILTER = 1
HAVE_7ZIP = 1
HAVE_PYTHON = 0
DYNAMIC = 1
@ -96,7 +103,7 @@ OS := Win32
OBJ :=
LIBS := -lm
DEFINES :=
DEFINES += -I. -Ilibretro-common/include -Ilibretro-common/include/compat/zlib -DRARCH_INTERNAL -DHAVE_OVERLAY
DEFINES += -I. -Ilibretro-common/include -Ilibretro-common/include/compat/zlib -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_OVERLAY
#DEFINES += -DHAVE_VIDEO_LAYOUT
LDFLAGS := -L. -static-libgcc
@ -162,7 +169,7 @@ $(OBJDIR)/%.o: %.c
.FORCE:
$(OBJDIR)/git_version.o: git_version.c .FORCE
$(OBJDIR)/version_git.o: version_git.c .FORCE
@-mkdir -p $(dir $@) || mkdir $(subst /,\,$(dir $@)) || echo .
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<

View File

@ -30,7 +30,7 @@ RETRO_BEGIN_DECLS
#define AUDIO_MIXER_MAX_STREAMS 16
#define AUDIO_MIXER_MAX_SYSTEM_STREAMS (AUDIO_MIXER_MAX_STREAMS + 4)
#define AUDIO_MIXER_MAX_SYSTEM_STREAMS (AUDIO_MIXER_MAX_STREAMS + 5)
/* do not define more than (MAX_SYSTEM_STREAMS - MAX_STREAMS) */
enum audio_mixer_system_slot
@ -38,7 +38,8 @@ enum audio_mixer_system_slot
AUDIO_MIXER_SYSTEM_SLOT_OK = AUDIO_MIXER_MAX_STREAMS,
AUDIO_MIXER_SYSTEM_SLOT_CANCEL,
AUDIO_MIXER_SYSTEM_SLOT_NOTICE,
AUDIO_MIXER_SYSTEM_SLOT_BGM
AUDIO_MIXER_SYSTEM_SLOT_BGM,
AUDIO_MIXER_SYSTEM_SLOT_ACHIEVEMENT_UNLOCK
};
enum audio_action

View File

@ -66,7 +66,7 @@ static void alsa_worker_thread(void *data)
size_t fifo_size;
snd_pcm_sframes_t frames;
slock_lock(alsa->fifo_lock);
avail = fifo_read_avail(alsa->buffer);
avail = FIFO_READ_AVAIL(alsa->buffer);
fifo_size = MIN(alsa->period_size, avail);
fifo_read(alsa->buffer, buf, fifo_size);
scond_signal(alsa->cond);
@ -256,7 +256,7 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
size_t write_amt;
slock_lock(alsa->fifo_lock);
avail = fifo_write_avail(alsa->buffer);
avail = FIFO_WRITE_AVAIL(alsa->buffer);
write_amt = MIN(avail, size);
fifo_write(alsa->buffer, buf, write_amt);
@ -271,7 +271,7 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
{
size_t avail;
slock_lock(alsa->fifo_lock);
avail = fifo_write_avail(alsa->buffer);
avail = FIFO_WRITE_AVAIL(alsa->buffer);
if (avail == 0)
{
@ -334,7 +334,7 @@ static size_t alsa_thread_write_avail(void *data)
if (alsa->thread_dead)
return 0;
slock_lock(alsa->fifo_lock);
val = fifo_write_avail(alsa->buffer);
val = FIFO_WRITE_AVAIL(alsa->buffer);
slock_unlock(alsa->fifo_lock);
return val;
}

View File

@ -103,7 +103,7 @@ static OSStatus audio_write_cb(void *userdata,
slock_lock(dev->lock);
if (fifo_read_avail(dev->buffer) < write_avail)
if (FIFO_READ_AVAIL(dev->buffer) < write_avail)
{
*action_flags = kAudioUnitRenderAction_OutputIsSilence;
@ -356,14 +356,14 @@ static ssize_t coreaudio_write(void *data, const void *buf_, size_t size)
slock_lock(dev->lock);
write_avail = fifo_write_avail(dev->buffer);
write_avail = FIFO_WRITE_AVAIL(dev->buffer);
if (write_avail > size)
write_avail = size;
fifo_write(dev->buffer, buf, write_avail);
buf += write_avail;
buf += write_avail;
written += write_avail;
size -= write_avail;
size -= write_avail;
if (dev->nonblock)
{
@ -430,7 +430,7 @@ static size_t coreaudio_write_avail(void *data)
coreaudio_t *dev = (coreaudio_t*)data;
slock_lock(dev->lock);
avail = fifo_write_avail(dev->buffer);
avail = FIFO_WRITE_AVAIL(dev->buffer);
slock_unlock(dev->lock);
return avail;

View File

@ -155,7 +155,7 @@ static DWORD CALLBACK dsound_thread(PVOID data)
avail = write_avail(read_ptr, write_ptr, ds->buffer_size);
EnterCriticalSection(&ds->crit);
fifo_avail = fifo_read_avail(ds->buffer);
fifo_avail = FIFO_READ_AVAIL(ds->buffer);
LeaveCriticalSection(&ds->crit);
if (avail < CHUNK_SIZE || ((fifo_avail < CHUNK_SIZE) && (avail < ds->buffer_size / 2)))
@ -511,7 +511,7 @@ static ssize_t dsound_write(void *data, const void *buf_, size_t size)
size_t avail;
EnterCriticalSection(&ds->crit);
avail = fifo_write_avail(ds->buffer);
avail = FIFO_WRITE_AVAIL(ds->buffer);
if (avail > size)
avail = size;
@ -530,7 +530,7 @@ static ssize_t dsound_write(void *data, const void *buf_, size_t size)
size_t avail;
EnterCriticalSection(&ds->crit);
avail = fifo_write_avail(ds->buffer);
avail = FIFO_WRITE_AVAIL(ds->buffer);
if (avail > size)
avail = size;
@ -558,7 +558,7 @@ static size_t dsound_write_avail(void *data)
dsound_t *ds = (dsound_t*)data;
EnterCriticalSection(&ds->crit);
avail = fifo_write_avail(ds->buffer);
avail = FIFO_WRITE_AVAIL(ds->buffer);
LeaveCriticalSection(&ds->crit);
return avail;
}

View File

@ -109,7 +109,7 @@ static INLINE void copy_swapped(uint32_t * restrict dst,
{
uint32_t s = *src++;
*dst++ = (s >> 16) | (s << 16);
}while(--size);
} while (--size);
}
static ssize_t gx_audio_write(void *data, const void *buf_, size_t size)

View File

@ -67,7 +67,7 @@ static void opensl_callback(SLAndroidSimpleBufferQueueItf bq, void *ctx)
#define GOTO_IF_FAIL(x) do { \
if ((res = (x)) != SL_RESULT_SUCCESS) \
goto error; \
} while(0)
} while (0)
static void sl_free(void *data)
{

View File

@ -61,7 +61,7 @@ static void event_loop(uint64_t data)
sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT);
sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT);
if (fifo_read_avail(aud->buffer) >= sizeof(out_tmp))
if (FIFO_READ_AVAIL(aud->buffer) >= sizeof(out_tmp))
fifo_read(aud->buffer, out_tmp, sizeof(out_tmp));
else
memset(out_tmp, 0, sizeof(out_tmp));
@ -152,11 +152,11 @@ static ssize_t ps3_audio_write(void *data, const void *buf, size_t size)
if (aud->nonblock)
{
if (fifo_write_avail(aud->buffer) < size)
if (FIFO_WRITE_AVAIL(aud->buffer) < size)
return 0;
}
while (fifo_write_avail(aud->buffer) < size)
while (FIFO_WRITE_AVAIL(aud->buffer) < size)
sys_lwcond_wait(&aud->cond, 0);
sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT);

View File

@ -39,9 +39,8 @@ typedef struct rsd
static ssize_t rsound_audio_cb(void *data, size_t bytes, void *userdata)
{
rsd_t *rsd = (rsd_t*)userdata;
size_t avail = fifo_read_avail(rsd->buffer);
rsd_t *rsd = (rsd_t*)userdata;
size_t avail = FIFO_READ_AVAIL(rsd->buffer);
size_t write_size = bytes > avail ? avail : bytes;
fifo_read(rsd->buffer, data, write_size);
scond_signal(rsd->cond);
@ -115,7 +114,7 @@ static ssize_t rs_write(void *data, const void *buf, size_t size)
rsd_callback_lock(rsd->rd);
avail = fifo_write_avail(rsd->buffer);
avail = FIFO_WRITE_AVAIL(rsd->buffer);
write_amt = avail > size ? size : avail;
fifo_write(rsd->buffer, buf, write_amt);
@ -130,7 +129,7 @@ static ssize_t rs_write(void *data, const void *buf, size_t size)
size_t avail;
rsd_callback_lock(rsd->rd);
avail = fifo_write_avail(rsd->buffer);
avail = FIFO_WRITE_AVAIL(rsd->buffer);
if (avail == 0)
{
@ -209,7 +208,7 @@ static size_t rs_write_avail(void *data)
if (rsd->has_error)
return 0;
rsd_callback_lock(rsd->rd);
val = fifo_write_avail(rsd->buffer);
val = FIFO_WRITE_AVAIL(rsd->buffer);
rsd_callback_unlock(rsd->rd);
return val;
}

View File

@ -46,7 +46,7 @@ typedef struct sdl_audio
static void sdl_audio_cb(void *data, Uint8 *stream, int len)
{
sdl_audio_t *sdl = (sdl_audio_t*)data;
size_t avail = fifo_read_avail(sdl->buffer);
size_t avail = FIFO_READ_AVAIL(sdl->buffer);
size_t write_size = len > (int)avail ? avail : len;
fifo_read(sdl->buffer, stream, write_size);
@ -151,7 +151,7 @@ static ssize_t sdl_audio_write(void *data, const void *buf, size_t size)
size_t avail, write_amt;
SDL_LockAudio();
avail = fifo_write_avail(sdl->buffer);
avail = FIFO_WRITE_AVAIL(sdl->buffer);
write_amt = avail > size ? size : avail;
fifo_write(sdl->buffer, buf, write_amt);
SDL_UnlockAudio();
@ -166,7 +166,7 @@ static ssize_t sdl_audio_write(void *data, const void *buf, size_t size)
size_t avail;
SDL_LockAudio();
avail = fifo_write_avail(sdl->buffer);
avail = FIFO_WRITE_AVAIL(sdl->buffer);
if (avail == 0)
{

View File

@ -241,7 +241,7 @@ static ssize_t libnx_audren_audio_write(void *data,
if (aud->nonblock)
{
while(written < size)
while (written < size)
{
written += libnx_audren_audio_append(
aud, buf + written, size - written);
@ -251,7 +251,7 @@ static ssize_t libnx_audren_audio_write(void *data,
}
else
{
while(written < size)
while (written < size)
{
written += libnx_audren_audio_append(
aud, buf + written, size - written);

View File

@ -96,7 +96,7 @@ static void thread_job(void* data)
if (current_wavebuf)
{
mutexLock(&aud->fifo_lock);
available = aud->paused ? 0 : fifo_read_avail(aud->fifo);
available = aud->paused ? 0 : FIFO_READ_AVAIL(aud->fifo);
written_tmp = MIN(available, aud->buffer_size - current_size);
dstbuf = current_pool_ptr + current_size;
if (written_tmp > 0)
@ -295,7 +295,7 @@ static ssize_t libnx_audren_thread_audio_write(void *data,
if (aud->nonblock)
{
mutexLock(&aud->fifo_lock);
available = fifo_write_avail(aud->fifo);
available = FIFO_WRITE_AVAIL(aud->fifo);
written = MIN(available, size);
if (written > 0)
fifo_write(aud->fifo, buf, written);
@ -307,7 +307,7 @@ static ssize_t libnx_audren_thread_audio_write(void *data,
while (written < size && aud->running)
{
mutexLock(&aud->fifo_lock);
available = fifo_write_avail(aud->fifo);
available = FIFO_WRITE_AVAIL(aud->fifo);
if (available)
{
written_tmp = MIN(size - written, available);
@ -407,7 +407,7 @@ static size_t libnx_audren_thread_audio_write_avail(void *data)
return 0;
mutexLock(&aud->fifo_lock);
available = fifo_write_avail(aud->fifo);
available = FIFO_WRITE_AVAIL(aud->fifo);
mutexUnlock(&aud->fifo_lock);
return available;

View File

@ -107,7 +107,7 @@ static void mainLoop(void* data)
compat_mutex_lock(&swa->fifoLock);
avail = fifo_read_avail(swa->fifo);
avail = FIFO_READ_AVAIL(swa->fifo);
to_write = MIN(avail, buf_avail);
if (to_write > 0)
{
@ -349,7 +349,7 @@ static ssize_t switch_thread_audio_write(void *data, const void *buf, size_t siz
if (swa->nonblock)
{
compat_mutex_lock(&swa->fifoLock);
avail = fifo_write_avail(swa->fifo);
avail = FIFO_WRITE_AVAIL(swa->fifo);
written = MIN(avail, size);
if (written > 0)
fifo_write(swa->fifo, buf, written);
@ -361,7 +361,7 @@ static ssize_t switch_thread_audio_write(void *data, const void *buf, size_t siz
while (written < size && swa->running)
{
compat_mutex_lock(&swa->fifoLock);
avail = fifo_write_avail(swa->fifo);
avail = FIFO_WRITE_AVAIL(swa->fifo);
if (avail == 0)
{
compat_mutex_unlock(&swa->fifoLock);
@ -413,7 +413,7 @@ static size_t switch_thread_audio_write_avail(void *data)
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
compat_mutex_lock(&swa->fifoLock);
val = fifo_write_avail(swa->fifo);
val = FIFO_WRITE_AVAIL(swa->fifo);
compat_mutex_unlock(&swa->fifoLock);
return val;

View File

@ -632,7 +632,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
{
ssize_t written = -1;
UINT32 padding = 0;
size_t write_avail = fifo_write_avail(w->buffer);
size_t write_avail = FIFO_WRITE_AVAIL(w->buffer);
if (!write_avail)
{
@ -643,7 +643,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return -1;
read_avail = fifo_read_avail(w->buffer);
read_avail = FIFO_READ_AVAIL(w->buffer);
write_avail = w->engine_buffer_size - padding * w->frame_size;
written = read_avail < write_avail ? read_avail : write_avail;
if (written)
@ -651,7 +651,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
return -1;
}
write_avail = fifo_write_avail(w->buffer);
write_avail = FIFO_WRITE_AVAIL(w->buffer);
written = size < write_avail ? size : write_avail;
if (written)
fifo_write(w->buffer, data, written);
@ -685,20 +685,20 @@ static ssize_t wasapi_write_sh(wasapi_t *w, const void * data, size_t size)
static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t size)
{
size_t write_avail = 0;
ssize_t written = -1;
UINT32 padding = 0;
size_t write_avail = 0;
ssize_t written = -1;
UINT32 padding = 0;
if (w->buffer)
{
write_avail = fifo_write_avail(w->buffer);
write_avail = FIFO_WRITE_AVAIL(w->buffer);
if (!write_avail)
{
size_t read_avail = 0;
if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return -1;
read_avail = fifo_read_avail(w->buffer);
read_avail = FIFO_READ_AVAIL(w->buffer);
write_avail = w->engine_buffer_size - padding * w->frame_size;
written = read_avail < write_avail ? read_avail : write_avail;
if (written)
@ -706,7 +706,7 @@ static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t s
return -1;
}
write_avail = fifo_write_avail(w->buffer);
write_avail = FIFO_WRITE_AVAIL(w->buffer);
written = size < write_avail ? size : write_avail;
if (written)
fifo_write(w->buffer, data, written);
@ -731,7 +731,7 @@ static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t s
static ssize_t wasapi_write_ex(wasapi_t *w, const void * data, size_t size, DWORD ms)
{
ssize_t written = 0;
size_t write_avail = fifo_write_avail(w->buffer);
size_t write_avail = FIFO_WRITE_AVAIL(w->buffer);
if (!write_avail)
{
@ -890,7 +890,7 @@ static size_t wasapi_write_avail(void *wh)
UINT32 padding = 0;
if (w->buffer)
return fifo_write_avail(w->buffer);
return FIFO_WRITE_AVAIL(w->buffer);
if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return 0;

View File

@ -219,7 +219,7 @@ static ssize_t ax_audio_write(void* data, const void* buf, size_t size)
else if (count_avail < count)
{
/* Sync, wait for free memory */
while(AXIsMultiVoiceRunning(ax->mvoice) && (count_avail < count))
while (AXIsMultiVoiceRunning(ax->mvoice) && (count_avail < count))
{
OSYieldThread(); /* Gives threads with same priority time to run */
count_avail = (ax->written > AX_AUDIO_MAX_FREE ? 0 : (AX_AUDIO_MAX_FREE - ax->written));

View File

@ -765,13 +765,13 @@ static void rsnd_drain(rsound_t *rd)
delta /= 1000000;
/* Calculates the amount of data we have in our virtual buffer. Only used to calculate delay. */
slock_lock(rd->thread.mutex);
rd->bytes_in_buffer = (int)((int64_t)rd->total_written + (int64_t)fifo_read_avail(rd->fifo_buffer) - delta);
rd->bytes_in_buffer = (int)((int64_t)rd->total_written + (int64_t)FIFO_READ_AVAIL(rd->fifo_buffer) - delta);
slock_unlock(rd->thread.mutex);
}
else
{
slock_lock(rd->thread.mutex);
rd->bytes_in_buffer = fifo_read_avail(rd->fifo_buffer);
rd->bytes_in_buffer = FIFO_READ_AVAIL(rd->fifo_buffer);
slock_unlock(rd->thread.mutex);
}
}
@ -789,7 +789,7 @@ static size_t rsnd_fill_buffer(rsound_t *rd, const char *buf, size_t size)
return 0;
slock_lock(rd->thread.mutex);
if ( fifo_write_avail(rd->fifo_buffer) >= size )
if (FIFO_WRITE_AVAIL(rd->fifo_buffer) >= size)
{
slock_unlock(rd->thread.mutex);
break;
@ -886,7 +886,7 @@ static size_t rsnd_get_ptr(rsound_t *rd)
{
int ptr;
slock_lock(rd->thread.mutex);
ptr = fifo_read_avail(rd->fifo_buffer);
ptr = FIFO_READ_AVAIL(rd->fifo_buffer);
slock_unlock(rd->thread.mutex);
return ptr;
@ -1060,7 +1060,7 @@ static int rsnd_update_server_info(rsound_t *rd)
int delay = rsd_delay(rd);
int delta = (int)(client_ptr - serv_ptr);
slock_lock(rd->thread.mutex);
delta += fifo_read_avail(rd->fifo_buffer);
delta += FIFO_READ_AVAIL(rd->fifo_buffer);
slock_unlock(rd->thread.mutex);
RSD_DEBUG("[RSound] Delay: %d, Delta: %d.\n", delay, delta);
@ -1116,7 +1116,7 @@ static void rsnd_thread ( void * thread_data )
/* If the buffer is empty or we've stopped the stream, jump out of this for loop */
slock_lock(rd->thread.mutex);
if ( fifo_read_avail(rd->fifo_buffer) < rd->backend_info.chunk_size || !rd->thread_active )
if (FIFO_READ_AVAIL(rd->fifo_buffer) < rd->backend_info.chunk_size || !rd->thread_active)
{
slock_unlock(rd->thread.mutex);
break;
@ -1382,11 +1382,10 @@ int rsd_exec(rsound_t *rsound)
fcntl(rsound->conn.socket, F_SETFL, O_NONBLOCK);
#endif
// Flush the buffer
if ( fifo_read_avail(rsound->fifo_buffer) > 0 )
/* Flush the buffer */
if (FIFO_READ_AVAIL(rsound->fifo_buffer) > 0 )
{
char buffer[fifo_read_avail(rsound->fifo_buffer)];
char buffer[FIFO_READ_AVAIL(rsound->fifo_buffer)];
fifo_read(rsound->fifo_buffer, buffer, sizeof(buffer));
if ( rsnd_send_chunk(fd, buffer, sizeof(buffer), 1) != (ssize_t)sizeof(buffer) )
{

View File

@ -0,0 +1,78 @@
/* RetroArch - A frontend for libretro.
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BLUETOOTH_DRIVER__H
#define __BLUETOOTH_DRIVER__H
#include <stdint.h>
#include <boolean.h>
#include <retro_common_api.h>
#include <lists/string_list.h>
RETRO_BEGIN_DECLS
enum rarch_bluetooth_ctl_state
{
RARCH_BLUETOOTH_CTL_NONE = 0,
RARCH_BLUETOOTH_CTL_DESTROY,
RARCH_BLUETOOTH_CTL_DEINIT,
RARCH_BLUETOOTH_CTL_FIND_DRIVER,
RARCH_BLUETOOTH_CTL_INIT
};
typedef struct bluetooth_driver
{
void *(*init)(void);
void (*free)(void *data);
void (*scan)(void *data);
void (*get_devices)(void *data, struct string_list *list);
bool (*device_is_connected)(void *data, unsigned i);
void (*device_get_sublabel)(void *data, char *s, unsigned i, size_t len);
bool (*connect_device)(void *data, unsigned i);
const char *ident;
} bluetooth_driver_t;
extern bluetooth_driver_t bluetooth_bluetoothctl;
extern bluetooth_driver_t bluetooth_bluez;
/**
* config_get_bluetooth_driver_options:
*
* Get an enumerated list of all bluetooth driver names,
* separated by '|'.
*
* Returns: string listing of all bluetooth driver names,
* separated by '|'.
**/
const char* config_get_bluetooth_driver_options(void);
void driver_bluetooth_scan(void);
void driver_bluetooth_get_devices(struct string_list *list);
bool driver_bluetooth_device_is_connected(unsigned i);
void driver_bluetooth_device_get_sublabel(char *s, unsigned i, size_t len);
bool driver_bluetooth_connect_device(unsigned i);
bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data);
RETRO_END_DECLS
#endif

View File

@ -0,0 +1,215 @@
/* RetroArch - A frontend for libretro.
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <compat/strl.h>
#include <configuration.h>
#include "../bluetooth_driver.h"
#include "../../retroarch.h"
typedef struct
{
bool bluetoothctl_cache[256];
unsigned bluetoothctl_counter[256];
struct string_list* lines;
char command[256];
} bluetoothctl_t;
static void *bluetoothctl_init(void)
{
return calloc(1, sizeof(bluetoothctl_t));
}
static void bluetoothctl_free(void *data)
{
if (data)
free(data);
}
static void bluetoothctl_scan(void *data)
{
char line[512];
union string_list_elem_attr attr;
FILE *dev_file = NULL;
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
attr.i = 0;
if (btctl->lines)
free(btctl->lines);
btctl->lines = string_list_new();
pclose(popen("bluetoothctl -- power on", "r"));
pclose(popen("bluetoothctl --timeout 10 scan on", "r"));
runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);
dev_file = popen("bluetoothctl -- devices", "r");
while (fgets(line, 512, dev_file))
{
size_t len = strlen(line);
if (len > 0 && line[len-1] == '\n')
line[--len] = '\0';
string_list_append(btctl->lines, line, attr);
}
pclose(dev_file);
}
static void bluetoothctl_get_devices(void *data, struct string_list* devices)
{
unsigned i;
union string_list_elem_attr attr;
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
attr.i = 0;
if (!btctl->lines)
return;
for (i = 0; i < btctl->lines->size; i++)
{
char device[64];
const char *line = btctl->lines->elems[i].data;
/* bluetoothctl devices outputs lines of the format:
* $ bluetoothctl devices
* 'Device (mac address) (device name)'
*/
strlcpy(device, line+24, sizeof(device));
string_list_append(devices, device, attr);
}
}
static bool bluetoothctl_device_is_connected(void *data, unsigned i)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
char ln[512] = {0};
char device[18] = {0};
const char *line = btctl->lines->elems[i].data;
FILE *command_file = NULL;
if (btctl->bluetoothctl_counter[i] == 60)
{
static struct string_list* list = NULL;
btctl->bluetoothctl_counter[i] = 0;
list = string_split(line, " ");
if (!list)
return false;
if (list->size == 0)
{
string_list_free(list);
return false;
}
strlcpy(device, list->elems[1].data, sizeof(device));
string_list_free(list);
snprintf(btctl->command, sizeof(btctl->command), "\
bluetoothctl -- info %s | grep 'Connected: yes'",
device);
command_file = popen(btctl->command, "r");
while (fgets(ln, 512, command_file))
{
btctl->bluetoothctl_cache[i] = true;
return true;
}
pclose(command_file);
btctl->bluetoothctl_cache[i] = false;
}
else
{
btctl->bluetoothctl_counter[i]++;
return btctl->bluetoothctl_cache[i];
}
return false;
}
static bool bluetoothctl_connect_device(void *data, unsigned idx)
{
unsigned i;
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
char device[18] = {0};
const char *line = btctl->lines->elems[idx].data;
static struct string_list* list = NULL;
/* bluetoothctl devices outputs lines of the format:
* $ bluetoothctl devices
* 'Device (mac address) (device name)'
*/
list = string_split(line, " ");
if (!list)
return false;
if (list->size == 0)
{
string_list_free(list);
return false;
}
strlcpy(device, list->elems[1].data, sizeof(device));
string_list_free(list);
snprintf(btctl->command, sizeof(btctl->command), "\
bluetoothctl -- trust %s",
device);
pclose(popen(btctl->command, "r"));
snprintf(btctl->command, sizeof(btctl->command), "\
bluetoothctl -- pair %s",
device);
pclose(popen(btctl->command, "r"));
snprintf(btctl->command, sizeof(btctl->command), "\
bluetoothctl -- connect %s",
device);
pclose(popen(btctl->command, "r"));
btctl->bluetoothctl_counter[idx] = 0;
return true;
}
static void bluetoothctl_device_get_sublabel(
void *data, char *s, unsigned i, size_t len)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
/* bluetoothctl devices outputs lines of the format:
* $ bluetoothctl devices
* 'Device (mac address) (device name)'
*/
const char *line = btctl->lines->elems[i].data;
strlcpy(s, line+7, 18);
}
bluetooth_driver_t bluetooth_bluetoothctl = {
bluetoothctl_init,
bluetoothctl_free,
bluetoothctl_scan,
bluetoothctl_get_devices,
bluetoothctl_device_is_connected,
bluetoothctl_device_get_sublabel,
bluetoothctl_connect_device,
"bluetoothctl",
};

616
bluetooth/drivers/bluez.c Normal file
View File

@ -0,0 +1,616 @@
/* RetroArch - A frontend for libretro.
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <dbus/dbus.h>
#include <compat/strl.h>
#include <configuration.h>
#include <retro_timers.h>
#include <string/stdstring.h>
#include "../bluetooth_driver.h"
#include "../../retroarch.h"
typedef struct
{
/* object path. usually looks like /org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF
* technically unlimited, but should be enough */
char path[128];
/* for display purposes 64 bytes should be enough */
char name[64];
/* MAC address, 17 bytes */
char address[18];
/* freedesktop.org icon name
* See bluez/src/dbus-common.c
* Can be NULL */
char icon[64];
int connected;
int paired;
int trusted;
} device_info_t;
#define VECTOR_LIST_TYPE device_info_t
#define VECTOR_LIST_NAME device_info
#include "../../libretro-common/lists/vector_list.c"
#undef VECTOR_LIST_TYPE
#undef VECTOR_LIST_NAME
typedef struct
{
struct device_info_vector_list *devices;
char adapter[256];
DBusConnection* dbus_connection;
bool bluez_cache[256];
int bluez_cache_counter[256];
} bluez_t;
static void *bluez_init (void)
{
return calloc(1, sizeof(bluez_t));
}
static void bluez_free (void *data)
{
if (data)
free(data);
}
static int
set_bool_property (
bluez_t *bluez,
const char *path,
const char *arg_adapter,
const char *arg_property,
int value)
{
DBusError err;
DBusMessage *message, *reply;
DBusMessageIter req_iter, req_subiter;
dbus_error_init(&err);
message = dbus_message_new_method_call(
"org.bluez",
path,
"org.freedesktop.DBus.Properties",
"Set"
);
if (!message)
return 1;
dbus_message_iter_init_append(message, &req_iter);
if (!dbus_message_iter_append_basic(
&req_iter, DBUS_TYPE_STRING, &arg_adapter))
goto fault;
if (!dbus_message_iter_append_basic(
&req_iter, DBUS_TYPE_STRING, &arg_property))
goto fault;
if (!dbus_message_iter_open_container(
&req_iter, DBUS_TYPE_VARIANT,
DBUS_TYPE_BOOLEAN_AS_STRING, &req_subiter))
goto fault;
if (!dbus_message_iter_append_basic(
&req_subiter, DBUS_TYPE_BOOLEAN, &value))
goto fault;
if (!dbus_message_iter_close_container(
&req_iter, &req_subiter))
goto fault;
reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
message, 1000, &err);
if (!reply)
goto fault;
dbus_message_unref(reply);
dbus_message_unref(message);
return 0;
fault:
dbus_message_iter_abandon_container_if_open(&req_iter, &req_subiter);
dbus_message_unref(message);
return 1;
}
static int get_bool_property(
bluez_t *bluez,
const char *path,
const char *arg_adapter,
const char *arg_property,
int *value)
{
DBusMessage *message, *reply;
DBusError err;
DBusMessageIter root_iter, variant_iter;
dbus_error_init(&err);
message = dbus_message_new_method_call( "org.bluez", path,
"org.freedesktop.DBus.Properties", "Get");
if (!message)
return 1;
if (!dbus_message_append_args(message,
DBUS_TYPE_STRING, &arg_adapter,
DBUS_TYPE_STRING, &arg_property,
DBUS_TYPE_INVALID))
return 1;
reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
message, 1000, &err);
dbus_message_unref(message);
if (!reply)
return 1;
if (!dbus_message_iter_init(reply, &root_iter))
return 1;
if (DBUS_TYPE_VARIANT != dbus_message_iter_get_arg_type(&root_iter))
return 1;
dbus_message_iter_recurse(&root_iter, &variant_iter);
dbus_message_iter_get_basic(&variant_iter, value);
dbus_message_unref(reply);
return 0;
}
static int adapter_discovery (bluez_t *bluez, const char *method)
{
DBusMessage *message = dbus_message_new_method_call(
"org.bluez", bluez->adapter,
"org.bluez.Adapter1", method);
if (!message)
return 1;
if (!dbus_connection_send(bluez->dbus_connection, message, NULL))
return 1;
dbus_connection_flush(bluez->dbus_connection);
dbus_message_unref(message);
return 0;
}
static int get_managed_objects (bluez_t *bluez, DBusMessage **reply)
{
DBusMessage *message;
DBusError err;
dbus_error_init(&err);
message = dbus_message_new_method_call("org.bluez", "/",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
if (!message)
return 1;
*reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
message, -1, &err);
/* if (!reply) is done by the caller in this one */
dbus_message_unref(message);
return 0;
}
static int device_method (bluez_t *bluez, const char *path, const char *method)
{
DBusMessage *message, *reply;
DBusError err;
dbus_error_init(&err);
message = dbus_message_new_method_call( "org.bluez", path,
"org.bluez.Device1", method);
if (!message)
return 1;
reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
message, 10000, &err);
if (!reply)
return 1;
dbus_connection_flush(bluez->dbus_connection);
dbus_message_unref(message);
return 0;
}
static int get_default_adapter(bluez_t *bluez, DBusMessage *reply)
{
/* "...an application would discover the available adapters by
* performing a ObjectManager.GetManagedObjects call and look for any
* returned objects with an org.bluez.Adapter1 interface.
* The concept of a default adapter was always a bit fuzzy and the
* value couldt be changed, so if applications need something like it
* they could e.g. just pick the first adapter they encounter in the
* GetManagedObjects reply."
* -- http://www.bluez.org/bluez-5-api-introduction-and-porting-guide/
*/
DBusMessageIter root_iter;
DBusMessageIter dict_1_iter, dict_2_iter;
DBusMessageIter array_1_iter, array_2_iter;
char *obj_path, *interface_name;
/* a{oa{sa{sv}}} */
if (!dbus_message_iter_init(reply, &root_iter))
return 1;
/* a */
if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&root_iter))
return 1;
dbus_message_iter_recurse(&root_iter, &array_1_iter);
do
{
/* a{...} */
if (DBUS_TYPE_DICT_ENTRY != dbus_message_iter_get_arg_type(&array_1_iter))
return 1;
dbus_message_iter_recurse(&array_1_iter, &dict_1_iter);
/* a{o...} */
if (DBUS_TYPE_OBJECT_PATH != dbus_message_iter_get_arg_type(&dict_1_iter))
return 1;
dbus_message_iter_get_basic(&dict_1_iter, &obj_path);
if (!dbus_message_iter_next(&dict_1_iter))
return 1;
/* a{oa} */
if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&dict_1_iter))
return 1;
dbus_message_iter_recurse(&dict_1_iter, &array_2_iter);
do
{
/* empty array? */
if (DBUS_TYPE_INVALID ==
dbus_message_iter_get_arg_type(&array_2_iter))
continue;
/* a{oa{...}} */
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_2_iter))
return 1;
dbus_message_iter_recurse(&array_2_iter, &dict_2_iter);
/* a{oa{s...}} */
if (DBUS_TYPE_STRING !=
dbus_message_iter_get_arg_type(&dict_2_iter))
return 1;
dbus_message_iter_get_basic(&dict_2_iter, &interface_name);
if (string_is_equal(interface_name, "org.bluez.Adapter1"))
{
strlcpy(bluez->adapter, obj_path, 256);
return 0;
}
} while (dbus_message_iter_next(&array_2_iter));
} while (dbus_message_iter_next(&array_1_iter));
/* Couldn't find an adapter */
return 1;
}
static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
{
device_info_t device;
DBusMessageIter root_iter;
DBusMessageIter dict_1_iter, dict_2_iter, dict_3_iter;
DBusMessageIter array_1_iter, array_2_iter, array_3_iter;
DBusMessageIter variant_iter;
char *obj_path, *interface_name, *interface_property_name;
char *found_device_address, *found_device_name, *found_device_icon;
/* a{oa{sa{sv}}} */
if (!dbus_message_iter_init(reply, &root_iter))
return 1;
/* a */
if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&root_iter))
return 1;
dbus_message_iter_recurse(&root_iter, &array_1_iter);
do
{
/* a{...} */
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_1_iter))
return 1;
dbus_message_iter_recurse(&array_1_iter, &dict_1_iter);
/* a{o...} */
if (DBUS_TYPE_OBJECT_PATH !=
dbus_message_iter_get_arg_type(&dict_1_iter))
return 1;
dbus_message_iter_get_basic(&dict_1_iter, &obj_path);
if (!dbus_message_iter_next(&dict_1_iter))
return 1;
/* a{oa} */
if (DBUS_TYPE_ARRAY !=
dbus_message_iter_get_arg_type(&dict_1_iter))
return 1;
dbus_message_iter_recurse(&dict_1_iter, &array_2_iter);
do
{
/* empty array? */
if (DBUS_TYPE_INVALID ==
dbus_message_iter_get_arg_type(&array_2_iter))
continue;
/* a{oa{...}} */
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_2_iter))
return 1;
dbus_message_iter_recurse(&array_2_iter, &dict_2_iter);
/* a{oa{s...}} */
if (DBUS_TYPE_STRING !=
dbus_message_iter_get_arg_type(&dict_2_iter))
return 1;
dbus_message_iter_get_basic(&dict_2_iter, &interface_name);
if (!string_is_equal(interface_name, "org.bluez.Device1"))
continue;
memset(&device, 0, sizeof(device));
strlcpy(device.path, obj_path, 128);
if (!dbus_message_iter_next(&dict_2_iter))
return 1;
/* a{oa{sa}} */
if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&dict_2_iter))
return 1;
dbus_message_iter_recurse(&dict_2_iter, &array_3_iter);
do {
/* empty array? */
if (DBUS_TYPE_INVALID ==
dbus_message_iter_get_arg_type(&array_3_iter))
continue;
/* a{oa{sa{...}}} */
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_3_iter))
return 1;
dbus_message_iter_recurse(&array_3_iter, &dict_3_iter);
/* a{oa{sa{s...}}} */
if (DBUS_TYPE_STRING !=
dbus_message_iter_get_arg_type(&dict_3_iter))
return 1;
dbus_message_iter_get_basic(&dict_3_iter,
&interface_property_name);
if (!dbus_message_iter_next(&dict_3_iter))
return 1;
/* a{oa{sa{sv}}} */
if (DBUS_TYPE_VARIANT !=
dbus_message_iter_get_arg_type(&dict_3_iter))
return 1;
/* Below, "Alias" property is used instead of "Name".
* "This value ("Name") is only present for
* completeness. It is better to always use
* the Alias property when displaying the
* devices name."
* -- bluez/doc/device-api.txt
*/
/* DBUS_TYPE_VARIANT is a container type */
dbus_message_iter_recurse(&dict_3_iter, &variant_iter);
if (string_is_equal(interface_property_name, "Address"))
{
dbus_message_iter_get_basic(&variant_iter,
&found_device_address);
strlcpy(device.address, found_device_address, 18);
}
else if (string_is_equal(interface_property_name, "Alias"))
{
dbus_message_iter_get_basic(&variant_iter,
&found_device_name);
strlcpy(device.name, found_device_name, 64);
}
else if (string_is_equal(interface_property_name, "Icon"))
{
dbus_message_iter_get_basic(&variant_iter,
&found_device_icon);
strlcpy(device.icon, found_device_icon, 64);
}
else if (string_is_equal(interface_property_name, "Connected"))
{
dbus_message_iter_get_basic(&variant_iter,
&device.connected);
}
else if (string_is_equal(interface_property_name, "Paired"))
{
dbus_message_iter_get_basic(&variant_iter,
&device.paired);
}
else if (string_is_equal(interface_property_name, "Trusted"))
{
dbus_message_iter_get_basic(&variant_iter,
&device.trusted);
}
} while (dbus_message_iter_next(&array_3_iter));
if (!device_info_vector_list_append(bluez->devices, device))
return 1;
} while (dbus_message_iter_next(&array_2_iter));
} while (dbus_message_iter_next(&array_1_iter));
return 0;
}
static void bluez_dbus_connect(bluez_t *bluez)
{
DBusError err;
dbus_error_init(&err);
bluez->dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
}
static void bluez_dbus_disconnect(bluez_t *bluez)
{
if (!bluez->dbus_connection)
return;
dbus_connection_close(bluez->dbus_connection);
dbus_connection_unref(bluez->dbus_connection);
bluez->dbus_connection = NULL;
}
static void bluez_scan(void *data)
{
DBusError err;
DBusMessage *reply;
bluez_t *bluez = (bluez_t*)data;
bluez_dbus_connect(bluez);
if (get_managed_objects(bluez, &reply))
return;
if (!reply)
return;
/* Get default adapter */
if (get_default_adapter(bluez, reply))
return;
dbus_message_unref(reply);
/* Power device on */
if (set_bool_property(bluez, bluez->adapter,
"org.bluez.Adapter1", "Powered", 1))
return;
/* Start discovery */
if (adapter_discovery(bluez, "StartDiscovery"))
return;
retro_sleep(10000);
/* Stop discovery */
if (adapter_discovery(bluez, "StopDiscovery"))
return;
/* Get scanned devices */
if (get_managed_objects(bluez, &reply))
return;
if (!reply)
return;
if (bluez->devices)
device_info_vector_list_free(bluez->devices);
bluez->devices = device_info_vector_list_new();
read_scanned_devices(bluez, reply);
dbus_message_unref(reply);
bluez_dbus_disconnect(bluez);
}
static void bluez_get_devices(void *data,
struct string_list* devices_string_list)
{
unsigned i;
union string_list_elem_attr attr;
bluez_t *bluez = (bluez_t*)data;
attr.i = 0;
if (!bluez->devices)
return;
for (i = 0; i < bluez->devices->count; i++)
{
char device[64];
strlcpy(device, bluez->devices->data[i].name, sizeof(device));
string_list_append(devices_string_list, device, attr);
}
}
static bool bluez_device_is_connected(void *data, unsigned i)
{
int value;
bluez_t *bluez = (bluez_t*)data;
if (bluez->bluez_cache_counter[i] == 60)
{
bluez->bluez_cache_counter[i] = 0;
bluez_dbus_connect(bluez);
/* Device disappeared */
if (get_bool_property(bluez, bluez->devices->data[i].path,
"org.bluez.Device1", "Connected", &value))
value = false;
bluez_dbus_disconnect(bluez);
bluez->bluez_cache[i] = value;
return value;
}
bluez->bluez_cache_counter[i]++;
return bluez->bluez_cache[i];
}
static void bluez_device_get_sublabel(
void *data, char *s, unsigned i, size_t len)
{
bluez_t *bluez = (bluez_t*)data;
strlcpy(s, bluez->devices->data[i].address, len);
}
static bool bluez_connect_device(void *data, unsigned i)
{
bluez_t *bluez = (bluez_t*)data;
bluez_dbus_connect(bluez);
/* Trust the device */
if (set_bool_property(bluez, bluez->devices->data[i].path,
"org.bluez.Device1", "Trusted", 1))
return false;
/* Pair the device */
device_method(bluez, bluez->devices->data[i].path, "Pair");
/* Can be "Already Exists" */
/* Connect the device */
if (device_method(bluez, bluez->devices->data[i].path, "Connect"))
return false;
bluez_dbus_disconnect(bluez);
bluez->bluez_cache_counter[i] = 0;
return true;
}
bluetooth_driver_t bluetooth_bluez = {
bluez_init,
bluez_free,
bluez_scan,
bluez_get_devices,
bluez_device_is_connected,
bluez_device_get_sublabel,
bluez_connect_device,
"bluez",
};

View File

@ -145,8 +145,8 @@ typedef struct rcheevos_async_io_request
int attempt_count;
char type;
char hardcore;
char* success_message;
char* failure_message;
const char* success_message;
const char* failure_message;
char user_agent[256];
} rcheevos_async_io_request;
@ -443,7 +443,7 @@ static retro_time_t rcheevos_async_send_rich_presence(
{
if (settings->bools.discord_enable
&& discord_is_ready())
discord_update(DISCORD_PRESENCE_RETROACHIEVEMENTS, false);
discord_update(DISCORD_PRESENCE_RETROACHIEVEMENTS);
}
#endif
@ -521,7 +521,8 @@ static void rcheevos_async_task_callback(
case CHEEVOS_ASYNC_AWARD_ACHIEVEMENT:
/* ignore already unlocked */
if (string_starts_with(buffer, "User already has "))
if (string_starts_with_size(buffer, "User already has ",
STRLEN_CONST("User already has ")))
break;
/* fallthrough to default */
@ -820,12 +821,16 @@ static void rcheevos_async_award_achievement(rcheevos_async_io_request* request)
rcheevos_log_url("rc_url_award_cheevo", buffer);
task_push_http_transfer_with_user_agent(buffer, true, NULL, request->user_agent, rcheevos_async_task_callback, request);
#ifdef HAVE_AUDIOMIXER
if (settings->bools.cheevos_unlock_sound_enable)
audio_driver_mixer_play_menu_sound(AUDIO_MIXER_SYSTEM_SLOT_ACHIEVEMENT_UNLOCK);
#endif
}
static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode)
{
char buffer[256];
settings_t *settings = config_get_ptr();
buffer[0] = 0;
CHEEVOS_LOG(RCHEEVOS_TAG "awarding cheevo %u: %s (%s)\n",
@ -865,24 +870,29 @@ static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode)
rcheevos_async_award_achievement(request);
}
/* Take a screenshot of the achievement. */
if (settings && settings->bools.cheevos_auto_screenshot)
#ifdef HAVE_SCREENSHOTS
{
char shotname[8192];
settings_t *settings = config_get_ptr();
/* Take a screenshot of the achievement. */
if (settings && settings->bools.cheevos_auto_screenshot)
{
char shotname[8192];
snprintf(shotname, sizeof(shotname), "%s/%s-cheevo-%u",
settings->paths.directory_screenshot,
path_basename(path_get(RARCH_PATH_BASENAME)),
cheevo->info->id);
shotname[sizeof(shotname) - 1] = '\0';
snprintf(shotname, sizeof(shotname), "%s/%s-cheevo-%u",
settings->paths.directory_screenshot,
path_basename(path_get(RARCH_PATH_BASENAME)),
cheevo->info->id);
shotname[sizeof(shotname) - 1] = '\0';
if (take_screenshot(settings->paths.directory_screenshot,
shotname, true,
video_driver_cached_frame_has_valid_framebuffer(), false, true))
CHEEVOS_LOG(RCHEEVOS_TAG "got a screenshot for cheevo %u\n", cheevo->info->id);
else
CHEEVOS_LOG(RCHEEVOS_TAG "failed to get screenshot for cheevo %u\n", cheevo->info->id);
if (take_screenshot(settings->paths.directory_screenshot,
shotname, true,
video_driver_cached_frame_has_valid_framebuffer(), false, true))
CHEEVOS_LOG(RCHEEVOS_TAG "got a screenshot for cheevo %u\n", cheevo->info->id);
else
CHEEVOS_LOG(RCHEEVOS_TAG "failed to get screenshot for cheevo %u\n", cheevo->info->id);
}
}
#endif
}
static int rcheevos_has_indirect_memref(const rc_memref_value_t* memrefs)
@ -994,14 +1004,6 @@ static void rcheevos_lboard_submit(rcheevos_lboard_t* lboard)
/* Deactivate the leaderboard. */
lboard->active = 0;
/* Failsafe for improper leaderboards. */
if (lboard->last_value == 0)
{
CHEEVOS_ERR(RCHEEVOS_TAG "Leaderboard %s tried to submit 0\n", lboard->info->title);
runloop_msg_queue_push("Leaderboard attempt cancelled!", 0, 2 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
return;
}
/* Show the OSD message. */
rc_format_value(value, sizeof(value), lboard->last_value, lboard->format);
@ -1150,16 +1152,23 @@ void rcheevos_get_achievement_state(unsigned index, char *buffer, size_t buffer_
{
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNSUPPORTED_ENTRY;
}
else if (!(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE))
{
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY_HARDCORE;
}
else if (!(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE))
{
/* if in hardcore mode, track progress towards hardcore unlock */
const settings_t* settings = config_get_ptr();
const bool hardcore = settings->bools.cheevos_hardcore_mode_enable && !rcheevos_hardcore_paused;
check_measured = hardcore;
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY;
}
else
{
settings_t* settings = config_get_ptr();
bool hardcore = settings->bools.cheevos_hardcore_mode_enable && !rcheevos_hardcore_paused;
if (hardcore && !(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE))
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY_HARDCORE;
else if (!hardcore && !(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE))
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY;
else /* Use either "Locked" for core or "Unofficial" for unofficial as set above */
check_measured = true;
/* Use either "Locked" for core or "Unofficial" for unofficial as set above and track progress */
check_measured = true;
}
strlcpy(buffer, msg_hash_to_str(enum_idx), buffer_size);
@ -1548,7 +1557,7 @@ static int rcheevos_iterate(rcheevos_coro_t* coro)
CORO_STOP();
/* iterate over the possible hashes for the file being loaded */
rc_hash_initialize_iterator(&coro->iterator, coro->path, NULL, 0);
rc_hash_initialize_iterator(&coro->iterator, coro->path, (uint8_t*)coro->data, coro->len);
#ifdef CHEEVOS_TIME_HASH
start = cpu_features_get_time_usec();
#endif

View File

@ -291,7 +291,7 @@ typedef struct
static char* rcheevos_unescape_string(const char* string, size_t length)
{
const char* end = string + length;
char* buffer = (char*)malloc(length + 1);
char* buffer = (char*)malloc(length + 1);
char* buffer_it = buffer;
if (buffer == NULL)
@ -329,18 +329,19 @@ static char* rcheevos_unescape_string(const char* string, size_t length)
{
char temp[5];
string += 2;
string += 2;
memcpy(temp, string, 4);
temp[4] = '\0';
utf16[j] = string_hex_to_unsigned(temp);
string += 4;
temp[4] = '\0';
utf16[j] = string_hex_to_unsigned(temp);
string += 4;
}
utf16[j] = 0;
if (utf16_to_char_string(utf16, utf8, sizeof(utf8)))
{
memcpy(buffer_it, utf8, strlen(utf8));
buffer_it += strlen(utf8);
size_t utf8_len = strlen(utf8);
memcpy(buffer_it, utf8, utf8_len);
buffer_it += utf8_len;
}
}
break;

View File

@ -53,48 +53,6 @@
#define DEFAULT_ASPECT_RATIO -1.0f
#endif
#if defined(ANDROID)
#define DEFAULT_MAX_PADS 8
#define ANDROID_KEYBOARD_PORT DEFAULT_MAX_PADS
#elif defined(_3DS)
#define DEFAULT_MAX_PADS 1
#elif defined(SWITCH) || defined(HAVE_LIBNX)
#define DEFAULT_MAX_PADS 8
#elif defined(WIIU)
#ifdef WIIU_HID
#define DEFAULT_MAX_PADS 16
#else
#define DEFAULT_MAX_PADS 5
#endif
#elif defined(DJGPP)
#define DEFAULT_MAX_PADS 1
#define DOS_KEYBOARD_PORT DEFAULT_MAX_PADS
#elif defined(XENON)
#define DEFAULT_MAX_PADS 4
#elif defined(VITA) || defined(SN_TARGET_PSP2)
#define DEFAULT_MAX_PADS 4
#elif defined(PSP)
#define DEFAULT_MAX_PADS 1
#elif defined(PS2)
#define DEFAULT_MAX_PADS 2
#elif defined(GEKKO) || defined(HW_RVL)
#define DEFAULT_MAX_PADS 4
#elif defined(__linux__) || (defined(BSD) && !defined(__MACH__))
#define DEFAULT_MAX_PADS 8
#elif defined(__QNX__)
#define DEFAULT_MAX_PADS 8
#elif defined(__CELLOS_LV2__)
#define DEFAULT_MAX_PADS 7
#elif defined(_XBOX)
#define DEFAULT_MAX_PADS 4
#elif defined(HAVE_XINPUT) && !defined(HAVE_DINPUT)
#define DEFAULT_MAX_PADS 4
#elif defined(DINGUX)
#define DEFAULT_MAX_PADS 2
#else
#define DEFAULT_MAX_PADS 16
#endif
#if defined(GEKKO)
#define DEFAULT_MOUSE_SCALE 1
#endif
@ -258,6 +216,18 @@
#endif
#define DEFAULT_CHECK_FIRMWARE_BEFORE_LOADING false
/* Specifies whether to 'reload' (fork and quit)
* RetroArch when launching content with the
* currently loaded core
* > Only relevant on platforms without dynamic core
* loading support
* > Setting this to 'false' will decrease loading
* times when required core is already running,
* but may cause stability issues (if core misbehaves) */
#ifndef HAVE_DYNAMIC
#define DEFAULT_ALWAYS_RELOAD_CORE_ON_RUN_CONTENT true
#endif
/* Forcibly disable composition.
* Only valid on Windows Vista/7/8 for now. */
#define DEFAULT_DISABLE_COMPOSITION false
@ -645,6 +615,8 @@ static const unsigned input_backtouch_enable = false;
static const unsigned input_backtouch_toggle = false;
#endif
#define DEFAULT_OVERLAY_ENABLE_AUTOPREFERRED true
#define DEFAULT_SHOW_PHYSICAL_INPUTS true
#define DEFAULT_ALL_USERS_CONTROL_MENU false
@ -755,6 +727,40 @@ static const bool audio_enable_menu_bgm = false;
#define DEFAULT_MENU_ENABLE_WIDGETS false
#endif
/* Display an animation when loading content
* > Currently implemented only as a widget */
#define DEFAULT_MENU_SHOW_LOAD_CONTENT_ANIMATION DEFAULT_MENU_ENABLE_WIDGETS
/* Display a notification when successfully
* connecting/disconnecting an autoconfigured
* controller
* > Disabled by default on the Switch */
#if defined(HAVE_LIBNX) && defined(HAVE_GFX_WIDGETS)
#define DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG false
#else
#define DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG true
#endif
/* Display a notification when cheats are being
* applied */
#define DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED true
/* Display a notification when loading an
* input remap file */
#define DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD true
/* Display a notification when loading a
* configuration override file */
#define DEFAULT_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD true
/* Display a notification when automatically restoring
* at launch the last used disk of multi-disk content */
#define DEFAULT_NOTIFICATION_SHOW_SET_INITIAL_DISK true
/* Display a notification when fast forwarding
* content */
#define DEFAULT_NOTIFICATION_SHOW_FAST_FORWARD true
/* Output samplerate. */
#ifdef GEKKO
#define DEFAULT_OUTPUT_RATE 32000
@ -1286,4 +1292,18 @@ static const bool enable_device_vibration = false;
#define DEFAULT_AI_SERVICE_URL "http://localhost:4404/"
#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
#define DEFAULT_BUILTIN_MEDIAPLAYER_ENABLE true
#else
#define DEFAULT_BUILTIN_MEDIAPLAYER_ENABLE false
#endif
#if defined(HAVE_IMAGEVIEWER)
#define DEFAULT_BUILTIN_IMAGEVIEWER_ENABLE true
#else
#define DEFAULT_BUILTIN_IMAGEVIEWER_ENABLE false
#endif
#define DEFAULT_FILTER_BY_CURRENT_CORE false
#endif

View File

@ -2,7 +2,7 @@
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2014-2017 - Jean-André Santoni
* Copyright (C) 2015-2019 - Andrés Suárez
* Copyright (C) 2015-2019 - Andrés Suárez (input remapping + other things)
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
@ -271,9 +271,16 @@ enum camera_driver_enum
CAMERA_NULL
};
enum bluetooth_driver_enum
{
BLUETOOTH_BLUETOOTHCTL = CAMERA_NULL + 1,
BLUETOOTH_BLUEZ,
BLUETOOTH_NULL
};
enum wifi_driver_enum
{
WIFI_CONNMANCTL = CAMERA_NULL + 1,
WIFI_CONNMANCTL = BLUETOOTH_NULL + 1,
WIFI_NULL
};
@ -559,6 +566,16 @@ static const enum camera_driver_enum CAMERA_DEFAULT_DRIVER = CAMERA_ANDROID;
static const enum camera_driver_enum CAMERA_DEFAULT_DRIVER = CAMERA_NULL;
#endif
#if defined(HAVE_BLUETOOTH)
# if defined(HAVE_DBUS)
static const enum bluetooth_driver_enum BLUETOOTH_DEFAULT_DRIVER = BLUETOOTH_BLUEZ;
# else
static const enum bluetooth_driver_enum BLUETOOTH_DEFAULT_DRIVER = BLUETOOTH_BLUETOOTHCTL;
# endif
#else
static const enum bluetooth_driver_enum BLUETOOTH_DEFAULT_DRIVER = BLUETOOTH_NULL;
#endif
#if defined(HAVE_LAKKA)
static const enum wifi_driver_enum WIFI_DEFAULT_DRIVER = WIFI_CONNMANCTL;
#else
@ -629,6 +646,10 @@ static void config_parse_file(global_t *global);
struct defaults g_defaults;
/* TODO/FIXME - static public global variables */
static unsigned old_analog_dpad_mode[MAX_USERS];
static unsigned old_libretro_device[MAX_USERS];
/**
* config_get_default_audio:
*
@ -1010,6 +1031,30 @@ const char *config_get_default_camera(void)
return "null";
}
/**
* config_get_default_bluetooth:
*
* Gets default bluetooth driver.
*
* Returns: Default bluetooth driver.
**/
const char *config_get_default_bluetooth(void)
{
enum bluetooth_driver_enum default_driver = BLUETOOTH_DEFAULT_DRIVER;
switch (default_driver)
{
case BLUETOOTH_BLUETOOTHCTL:
return "bluetoothctl";
case BLUETOOTH_BLUEZ:
return "bluez";
case BLUETOOTH_NULL:
break;
}
return "null";
}
/**
* config_get_default_wifi:
*
@ -1144,6 +1189,7 @@ static struct config_array_setting *populate_settings_array(settings_t *settings
SETTING_ARRAY("video_driver", settings->arrays.video_driver, false, NULL, true);
SETTING_ARRAY("record_driver", settings->arrays.record_driver, false, NULL, true);
SETTING_ARRAY("camera_driver", settings->arrays.camera_driver, false, NULL, true);
SETTING_ARRAY("bluetooth_driver", settings->arrays.bluetooth_driver, false, NULL, true);
SETTING_ARRAY("wifi_driver", settings->arrays.wifi_driver, false, NULL, true);
SETTING_ARRAY("location_driver", settings->arrays.location_driver,false, NULL, true);
#ifdef HAVE_MENU
@ -1376,8 +1422,11 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("input_descriptor_hide_unbound", &settings->bools.input_descriptor_hide_unbound, true, input_descriptor_hide_unbound, false);
SETTING_BOOL("load_dummy_on_core_shutdown", &settings->bools.load_dummy_on_core_shutdown, true, DEFAULT_LOAD_DUMMY_ON_CORE_SHUTDOWN, false);
SETTING_BOOL("check_firmware_before_loading", &settings->bools.check_firmware_before_loading, true, DEFAULT_CHECK_FIRMWARE_BEFORE_LOADING, false);
SETTING_BOOL("builtin_mediaplayer_enable", &settings->bools.multimedia_builtin_mediaplayer_enable, false, false /* TODO */, false);
SETTING_BOOL("builtin_imageviewer_enable", &settings->bools.multimedia_builtin_imageviewer_enable, true, true, false);
#ifndef HAVE_DYNAMIC
SETTING_BOOL("always_reload_core_on_run_content", &settings->bools.always_reload_core_on_run_content, true, DEFAULT_ALWAYS_RELOAD_CORE_ON_RUN_CONTENT, false);
#endif
SETTING_BOOL("builtin_mediaplayer_enable", &settings->bools.multimedia_builtin_mediaplayer_enable, true, DEFAULT_BUILTIN_MEDIAPLAYER_ENABLE, false);
SETTING_BOOL("builtin_imageviewer_enable", &settings->bools.multimedia_builtin_imageviewer_enable, true, DEFAULT_BUILTIN_IMAGEVIEWER_ENABLE, false);
SETTING_BOOL("fps_show", &settings->bools.video_fps_show, true, DEFAULT_FPS_SHOW, false);
SETTING_BOOL("statistics_show", &settings->bools.video_statistics_show, true, DEFAULT_STATISTICS_SHOW, false);
SETTING_BOOL("framecount_show", &settings->bools.video_framecount_show, true, DEFAULT_FRAMECOUNT_SHOW, false);
@ -1423,6 +1472,13 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("core_set_supports_no_game_enable", &settings->bools.set_supports_no_game_enable, true, true, false);
SETTING_BOOL("audio_enable", &settings->bools.audio_enable, true, DEFAULT_AUDIO_ENABLE, false);
SETTING_BOOL("menu_enable_widgets", &settings->bools.menu_enable_widgets, true, DEFAULT_MENU_ENABLE_WIDGETS, false);
SETTING_BOOL("menu_show_load_content_animation", &settings->bools.menu_show_load_content_animation, true, DEFAULT_MENU_SHOW_LOAD_CONTENT_ANIMATION, false);
SETTING_BOOL("notification_show_autoconfig", &settings->bools.notification_show_autoconfig, true, DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG, false);
SETTING_BOOL("notification_show_cheats_applied", &settings->bools.notification_show_cheats_applied, true, DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED, false);
SETTING_BOOL("notification_show_remap_load", &settings->bools.notification_show_remap_load, true, DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD, false);
SETTING_BOOL("notification_show_config_override_load", &settings->bools.notification_show_config_override_load, true, DEFAULT_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD, false);
SETTING_BOOL("notification_show_set_initial_disk", &settings->bools.notification_show_set_initial_disk, true, DEFAULT_NOTIFICATION_SHOW_SET_INITIAL_DISK, false);
SETTING_BOOL("notification_show_fast_forward", &settings->bools.notification_show_fast_forward, true, DEFAULT_NOTIFICATION_SHOW_FAST_FORWARD, false);
SETTING_BOOL("menu_widget_scale_auto", &settings->bools.menu_widget_scale_auto, true, DEFAULT_MENU_WIDGET_SCALE_AUTO, false);
SETTING_BOOL("audio_enable_menu", &settings->bools.audio_enable_menu, true, audio_enable_menu, false);
SETTING_BOOL("audio_enable_menu_ok", &settings->bools.audio_enable_menu_ok, true, audio_enable_menu_ok, false);
@ -1554,7 +1610,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("menu_show_online_updater", &settings->bools.menu_show_online_updater, true, menu_show_online_updater, false);
SETTING_BOOL("menu_show_core_updater", &settings->bools.menu_show_core_updater, true, menu_show_core_updater, false);
SETTING_BOOL("menu_show_legacy_thumbnail_updater", &settings->bools.menu_show_legacy_thumbnail_updater, true, menu_show_legacy_thumbnail_updater, false);
SETTING_BOOL("filter_by_current_core", &settings->bools.filter_by_current_core, false, false /* TODO */, false);
SETTING_BOOL("filter_by_current_core", &settings->bools.filter_by_current_core, true, DEFAULT_FILTER_BY_CURRENT_CORE, false);
SETTING_BOOL("rgui_show_start_screen", &settings->bools.menu_show_start_screen, false, false /* TODO */, false);
SETTING_BOOL("menu_navigation_wraparound_enable", &settings->bools.menu_navigation_wraparound_enable, true, true, false);
SETTING_BOOL("menu_navigation_browser_filter_supported_extensions_enable",
@ -1588,6 +1644,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("cheevos_hardcore_mode_enable", &settings->bools.cheevos_hardcore_mode_enable, true, false, false);
SETTING_BOOL("cheevos_leaderboards_enable", &settings->bools.cheevos_leaderboards_enable, true, false, false);
SETTING_BOOL("cheevos_richpresence_enable", &settings->bools.cheevos_richpresence_enable, true, true, false);
SETTING_BOOL("cheevos_unlock_sound_enable", &settings->bools.cheevos_unlock_sound_enable, true, false, false);
SETTING_BOOL("cheevos_verbose_enable", &settings->bools.cheevos_verbose_enable, true, false, false);
SETTING_BOOL("cheevos_auto_screenshot", &settings->bools.cheevos_auto_screenshot, true, false, false);
SETTING_BOOL("cheevos_badges_enable", &settings->bools.cheevos_badges_enable, true, false, false);
@ -1595,8 +1652,8 @@ static struct config_bool_setting *populate_settings_bool(
#endif
#ifdef HAVE_OVERLAY
SETTING_BOOL("input_overlay_enable", &settings->bools.input_overlay_enable, true, config_overlay_enable_default(), false);
SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, true, false);
SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, false, false);
SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, DEFAULT_OVERLAY_ENABLE_AUTOPREFERRED, false);
SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, DEFAULT_SHOW_PHYSICAL_INPUTS, false);
SETTING_BOOL("input_overlay_hide_in_menu", &settings->bools.input_overlay_hide_in_menu, true, DEFAULT_OVERLAY_HIDE_IN_MENU, false);
SETTING_BOOL("input_overlay_show_mouse_cursor", &settings->bools.input_overlay_show_mouse_cursor, true, DEFAULT_OVERLAY_SHOW_MOUSE_CURSOR, false);
SETTING_BOOL("input_overlay_auto_rotate", &settings->bools.input_overlay_auto_rotate, true, DEFAULT_OVERLAY_AUTO_ROTATE, false);
@ -1676,7 +1733,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("log_to_file", &settings->bools.log_to_file, true, DEFAULT_LOG_TO_FILE, false);
SETTING_OVERRIDE(RARCH_OVERRIDE_SETTING_LOG_TO_FILE);
SETTING_BOOL("log_to_file_timestamp", &settings->bools.log_to_file_timestamp, true, DEFAULT_LOG_TO_FILE_TIMESTAMP, false);
SETTING_BOOL("ai_service_enable", &settings->bools.ai_service_enable, DEFAULT_AI_SERVICE_ENABLE, false, false);
SETTING_BOOL("ai_service_enable", &settings->bools.ai_service_enable, true, DEFAULT_AI_SERVICE_ENABLE, false);
SETTING_BOOL("ai_service_pause", &settings->bools.ai_service_pause, true, DEFAULT_AI_SERVICE_PAUSE, false);
*size = count;
@ -1894,9 +1951,9 @@ static struct config_uint_setting *populate_settings_uint(
SETTING_UINT("video_windowed_position_y", &settings->uints.window_position_y, true, 0, false);
SETTING_UINT("video_windowed_position_width", &settings->uints.window_position_width, true, DEFAULT_WINDOW_WIDTH, false);
SETTING_UINT("video_windowed_position_height", &settings->uints.window_position_height, true, DEFAULT_WINDOW_HEIGHT, false);
SETTING_UINT("ai_service_mode", &settings->uints.ai_service_mode, DEFAULT_AI_SERVICE_MODE, 0, false);
SETTING_UINT("ai_service_target_lang", &settings->uints.ai_service_target_lang, 0, 0, false);
SETTING_UINT("ai_service_source_lang", &settings->uints.ai_service_source_lang, 0, 0, false);
SETTING_UINT("ai_service_mode", &settings->uints.ai_service_mode, true, DEFAULT_AI_SERVICE_MODE, false);
SETTING_UINT("ai_service_target_lang", &settings->uints.ai_service_target_lang, true, 0, false);
SETTING_UINT("ai_service_source_lang", &settings->uints.ai_service_source_lang, true, 0, false);
SETTING_UINT("video_record_threads", &settings->uints.video_record_threads, true, DEFAULT_VIDEO_RECORD_THREADS, false);
@ -1975,6 +2032,20 @@ static struct config_int_setting *populate_settings_int(
return tmp;
}
static void video_driver_default_settings(void)
{
global_t *global = global_get_ptr();
if (!global)
return;
global->console.screen.gamma_correction = DEFAULT_GAMMA;
global->console.flickerfilter_enable = false;
global->console.softfilter_enable = false;
global->console.screen.resolutions.current.id = 0;
}
/**
* config_set_defaults:
*
@ -2002,6 +2073,7 @@ void config_set_defaults(void *data)
const char *def_menu = config_get_default_menu();
#endif
const char *def_camera = config_get_default_camera();
const char *def_bluetooth = config_get_default_bluetooth();
const char *def_wifi = config_get_default_wifi();
const char *def_led = config_get_default_led();
const char *def_location = config_get_default_location();
@ -2073,6 +2145,10 @@ void config_set_defaults(void *data)
configuration_set_string(settings,
settings->arrays.camera_driver,
def_camera);
if (def_bluetooth)
configuration_set_string(settings,
settings->arrays.bluetooth_driver,
def_bluetooth);
if (def_wifi)
configuration_set_string(settings,
settings->arrays.wifi_driver,
@ -2141,11 +2217,6 @@ void config_set_defaults(void *data)
#endif
#endif
#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
configuration_set_bool(settings, settings->bools.multimedia_builtin_mediaplayer_enable, true);
#else
configuration_set_bool(settings, settings->bools.multimedia_builtin_mediaplayer_enable, false);
#endif
settings->floats.video_scale = DEFAULT_SCALE;
video_driver_set_threaded(DEFAULT_VIDEO_THREADED);
@ -2200,7 +2271,6 @@ void config_set_defaults(void *data)
#ifdef HAVE_CONFIGFILE
input_remapping_set_defaults(true);
#endif
input_autoconfigure_reset();
/* Verify that binds are in proper order. */
for (i = 0; i < MAX_USERS; i++)
@ -2515,7 +2585,7 @@ static bool check_menu_driver_compatibility(settings_t *settings)
return true;
/* TODO/FIXME - maintenance hazard */
if (string_starts_with(video_driver, "d3d"))
if (string_starts_with_size(video_driver, "d3d", STRLEN_CONST("d3d")))
if (
string_is_equal(video_driver, "d3d9") ||
string_is_equal(video_driver, "d3d10") ||
@ -2523,7 +2593,7 @@ static bool check_menu_driver_compatibility(settings_t *settings)
string_is_equal(video_driver, "d3d12")
)
return true;
if (string_starts_with(video_driver, "gl"))
if (string_starts_with_size(video_driver, "gl", STRLEN_CONST("gl")))
if (
string_is_equal(video_driver, "gl") ||
string_is_equal(video_driver, "gl1") ||
@ -2754,6 +2824,39 @@ error:
free(app_path);
return NULL;
}
#ifdef RARCH_CONSOLE
static void video_driver_load_settings(config_file_t *conf)
{
bool tmp_bool = false;
global_t *global = global_get_ptr();
if (!conf)
return;
CONFIG_GET_INT_BASE(conf, global,
console.screen.gamma_correction, "gamma_correction");
if (config_get_bool(conf, "flicker_filter_enable",
&tmp_bool))
global->console.flickerfilter_enable = tmp_bool;
if (config_get_bool(conf, "soft_filter_enable",
&tmp_bool))
global->console.softfilter_enable = tmp_bool;
CONFIG_GET_INT_BASE(conf, global,
console.screen.soft_filter_index,
"soft_filter_index");
CONFIG_GET_INT_BASE(conf, global,
console.screen.resolutions.current.id,
"current_resolution_id");
CONFIG_GET_INT_BASE(conf, global,
console.screen.flicker_filter_index,
"flicker_filter_index");
}
#endif
/**
* config_load:
* @path : path to be read from.
@ -3326,6 +3429,7 @@ bool config_load_override(void *data)
system->info.library_name : NULL;
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
const char *game_name = path_basename(rarch_path_basename);
settings_t *settings = config_get_ptr();
char content_dir_name[PATH_MAX_LENGTH];
if (!string_is_empty(rarch_path_basename))
@ -3464,15 +3568,16 @@ bool config_load_override(void *data)
retroarch_override_setting_unset(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL);
if (!config_load_file(global_get_ptr(),
path_get(RARCH_PATH_CONFIG), config_get_ptr()))
path_get(RARCH_PATH_CONFIG), settings))
goto error;
/* Restore the libretro_path we're using
* since it will be overwritten by the override when reloading. */
path_set(RARCH_PATH_CORE, buf);
runloop_msg_queue_push(msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED),
1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
if (settings->bools.notification_show_config_override_load)
runloop_msg_queue_push(msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED),
1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
/* Reset save paths. */
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL);
@ -3550,6 +3655,8 @@ bool config_load_remap(const char *directory_input_remapping,
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
const char *game_name = path_basename(rarch_path_basename);
enum msg_hash_enums msg_remap_loaded = MSG_GAME_REMAP_FILE_LOADED;
settings_t *settings = config_get_ptr();
bool notification_show_remap_load = settings->bools.notification_show_remap_load;
char content_dir_name[PATH_MAX_LENGTH];
if (string_is_empty(core_name) || string_is_empty(game_name))
@ -3650,9 +3757,11 @@ bool config_load_remap(const char *directory_input_remapping,
return false;
success:
runloop_msg_queue_push(
msg_hash_to_str(msg_remap_loaded), 1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
if (notification_show_remap_load)
runloop_msg_queue_push(
msg_hash_to_str(msg_remap_loaded), 1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
free(content_path);
free(remap_directory);
free(core_path);
@ -3684,6 +3793,28 @@ static void config_parse_file(global_t *global)
}
}
}
static void video_driver_save_settings(config_file_t *conf)
{
global_t *global = global_get_ptr();
if (!conf)
return;
config_set_int(conf, "gamma_correction",
global->console.screen.gamma_correction);
config_set_bool(conf, "flicker_filter_enable",
global->console.flickerfilter_enable);
config_set_bool(conf, "soft_filter_enable",
global->console.softfilter_enable);
config_set_int(conf, "soft_filter_index",
global->console.screen.soft_filter_index);
config_set_int(conf, "current_resolution_id",
global->console.screen.resolutions.current.id);
config_set_int(conf, "flicker_filter_index",
global->console.screen.flicker_filter_index);
}
/**
* config_save_autoconf_profile:
* @path : Path that shall be written to.
@ -3773,8 +3904,8 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
config_set_string(conf, "input_device",
input_config_get_device_name(user));
pid_user = input_config_get_pid(user);
vid_user = input_config_get_vid(user);
pid_user = input_config_get_device_pid(user);
vid_user = input_config_get_device_vid(user);
if (pid_user && vid_user)
{
@ -4304,4 +4435,288 @@ bool config_replace(bool config_replace_save_on_exit, char *path)
return task_push_start_dummy_core(&content_info);
}
/**
* input_remapping_load_file:
* @data : Path to config file.
*
* Loads a remap file from disk to memory.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool input_remapping_load_file(void *data, const char *path)
{
unsigned i, j, k;
config_file_t *conf = (config_file_t*)data;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (!conf || string_is_empty(path))
return false;
if (!string_is_empty(global->name.remapfile))
input_remapping_set_defaults(true);
global->name.remapfile = strdup(path);
for (i = 0; i < MAX_USERS; i++)
{
char s1[64], s2[64], s3[64];
char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char stk_ident[8][192] = {{0}};
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = {
"b", "y", "select", "start",
"up", "down", "left", "right",
"a", "x", "l", "r", "l2", "r2",
"l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
old_analog_dpad_mode[i] = settings->uints.input_analog_dpad_mode[i];
old_libretro_device[i] = settings->uints.input_libretro_device[i];
s1[0] = '\0';
s2[0] = '\0';
s3[0] = '\0';
snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1);
snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
snprintf(s3, sizeof(s3), "input_player%u_stk", i + 1);
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{
if (j < RARCH_FIRST_CUSTOM_BIND)
{
int btn_remap = -1;
int key_remap = -1;
fill_pathname_join_delim(btn_ident[j], s1,
key_strings[j], '_', sizeof(btn_ident[j]));
fill_pathname_join_delim(key_ident[j], s2,
key_strings[j], '_', sizeof(btn_ident[j]));
if (config_get_int(conf, btn_ident[j], &btn_remap))
{
if (btn_remap == -1)
btn_remap = RARCH_UNMAPPED;
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], btn_remap);
}
if (!config_get_int(conf, key_ident[j], &key_remap))
key_remap = RETROK_UNKNOWN;
configuration_set_uint(settings,
settings->uints.input_keymapper_ids[i][j], key_remap);
}
else
{
int stk_remap = -1;
k = j - RARCH_FIRST_CUSTOM_BIND;
fill_pathname_join_delim(stk_ident[k], s3,
key_strings[j], '$', sizeof(stk_ident[k]));
snprintf(stk_ident[k],
sizeof(stk_ident[k]),
"%s_%s",
s3,
key_strings[j]);
if (config_get_int(conf, stk_ident[k], &stk_remap))
{
if (stk_remap == -1)
stk_remap = RARCH_UNMAPPED;
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], stk_remap);
}
}
}
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], s1);
snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_libretro_device[i], s1);
}
config_file_free(conf);
return true;
}
/**
* input_remapping_save_file:
* @path : Path to remapping file (relative path).
*
* Saves remapping values to file.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool input_remapping_save_file(const char *path)
{
bool ret;
unsigned i, j, k;
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
config_file_t *conf = NULL;
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
settings_t *settings = config_get_ptr();
const char *dir_input_remapping = settings->paths.directory_input_remapping;
buf[0] = remap_file[0] = '\0';
fill_pathname_join(buf, dir_input_remapping, path, path_size);
fill_pathname_noext(remap_file, buf, ".rmp", path_size);
free(buf);
if (!(conf = config_file_new_from_path_to_string(remap_file)))
{
if (!(conf = config_file_new_alloc()))
{
free(remap_file);
return false;
}
}
for (i = 0; i < max_users; i++)
{
char s1[64], s2[64], s3[64];
char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char stk_ident[8][128] = {{0}};
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = {
"b", "y", "select", "start",
"up", "down", "left", "right",
"a", "x", "l", "r", "l2", "r2",
"l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
s1[0] = '\0';
s2[0] = '\0';
snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1);
snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
snprintf(s3, sizeof(s1), "input_player%u_stk", i + 1);
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{
unsigned remap_id = settings->uints.input_remap_ids[i][j];
unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];
if (j < RARCH_FIRST_CUSTOM_BIND)
{
fill_pathname_join_delim(btn_ident[j], s1,
key_strings[j], '_', sizeof(btn_ident[j]));
fill_pathname_join_delim(key_ident[j], s2,
key_strings[j], '_', sizeof(btn_ident[j]));
/* only save values that have been modified */
if (remap_id != j && remap_id != RARCH_UNMAPPED)
config_set_int(conf, btn_ident[j],
settings->uints.input_remap_ids[i][j]);
else if (remap_id != j && remap_id == RARCH_UNMAPPED)
config_set_int(conf, btn_ident[j], -1);
else
config_unset(conf, btn_ident[j]);
if (keymap_id != RETROK_UNKNOWN)
config_set_int(conf, key_ident[j],
settings->uints.input_keymapper_ids[i][j]);
}
else
{
k = j - RARCH_FIRST_CUSTOM_BIND;
fill_pathname_join_delim(stk_ident[k], s3,
key_strings[j], '_', sizeof(stk_ident[k]));
if (remap_id != j && remap_id != RARCH_UNMAPPED)
config_set_int(conf, stk_ident[k],
settings->uints.input_remap_ids[i][j]);
else if (remap_id != j && remap_id == RARCH_UNMAPPED)
config_set_int(conf, stk_ident[k],
-1);
else
config_unset(conf, stk_ident[k]);
}
}
snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
config_set_int(conf, s1, input_config_get_device(i));
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
config_set_int(conf, s1, settings->uints.input_analog_dpad_mode[i]);
}
ret = config_file_write(conf, remap_file, true);
config_file_free(conf);
free(remap_file);
return ret;
}
bool input_remapping_remove_file(const char *path,
const char *dir_input_remapping)
{
bool ret = false;
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
buf[0] = remap_file[0] = '\0';
fill_pathname_join(buf, dir_input_remapping, path, path_size);
fill_pathname_noext(remap_file, buf, ".rmp", path_size);
ret = filestream_delete(remap_file) == 0 ? true : false;
free(buf);
free(remap_file);
return ret;
}
void input_remapping_set_defaults(bool deinit)
{
unsigned i, j;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (!global)
return;
if (deinit)
{
if (!string_is_empty(global->name.remapfile))
free(global->name.remapfile);
global->name.remapfile = NULL;
rarch_ctl(RARCH_CTL_UNSET_REMAPS_CORE_ACTIVE, NULL);
rarch_ctl(RARCH_CTL_UNSET_REMAPS_CONTENT_DIR_ACTIVE, NULL);
rarch_ctl(RARCH_CTL_UNSET_REMAPS_GAME_ACTIVE, NULL);
}
for (i = 0; i < MAX_USERS; i++)
{
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{
if (j < RARCH_FIRST_CUSTOM_BIND)
{
const struct retro_keybind *keybind = &input_config_binds[i][j];
if (keybind)
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], keybind->id);
configuration_set_uint(settings,
settings->uints.input_keymapper_ids[i][j], RETROK_UNKNOWN);
}
else
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], j);
}
if (old_analog_dpad_mode[i])
configuration_set_uint(settings,
settings->uints.input_analog_dpad_mode[i], old_analog_dpad_mode[i]);
if (old_libretro_device[i])
configuration_set_uint(settings,
settings->uints.input_libretro_device[i], old_libretro_device[i]);
}
}
#endif

View File

@ -158,6 +158,13 @@ typedef struct settings
/* Menu */
bool filter_by_current_core;
bool menu_enable_widgets;
bool menu_show_load_content_animation;
bool notification_show_autoconfig;
bool notification_show_cheats_applied;
bool notification_show_remap_load;
bool notification_show_config_override_load;
bool notification_show_set_initial_disk;
bool notification_show_fast_forward;
bool menu_widget_scale_auto;
bool menu_show_start_screen;
bool menu_pause_libretro;
@ -306,10 +313,14 @@ typedef struct settings
bool cheevos_verbose_enable;
bool cheevos_auto_screenshot;
bool cheevos_start_active;
bool cheevos_unlock_sound_enable;
/* Camera */
bool camera_allow;
/* Bluetooth */
bool bluetooth_allow;
/* WiFi */
bool wifi_allow;
@ -356,6 +367,9 @@ typedef struct settings
bool network_remote_enable_user[MAX_USERS];
bool load_dummy_on_core_shutdown;
bool check_firmware_before_loading;
#ifndef HAVE_DYNAMIC
bool always_reload_core_on_run_content;
#endif
bool game_specific_options;
bool auto_overrides_enable;
@ -639,6 +653,7 @@ typedef struct settings
char video_driver[32];
char record_driver[32];
char camera_driver[32];
char bluetooth_driver[32];
char wifi_driver[32];
char led_driver[32];
char location_driver[32];
@ -759,6 +774,15 @@ typedef struct settings
**/
const char *config_get_default_camera(void);
/**
* config_get_default_bluetooth:
*
* Gets default bluetooth driver.
*
* Returns: Default bluetooth driver.
**/
const char *config_get_default_bluetooth(void);
/**
* config_get_default_wifi:
*

View File

@ -51,8 +51,8 @@ bool content_load_state(const char* path, bool load_to_backup_buffer, bool autol
/* Save a state from memory to disk. */
bool content_save_state(const char *path, bool save_to_disk, bool autosave);
/* Returns true if a save state task is in progress */
bool content_save_state_in_progress(void);
/* Waits for any in-progress save state tasks to finish */
void content_wait_for_save_state_task(void);
/* Copy a save state. */
bool content_rename_state(const char *origin, const char *dest);

2
core.h
View File

@ -156,7 +156,9 @@ typedef struct retro_callbacks
bool core_set_default_callbacks(struct retro_callbacks *cbs);
#ifdef HAVE_REWIND
bool core_set_rewind_callbacks(void);
#endif
#ifdef HAVE_NETWORKING
bool core_set_netplay_callbacks(void);

View File

@ -536,23 +536,27 @@ core_backup_list_t *core_backup_list_init(
dir_list_sort(dir_list, true);
/* Create core backup list */
backup_list = (core_backup_list_t*)calloc(1, sizeof(*backup_list));
backup_list = (core_backup_list_t*)malloc(sizeof(*backup_list));
if (!backup_list)
goto error;
backup_list->entries = NULL;
backup_list->capacity = 0;
backup_list->size = 0;
/* Create entries array
* (Note: Set this to the full size of the directory
* list - this may be larger than we need, but saves
* many inefficiencies later) */
entries = (core_backup_list_entry_t*)calloc(dir_list->size, sizeof(*entries));
entries = (core_backup_list_entry_t*)
calloc(dir_list->size, sizeof(*entries));
if (!entries)
goto error;
backup_list->entries = entries;
backup_list->capacity = dir_list->size;
backup_list->size = 0;
/* Loop over backup files and parse file names */
for (i = 0; i < dir_list->size; i++)

View File

@ -114,31 +114,25 @@ static void core_info_list_resolve_all_firmware(
char path_key[64];
char desc_key[64];
char opt_key[64];
struct config_entry_list
*entry = NULL;
bool tmp_bool = false;
char *tmp = NULL;
path_key[0] = desc_key[0] = opt_key[0] = '\0';
snprintf(path_key, sizeof(path_key), "firmware%u_path", c);
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c);
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c);
if (config_get_string(config, path_key, &tmp))
{
if (!string_is_empty(tmp))
info->firmware[c].path = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(config, desc_key, &tmp))
{
if (!string_is_empty(tmp))
info->firmware[c].desc = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (tmp)
free(tmp);
tmp = NULL;
entry = config_get_entry(config, path_key, NULL);
if (entry && !string_is_empty(entry->value))
info->firmware[c].path = strdup(entry->value);
entry = config_get_entry(config, desc_key, NULL);
if (entry && !string_is_empty(entry->value))
info->firmware[c].desc = strdup(entry->value);
if (config_get_bool(config, opt_key , &tmp_bool))
info->firmware[c].optional = tmp_bool;
}
@ -304,14 +298,20 @@ static core_info_list_t *core_info_list_new(const char *path,
if (!contents)
return NULL;
core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
core_info_list = (core_info_list_t*)malloc(sizeof(*core_info_list));
if (!core_info_list)
{
string_list_free(contents);
return NULL;
}
core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
core_info_list->list = NULL;
core_info_list->count = 0;
core_info_list->all_ext = NULL;
core_info = (core_info_t*)
calloc(contents->size, sizeof(*core_info));
if (!core_info)
{
core_info_list_free(core_info_list);
@ -319,8 +319,8 @@ static core_info_list_t *core_info_list_new(const char *path,
return NULL;
}
core_info_list->list = core_info;
core_info_list->count = contents->size;
core_info_list->list = core_info;
core_info_list->count = contents->size;
for (i = 0; i < contents->size; i++)
{
@ -330,188 +330,130 @@ static core_info_list_t *core_info_list_new(const char *path,
if (conf)
{
char *tmp = NULL;
bool tmp_bool = false;
unsigned tmp_uint = 0;
struct config_entry_list
*entry = config_get_entry(conf, "display_name", NULL);
if (config_get_string(conf, "display_name", &tmp))
if (entry && !string_is_empty(entry->value))
core_info[i].display_name = strdup(entry->value);
entry = config_get_entry(conf, "display_version", NULL);
if (entry && !string_is_empty(entry->value))
core_info[i].display_version = strdup(entry->value);
entry = config_get_entry(conf, "corename", NULL);
if (entry && !string_is_empty(entry->value))
core_info[i].core_name = strdup(entry->value);
entry = config_get_entry(conf, "systemname", NULL);
if (entry && !string_is_empty(entry->value))
core_info[i].systemname = strdup(entry->value);
entry = config_get_entry(conf, "systemid", NULL);
if (entry && !string_is_empty(entry->value))
core_info[i].system_id = strdup(entry->value);
entry = config_get_entry(conf, "manufacturer", NULL);
if (entry && !string_is_empty(entry->value))
core_info[i].system_manufacturer = strdup(entry->value);
config_get_uint(conf, "firmware_count", &tmp_uint);
core_info[i].firmware_count = tmp_uint;
entry = config_get_entry(conf, "supported_extensions", NULL);
if (entry && !string_is_empty(entry->value))
{
if (!string_is_empty(tmp))
core_info[i].display_name = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "display_version", &tmp))
{
if (!string_is_empty(tmp))
core_info[i].display_version = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "corename", &tmp))
{
if (!string_is_empty(tmp))
core_info[i].core_name = strdup(tmp);
free(tmp);
tmp = NULL;
core_info[i].supported_extensions = strdup(entry->value);
core_info[i].supported_extensions_list =
string_split(core_info[i].supported_extensions, "|");
}
if (config_get_string(conf, "systemname", &tmp))
entry = config_get_entry(conf, "authors", NULL);
if (entry && !string_is_empty(entry->value))
{
if (!string_is_empty(tmp))
core_info[i].systemname = strdup(tmp);
free(tmp);
tmp = NULL;
core_info[i].authors = strdup(entry->value);
core_info[i].authors_list =
string_split(core_info[i].authors, "|");
}
if (config_get_string(conf, "systemid", &tmp))
entry = config_get_entry(conf, "permissions", NULL);
if (entry && !string_is_empty(entry->value))
{
if (!string_is_empty(tmp))
core_info[i].system_id = strdup(tmp);
free(tmp);
tmp = NULL;
core_info[i].permissions = strdup(entry->value);
core_info[i].permissions_list =
string_split(core_info[i].permissions, "|");
}
if (config_get_string(conf, "manufacturer", &tmp))
entry = config_get_entry(conf, "license", NULL);
if (entry && !string_is_empty(entry->value))
{
if (!string_is_empty(tmp))
core_info[i].system_manufacturer = strdup(tmp);
free(tmp);
tmp = NULL;
core_info[i].licenses = strdup(entry->value);
core_info[i].licenses_list =
string_split(core_info[i].licenses, "|");
}
entry = config_get_entry(conf, "categories", NULL);
if (entry && !string_is_empty(entry->value))
{
unsigned count = 0;
config_get_uint(conf, "firmware_count", &count);
core_info[i].firmware_count = count;
core_info[i].categories = strdup(entry->value);
core_info[i].categories_list =
string_split(core_info[i].categories, "|");
}
if (config_get_string(conf, "supported_extensions", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].supported_extensions = strdup(tmp);
core_info[i].supported_extensions_list =
string_split(core_info[i].supported_extensions, "|");
}
entry = config_get_entry(conf, "database", NULL);
free(tmp);
tmp = NULL;
if (entry && !string_is_empty(entry->value))
{
core_info[i].databases = strdup(entry->value);
core_info[i].databases_list =
string_split(core_info[i].databases, "|");
}
if (config_get_string(conf, "authors", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].authors = strdup(tmp);
core_info[i].authors_list =
string_split(core_info[i].authors, "|");
}
entry = config_get_entry(conf, "notes", NULL);
free(tmp);
tmp = NULL;
if (entry && !string_is_empty(entry->value))
{
core_info[i].notes = strdup(entry->value);
core_info[i].note_list =
string_split(core_info[i].notes, "|");
}
if (config_get_string(conf, "permissions", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].permissions = strdup(tmp);
core_info[i].permissions_list =
string_split(core_info[i].permissions, "|");
}
entry = config_get_entry(conf, "required_hw_api", NULL);
free(tmp);
tmp = NULL;
if (entry && !string_is_empty(entry->value))
{
core_info[i].required_hw_api = strdup(entry->value);
core_info[i].required_hw_api_list =
string_split(core_info[i].required_hw_api, "|");
}
if (config_get_string(conf, "license", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].licenses = strdup(tmp);
core_info[i].licenses_list =
string_split(core_info[i].licenses, "|");
}
entry = config_get_entry(conf, "description", NULL);
free(tmp);
tmp = NULL;
}
if (entry && !string_is_empty(entry->value))
core_info[i].description = strdup(entry->value);
if (config_get_string(conf, "categories", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].categories = strdup(tmp);
core_info[i].categories_list =
string_split(core_info[i].categories, "|");
}
if (config_get_bool(conf, "supports_no_game",
&tmp_bool))
core_info[i].supports_no_game = tmp_bool;
free(tmp);
tmp = NULL;
}
if (config_get_bool(conf, "database_match_archive_member",
&tmp_bool))
core_info[i].database_match_archive_member = tmp_bool;
if (config_get_string(conf, "database", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].databases = strdup(tmp);
core_info[i].databases_list =
string_split(core_info[i].databases, "|");
}
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "notes", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].notes = strdup(tmp);
core_info[i].note_list = string_split(core_info[i].notes, "|");
}
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "required_hw_api", &tmp))
{
if (!string_is_empty(tmp))
{
core_info[i].required_hw_api = strdup(tmp);
core_info[i].required_hw_api_list = string_split(core_info[i].required_hw_api, "|");
}
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "description", &tmp))
{
if (!string_is_empty(tmp))
core_info[i].description = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (tmp)
free(tmp);
tmp = NULL;
{
bool tmp_bool = false;
if (config_get_bool(conf, "supports_no_game",
&tmp_bool))
core_info[i].supports_no_game = tmp_bool;
if (config_get_bool(conf, "database_match_archive_member",
&tmp_bool))
core_info[i].database_match_archive_member = tmp_bool;
if (config_get_bool(conf, "is_experimental",
&tmp_bool))
core_info[i].is_experimental = tmp_bool;
}
if (config_get_bool(conf, "is_experimental",
&tmp_bool))
core_info[i].is_experimental = tmp_bool;
core_info[i].config_data = conf;
}
@ -735,11 +677,47 @@ void core_info_free_current_core(core_info_state_t *p_coreinfo)
bool core_info_init_current_core(void)
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
core_info_t *current = (core_info_t*)calloc(1, sizeof(*current));
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
core_info_t *current = (core_info_t*)
malloc(sizeof(*current));
if (!current)
return false;
p_coreinfo->current = current;
current->supports_no_game = false;
current->database_match_archive_member = false;
current->is_experimental = false;
current->is_locked = false;
current->firmware_count = 0;
current->path = NULL;
current->config_data = NULL;
current->display_name = NULL;
current->display_version = NULL;
current->core_name = NULL;
current->system_manufacturer = NULL;
current->systemname = NULL;
current->system_id = NULL;
current->supported_extensions = NULL;
current->authors = NULL;
current->permissions = NULL;
current->licenses = NULL;
current->categories = NULL;
current->databases = NULL;
current->notes = NULL;
current->required_hw_api = NULL;
current->description = NULL;
current->categories_list = NULL;
current->databases_list = NULL;
current->note_list = NULL;
current->supported_extensions_list = NULL;
current->authors_list = NULL;
current->permissions_list = NULL;
current->licenses_list = NULL;
current->required_hw_api_list = NULL;
current->firmware = NULL;
current->core_file_id.str = NULL;
current->core_file_id.len = 0;
current->userdata = NULL;
p_coreinfo->current = current;
return true;
}
@ -912,8 +890,9 @@ void core_info_get_name(const char *path, char *s, size_t len,
for (i = 0; i < contents->size; i++)
{
struct config_entry_list
*entry = NULL;
config_file_t *conf = NULL;
char *new_core_name = NULL;
const char *current_path = contents->elems[i].data;
if (!string_is_equal(path_basename(current_path), core_path_basename))
@ -925,13 +904,13 @@ void core_info_get_name(const char *path, char *s, size_t len,
if (!conf)
continue;
if (config_get_string(conf, get_display_name
? "display_name" : "corename",
&new_core_name))
{
strlcpy(s, new_core_name, len);
free(new_core_name);
}
if (get_display_name)
entry = config_get_entry(conf, "display_name", NULL);
else
entry = config_get_entry(conf, "corename", NULL);
if (entry && !string_is_empty(entry->value))
strlcpy(s, entry->value, len);
config_file_free(conf);
break;
@ -1077,17 +1056,17 @@ bool core_info_list_get_display_name(core_info_list_t *core_info_list,
bool core_info_get_display_name(const char *path, char *s, size_t len)
{
char *tmp = NULL;
struct config_entry_list
*entry = NULL;
config_file_t *conf = config_file_new_from_path_to_string(path);
if (!conf)
return false;
if (config_get_string(conf, "display_name", &tmp))
{
strlcpy(s, tmp, len);
free(tmp);
}
entry = config_get_entry(conf, "display_name", NULL);
if (entry && !string_is_empty(entry->value))
strlcpy(s, entry->value, len);
config_file_free(conf);
return true;
@ -1100,7 +1079,8 @@ bool core_info_get_display_name(const char *path, char *s, size_t len)
* Returns NULL if 'path' is invalid. */
core_updater_info_t *core_info_get_core_updater_info(const char *path)
{
char *tmp_str = NULL;
struct config_entry_list
*entry = NULL;
bool tmp_bool = false;
core_updater_info_t *info = NULL;
config_file_t *conf = NULL;
@ -1115,53 +1095,39 @@ core_updater_info_t *core_info_get_core_updater_info(const char *path)
return NULL;
/* Create info struct */
info = (core_updater_info_t*)calloc(1, sizeof(*info));
info = (core_updater_info_t*)malloc(sizeof(*info));
if (!info)
return NULL;
info->is_experimental = false;
info->display_name = NULL;
info->description = NULL;
info->licenses = NULL;
/* Fetch required parameters */
/* > is_experimental */
info->is_experimental = false;
if (config_get_bool(conf, "is_experimental", &tmp_bool))
info->is_experimental = tmp_bool;
info->is_experimental = tmp_bool;
/* > display_name */
info->display_name = NULL;
if (config_get_string(conf, "display_name", &tmp_str))
{
if (!string_is_empty(tmp_str))
info->display_name = tmp_str;
else
free(tmp_str);
entry = config_get_entry(conf, "display_name", NULL);
tmp_str = NULL;
}
if (entry && !string_is_empty(entry->value))
info->display_name = strdup(entry->value);
/* > description */
info->description = NULL;
if (config_get_string(conf, "description", &tmp_str))
{
if (!string_is_empty(tmp_str))
info->description = tmp_str;
else
free(tmp_str);
entry = config_get_entry(conf, "description", NULL);
tmp_str = NULL;
}
if (entry && !string_is_empty(entry->value))
info->description = strdup(entry->value);
/* > licenses */
info->licenses = NULL;
if (config_get_string(conf, "license", &tmp_str))
{
if (!string_is_empty(tmp_str))
info->licenses = tmp_str;
else
free(tmp_str);
entry = config_get_entry(conf, "license", NULL);
tmp_str = NULL;
}
if (entry && !string_is_empty(entry->value))
info->licenses = strdup(entry->value);
/* Clean up */
config_file_free(conf);

View File

@ -109,7 +109,7 @@ core_updater_list_t *core_updater_list_init(size_t max_size)
return NULL;
/* Create core updater list */
core_list = (core_updater_list_t*)calloc(1, sizeof(*core_list));
core_list = (core_updater_list_t*)malloc(sizeof(*core_list));
if (!core_list)
return NULL;

View File

@ -67,6 +67,8 @@ extern "C" {
s ##_version() & 0xFF);
static bool reset_triggered;
static bool libretro_supports_bitmasks = false;
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
va_list va;
@ -193,11 +195,20 @@ static struct
{
unsigned width;
unsigned height;
double interpolate_fps;
unsigned sample_rate;
float aspect;
struct
{
double time;
unsigned hours;
unsigned minutes;
unsigned seconds;
} duration;
} media;
#ifdef HAVE_SSA
@ -231,10 +242,15 @@ void CORE_PREFIX(retro_init)(void)
reset_triggered = false;
av_register_all();
if (CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
libretro_supports_bitmasks = true;
}
void CORE_PREFIX(retro_deinit)(void)
{}
{
libretro_supports_bitmasks = false;
}
unsigned CORE_PREFIX(retro_api_version)(void)
{
@ -473,7 +489,13 @@ static void check_variables(bool firststart)
static void seek_frame(int seek_frames)
{
char msg[256];
struct retro_message msg_obj = {0};
struct retro_message_ext msg_obj = {0};
unsigned seek_hours = 0;
unsigned seek_minutes = 0;
unsigned seek_seconds = 0;
int8_t seek_progress = -1;
msg[0] = '\0';
if ((seek_frames < 0 && (unsigned)-seek_frames > frame_cnt) || reset_triggered)
frame_cnt = 0;
@ -484,10 +506,34 @@ static void seek_frame(int seek_frames)
do_seek = true;
seek_time = frame_cnt / media.interpolate_fps;
snprintf(msg, sizeof(msg), "Seek: %u s.", (unsigned)seek_time);
msg_obj.msg = msg;
msg_obj.frames = 180;
CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg_obj);
/* Convert seek time to a printable format */
seek_seconds = (unsigned)seek_time;
seek_minutes = seek_seconds / 60;
seek_seconds %= 60;
seek_hours = seek_minutes / 60;
seek_minutes %= 60;
snprintf(msg, sizeof(msg), "%02d:%02d:%02d / %02d:%02d:%02d",
seek_hours, seek_minutes, seek_seconds,
media.duration.hours, media.duration.minutes, media.duration.seconds);
/* Get current progress */
if (media.duration.time > 0.0)
{
seek_progress = (int8_t)((100.0 * seek_time / media.duration.time) + 0.5);
seek_progress = (seek_progress < -1) ? -1 : seek_progress;
seek_progress = (seek_progress > 100) ? 100 : seek_progress;
}
/* Send message to frontend */
msg_obj.msg = msg;
msg_obj.duration = 2000;
msg_obj.priority = 3;
msg_obj.level = RETRO_LOG_INFO;
msg_obj.target = RETRO_MESSAGE_TARGET_OSD;
msg_obj.type = RETRO_MESSAGE_TYPE_PROGRESS;
msg_obj.progress = seek_progress;
CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg_obj);
if (seek_frames < 0)
{
@ -522,6 +568,7 @@ void CORE_PREFIX(retro_run)(void)
double min_pts;
int16_t audio_buffer[2048];
bool left, right, up, down, l, r;
int16_t ret = 0;
size_t to_read_frames = 0;
int seek_frames = 0;
bool updated = false;
@ -552,20 +599,28 @@ void CORE_PREFIX(retro_run)(void)
CORE_PREFIX(input_poll_cb)();
left = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_LEFT);
right = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_RIGHT);
up = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_UP) ||
CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP);
down = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_DOWN) ||
CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN);
l = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_L);
r = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_R);
if (libretro_supports_bitmasks)
ret = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD,
0, RETRO_DEVICE_ID_JOYPAD_MASK);
else
{
unsigned i;
for (i = RETRO_DEVICE_ID_JOYPAD_B; i <= RETRO_DEVICE_ID_JOYPAD_R; i++)
if (CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0, i))
ret |= (1 << i);
}
if (CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP))
ret |= (1 << RETRO_DEVICE_ID_JOYPAD_UP);
if (CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN))
ret |= (1 << RETRO_DEVICE_ID_JOYPAD_DOWN);
left = ret & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT);
right = ret & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT);
up = ret & (1 << RETRO_DEVICE_ID_JOYPAD_UP);
down = ret & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN);
l = ret & (1 << RETRO_DEVICE_ID_JOYPAD_L);
r = ret & (1 << RETRO_DEVICE_ID_JOYPAD_R);
if (left && !last_left)
seek_frames -= 10 * media.interpolate_fps;
@ -579,7 +634,9 @@ void CORE_PREFIX(retro_run)(void)
if (l && !last_l && audio_streams_num > 0)
{
char msg[256];
struct retro_message msg_obj = {0};
struct retro_message_ext msg_obj = {0};
msg[0] = '\0';
slock_lock(decode_thread_lock);
audio_streams_ptr = (audio_streams_ptr + 1) % audio_streams_num;
@ -587,23 +644,36 @@ void CORE_PREFIX(retro_run)(void)
snprintf(msg, sizeof(msg), "Audio Track #%d.", audio_streams_ptr);
msg_obj.msg = msg;
msg_obj.frames = 180;
CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg_obj);
msg_obj.msg = msg;
msg_obj.duration = 3000;
msg_obj.priority = 1;
msg_obj.level = RETRO_LOG_INFO;
msg_obj.target = RETRO_MESSAGE_TARGET_ALL;
msg_obj.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
msg_obj.progress = -1;
CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg_obj);
}
else if (r && !last_r && subtitle_streams_num > 0)
{
char msg[256];
struct retro_message msg_obj = {0};
struct retro_message_ext msg_obj = {0};
msg[0] = '\0';
slock_lock(decode_thread_lock);
subtitle_streams_ptr = (subtitle_streams_ptr + 1) % subtitle_streams_num;
slock_unlock(decode_thread_lock);
snprintf(msg, sizeof(msg), "Subtitle Track #%d.", subtitle_streams_ptr);
msg_obj.msg = msg;
msg_obj.frames = 180;
CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg_obj);
msg_obj.msg = msg;
msg_obj.duration = 3000;
msg_obj.priority = 1;
msg_obj.level = RETRO_LOG_INFO;
msg_obj.target = RETRO_MESSAGE_TARGET_ALL;
msg_obj.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
msg_obj.progress = -1;
CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg_obj);
}
last_left = left;
@ -649,7 +719,7 @@ void CORE_PREFIX(retro_run)(void)
to_read_bytes = to_read_frames * sizeof(int16_t) * 2;
slock_lock(fifo_lock);
while (!decode_thread_dead && fifo_read_avail(audio_decode_fifo) < to_read_bytes)
while (!decode_thread_dead && FIFO_READ_AVAIL(audio_decode_fifo) < to_read_bytes)
{
main_sleeping = true;
scond_signal(fifo_decode_cond);
@ -658,7 +728,7 @@ void CORE_PREFIX(retro_run)(void)
}
reading_pts = decode_last_audio_time -
(double)fifo_read_avail(audio_decode_fifo) / (media.sample_rate * sizeof(int16_t) * 2);
(double)FIFO_READ_AVAIL(audio_decode_fifo) / (media.sample_rate * sizeof(int16_t) * 2);
expected_pts = (double)audio_frames / media.sample_rate;
old_pts_bias = pts_bias;
pts_bias = reading_pts - expected_pts;
@ -707,15 +777,17 @@ void CORE_PREFIX(retro_run)(void)
if (!decode_thread_dead)
{
unsigned y;
const uint8_t *src;
int stride, width;
uint32_t *data = video_frame_temp_buffer;
const uint8_t *src = NULL;
video_decoder_context_t *ctx = NULL;
uint32_t *data = NULL;
video_buffer_get_finished_slot(video_buffer, &ctx);
pts = ctx->pts;
#ifndef HAVE_OPENGLES
#ifdef HAVE_OPENGLES
data = video_frame_temp_buffer;
#else
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, frames[1].pbo);
#ifdef __MACH__
data = (uint32_t*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
@ -1190,6 +1262,28 @@ static bool init_media_info(void)
av_q2d(vctx->sample_aspect_ratio) / vctx->height;
}
if (fctx)
{
if (fctx->duration != AV_NOPTS_VALUE)
{
int64_t duration = fctx->duration + (fctx->duration <= INT64_MAX - 5000 ? 5000 : 0);
media.duration.time = (double)(duration / AV_TIME_BASE);
media.duration.seconds = (unsigned)media.duration.time;
media.duration.minutes = media.duration.seconds / 60;
media.duration.seconds %= 60;
media.duration.hours = media.duration.minutes / 60;
media.duration.minutes %= 60;
}
else
{
media.duration.time = 0.0;
media.duration.hours = 0;
media.duration.minutes = 0;
media.duration.seconds = 0;
log_cb(RETRO_LOG_ERROR, "[FFMPEG] Could not determine media duration\n");
}
}
#ifdef HAVE_SSA
if (sctx[0])
{
@ -1496,7 +1590,8 @@ static int16_t *decode_audio(AVCodecContext *ctx, AVPacket *pkt,
pts = frame->best_effort_timestamp;
slock_lock(fifo_lock);
while (!decode_thread_dead && fifo_write_avail(audio_decode_fifo) < required_buffer)
while (!decode_thread_dead &&
FIFO_WRITE_AVAIL(audio_decode_fifo) < required_buffer)
{
if (!main_sleeping)
scond_wait(fifo_decode_cond, fifo_lock);

View File

@ -1,10 +1,12 @@
#include "packet_buffer.h"
struct AVPacketNode {
struct AVPacketNode
{
AVPacket *data;
struct AVPacketNode *next;
struct AVPacketNode *previous;
};
typedef struct AVPacketNode AVPacketNode_t;
struct packet_buffer
@ -14,7 +16,7 @@ struct packet_buffer
size_t size;
};
packet_buffer_t *packet_buffer_create()
packet_buffer_t *packet_buffer_create(void)
{
packet_buffer_t *b = (packet_buffer_t*)malloc(sizeof(packet_buffer_t));
if (!b)

View File

@ -6,7 +6,13 @@
#include <boolean.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#ifdef __cplusplus
}
#endif
#include <retro_miscellaneous.h>

View File

@ -1,4 +1,10 @@
#ifdef __cplusplus
extern "C" {
#endif
#include <libavformat/avformat.h>
#ifdef __cplusplus
}
#endif
#include <rthreads/rthreads.h>
@ -6,7 +12,7 @@
enum kbStatus
{
KB_OPEN,
KB_OPEN = 0,
KB_IN_PROGRESS,
KB_FINISHED
};
@ -23,32 +29,41 @@ struct video_buffer
int64_t tail;
};
video_buffer_t *video_buffer_create(size_t capacity, int frame_size, int width, int height)
video_buffer_t *video_buffer_create(
size_t capacity, int frame_size, int width, int height)
{
unsigned i;
video_buffer_t *b = (video_buffer_t*)malloc(sizeof(video_buffer_t));
if (!b)
return NULL;
memset(b, 0, sizeof(video_buffer_t));
b->capacity = capacity;
b->buffer = NULL;
b->capacity = capacity;
b->lock = NULL;
b->open_cond = NULL;
b->finished_cond = NULL;
b->head = 0;
b->tail = 0;
b->status = (enum kbStatus*)malloc(sizeof(enum kbStatus) * capacity);
b->status = (enum kbStatus*)malloc(sizeof(enum kbStatus) * capacity);
if (!b->status)
goto fail;
for (int i = 0; i < capacity; i++)
b->status[i] = KB_OPEN;
b->lock = slock_new();
b->open_cond = scond_new();
for (i = 0; i < capacity; i++)
b->status[i] = KB_OPEN;
b->lock = slock_new();
b->open_cond = scond_new();
b->finished_cond = scond_new();
if (!b->lock || !b->open_cond || !b->finished_cond)
goto fail;
b->buffer = (video_decoder_context_t*)malloc(sizeof(video_decoder_context_t) * capacity);
b->buffer = (video_decoder_context_t*)
malloc(sizeof(video_decoder_context_t) * capacity);
if (!b->buffer)
goto fail;
for (int i = 0; i < capacity; i++)
for (i = 0; i < (unsigned)capacity; i++)
{
b->buffer[i].index = i;
b->buffer[i].pts = 0;
@ -60,15 +75,17 @@ video_buffer_t *video_buffer_create(size_t capacity, int frame_size, int width,
b->buffer[i].target = av_frame_alloc();
b->buffer[i].frame_buf = (uint8_t*)av_malloc(frame_size);
avpicture_fill((AVPicture*)b->buffer[i].target, (const uint8_t*)b->buffer[i].frame_buf,
avpicture_fill((AVPicture*)
b->buffer[i].target,
(const uint8_t*)b->buffer[i].frame_buf,
PIX_FMT_RGB32, width, height);
if (!b->buffer[i].sws ||
!b->buffer[i].source ||
if (!b->buffer[i].sws ||
!b->buffer[i].source ||
#if LIBAVUTIL_VERSION_MAJOR > 55
!b->buffer[i].hw_source ||
#endif
!b->buffer[i].target ||
!b->buffer[i].target ||
!b->buffer[i].frame_buf)
goto fail;
}
@ -81,6 +98,7 @@ fail:
void video_buffer_destroy(video_buffer_t *video_buffer)
{
unsigned i;
if (!video_buffer)
return;
@ -89,22 +107,25 @@ void video_buffer_destroy(video_buffer_t *video_buffer)
scond_free(video_buffer->finished_cond);
free(video_buffer->status);
if (video_buffer->buffer)
for (int i = 0; i < video_buffer->capacity; i++)
{
for (i = 0; i < video_buffer->capacity; i++)
{
#if LIBAVUTIL_VERSION_MAJOR > 55
#if LIBAVUTIL_VERSION_MAJOR > 55
av_frame_free(&video_buffer->buffer[i].hw_source);
#endif
#endif
av_frame_free(&video_buffer->buffer[i].source);
av_frame_free(&video_buffer->buffer[i].target);
av_freep(&video_buffer->buffer[i].frame_buf);
sws_freeContext(video_buffer->buffer[i].sws);
}
}
free(video_buffer->buffer);
free(video_buffer);
}
void video_buffer_clear(video_buffer_t *video_buffer)
{
unsigned i;
if (!video_buffer)
return;
@ -115,13 +136,14 @@ void video_buffer_clear(video_buffer_t *video_buffer)
video_buffer->head = 0;
video_buffer->tail = 0;
for (int i = 0; i < video_buffer->capacity; i++)
for (i = 0; i < video_buffer->capacity; i++)
video_buffer->status[i] = KB_OPEN;
slock_unlock(video_buffer->lock);
}
void video_buffer_get_open_slot(video_buffer_t *video_buffer, video_decoder_context_t **context)
void video_buffer_get_open_slot(
video_buffer_t *video_buffer, video_decoder_context_t **context)
{
slock_lock(video_buffer->lock);
@ -136,7 +158,8 @@ void video_buffer_get_open_slot(video_buffer_t *video_buffer, video_decoder_cont
slock_unlock(video_buffer->lock);
}
void video_buffer_return_open_slot(video_buffer_t *video_buffer, video_decoder_context_t *context)
void video_buffer_return_open_slot(
video_buffer_t *video_buffer, video_decoder_context_t *context)
{
slock_lock(video_buffer->lock);
@ -150,7 +173,9 @@ void video_buffer_return_open_slot(video_buffer_t *video_buffer, video_decoder_c
slock_unlock(video_buffer->lock);
}
void video_buffer_open_slot(video_buffer_t *video_buffer, video_decoder_context_t *context)
void video_buffer_open_slot(
video_buffer_t *video_buffer,
video_decoder_context_t *context)
{
slock_lock(video_buffer->lock);
@ -165,7 +190,9 @@ void video_buffer_open_slot(video_buffer_t *video_buffer, video_decoder_context_
slock_unlock(video_buffer->lock);
}
void video_buffer_get_finished_slot(video_buffer_t *video_buffer, video_decoder_context_t **context)
void video_buffer_get_finished_slot(
video_buffer_t *video_buffer,
video_decoder_context_t **context)
{
slock_lock(video_buffer->lock);
@ -175,7 +202,9 @@ void video_buffer_get_finished_slot(video_buffer_t *video_buffer, video_decoder_
slock_unlock(video_buffer->lock);
}
void video_buffer_finish_slot(video_buffer_t *video_buffer, video_decoder_context_t *context)
void video_buffer_finish_slot(
video_buffer_t *video_buffer,
video_decoder_context_t *context)
{
slock_lock(video_buffer->lock);

View File

@ -10,9 +10,17 @@
#include <ass/ass.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <libavutil/frame.h>
#include <libswscale/swscale.h>
#ifdef __cplusplus
}
#endif
#include <retro_miscellaneous.h>
RETRO_BEGIN_DECLS

View File

@ -82,9 +82,8 @@ void __attribute__((weak)) __libctru_init(void (*retAddr)(void))
{
/* Store the return address */
__system_retAddr = NULL;
if (envIsHomebrew()) {
if (envIsHomebrew())
__system_retAddr = retAddr;
}
/* Initialize the synchronization subsystem */
__sync_init();

View File

@ -28,11 +28,12 @@ void GPU_Reset(u32* gxbuf, u32* gpuBuf, u32 gpuBufSize)
void GPU_SetFloatUniform(GPU_SHADER_TYPE type,
u32 startreg, u32* data, u32 numreg)
{
int regOffset;
if(!data)
int regOffset = 0x0;;
if (!data)
return;
regOffset = (type == GPU_GEOMETRY_SHADER) ? (-0x30) : (0x0);
if (type == GPU_GEOMETRY_SHADER)
regOffset = (-0x30);
GPUCMD_AddWrite(GPUREG_VSH_FLOATUNIFORM_CONFIG+regOffset,
0x80000000 | startreg);
@ -153,28 +154,28 @@ void GPU_SetTextureEnable(GPU_TEXUNIT units)
void GPU_SetTexture(GPU_TEXUNIT unit, u32* data, u16 width, u16 height, u32 param, GPU_TEXCOLOR colorType)
{
switch (unit)
{
case GPU_TEXUNIT0:
GPUCMD_AddWrite(GPUREG_TEXUNIT0_TYPE, colorType);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_ADDR1, ((u32)data) >> 3);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_DIM, (width << 16)|height);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_PARAM, param);
break;
{
case GPU_TEXUNIT0:
GPUCMD_AddWrite(GPUREG_TEXUNIT0_TYPE, colorType);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_ADDR1, ((u32)data) >> 3);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_DIM, (width << 16)|height);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_PARAM, param);
break;
case GPU_TEXUNIT1:
GPUCMD_AddWrite(GPUREG_TEXUNIT1_TYPE, colorType);
GPUCMD_AddWrite(GPUREG_TEXUNIT1_ADDR, ((u32)data) >> 3);
GPUCMD_AddWrite(GPUREG_TEXUNIT1_DIM, (width << 16)|height);
GPUCMD_AddWrite(GPUREG_TEXUNIT1_PARAM, param);
break;
case GPU_TEXUNIT1:
GPUCMD_AddWrite(GPUREG_TEXUNIT1_TYPE, colorType);
GPUCMD_AddWrite(GPUREG_TEXUNIT1_ADDR, ((u32)data) >> 3);
GPUCMD_AddWrite(GPUREG_TEXUNIT1_DIM, (width << 16)|height);
GPUCMD_AddWrite(GPUREG_TEXUNIT1_PARAM, param);
break;
case GPU_TEXUNIT2:
GPUCMD_AddWrite(GPUREG_TEXUNIT2_TYPE, colorType);
GPUCMD_AddWrite(GPUREG_TEXUNIT2_ADDR, ((u32)data) >> 3);
GPUCMD_AddWrite(GPUREG_TEXUNIT2_DIM, (width << 16)|height);
GPUCMD_AddWrite(GPUREG_TEXUNIT2_PARAM, param);
break;
}
case GPU_TEXUNIT2:
GPUCMD_AddWrite(GPUREG_TEXUNIT2_TYPE, colorType);
GPUCMD_AddWrite(GPUREG_TEXUNIT2_ADDR, ((u32)data) >> 3);
GPUCMD_AddWrite(GPUREG_TEXUNIT2_DIM, (width << 16)|height);
GPUCMD_AddWrite(GPUREG_TEXUNIT2_PARAM, param);
break;
}
}
void GPU_SetTextureBorderColor(GPU_TEXUNIT unit,u32 borderColor)
@ -266,7 +267,6 @@ void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16
u32 param[0x5];
if(id > 6)
return;
memset(param, 0x00, 5*4);
param[0x0] = (alphaSources << 16) | (rgbSources);
param[0x1] = (alphaOperands << 12) | (rgbOperands);

View File

@ -217,7 +217,8 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur,
if (!string_is_empty(val_string))
db_info->franchise = strdup(val_string);
}
else if (string_ends_with(str, "_rating"))
else if (string_ends_with_size(str, "_rating",
strlen(str), STRLEN_CONST("_rating")))
{
if (string_is_equal(str, "bbfc_rating"))
{
@ -364,7 +365,7 @@ database_info_handle_t *database_info_dir_init(const char *dir,
core_info_list_t *core_info_list = NULL;
struct string_list *list = NULL;
database_info_handle_t *db = (database_info_handle_t*)
calloc(1, sizeof(*db));
malloc(sizeof(*db));
if (!db)
return NULL;
@ -383,10 +384,10 @@ database_info_handle_t *database_info_dir_init(const char *dir,
dir_list_prioritize(list);
db->list = list;
db->list_ptr = 0;
db->status = DATABASE_STATUS_ITERATE;
db->type = type;
db->status = DATABASE_STATUS_ITERATE;
db->type = type;
db->list_ptr = 0;
db->list = list;
return db;
}
@ -397,7 +398,7 @@ database_info_handle_t *database_info_file_init(const char *path,
union string_list_elem_attr attr;
struct string_list *list = NULL;
database_info_handle_t *db = (database_info_handle_t*)
calloc(1, sizeof(*db));
malloc(sizeof(*db));
if (!db)
return NULL;
@ -414,10 +415,10 @@ database_info_handle_t *database_info_file_init(const char *path,
string_list_append(list, path, attr);
db->list_ptr = 0;
db->list = list;
db->status = DATABASE_STATUS_ITERATE;
db->type = type;
db->status = DATABASE_STATUS_ITERATE;
db->type = type;
db->list_ptr = 0;
db->list = list;
return db;
}
@ -498,6 +499,10 @@ database_info_list_t *database_info_list_new(
free(db_info.rom_name);
if (db_info.serial)
free(db_info.serial);
if (db_info.md5)
free(db_info.md5);
if (db_info.sha1)
free(db_info.sha1);
database_info_list_free(database_info_list);
free(database_info);
free(database_info_list);

View File

@ -76,7 +76,6 @@ typedef struct
enum database_type type;
size_t list_ptr;
struct string_list *list;
file_archive_transfer_t state;
} database_info_handle_t;
typedef struct

557
deps/7zip/7zDec.c vendored
View File

@ -23,44 +23,60 @@
#define k_SPARC 0x03030805
#define k_BCJ2 0x0303011B
static SRes SzDecodeLzma(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *inStream,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
static SRes SzDecodeLzma(CSzCoderInfo *coder,
uint64_t inSize, ILookInStream *inStream,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
int result;
CLzmaDec state;
SRes res = SZ_OK;
SRes res = SZ_OK;
LzmaDec_Construct(&state);
RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
state.dic = outBuffer;
result = LzmaDec_AllocateProbs(
&state, coder->Props.data,
(unsigned)coder->Props.size, allocMain);
if (result != 0)
return result;
state.dic = outBuffer;
state.dicBufSize = outSize;
LzmaDec_Init(&state);
for (;;)
{
uint8_t *inBuf = NULL;
uint8_t *inBuf = NULL;
size_t lookahead = (1 << 18);
if (lookahead > inSize)
lookahead = (size_t)inSize;
res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
lookahead = (size_t)inSize;
res = inStream->Look(
(void *)inStream, (const void **)&inBuf, &lookahead);
if (res != SZ_OK)
break;
{
size_t inProcessed = (size_t)lookahead, dicPos = state.dicPos;
ELzmaStatus status;
res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
lookahead -= inProcessed;
inSize -= inProcessed;
size_t inProcessed = (size_t)lookahead, dicPos = state.dicPos;
res = LzmaDec_DecodeToDic(
&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
lookahead -= inProcessed;
inSize -= inProcessed;
if (res != SZ_OK)
break;
if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
if (
state.dicPos == state.dicBufSize ||
(inProcessed == 0 && dicPos == state.dicPos))
{
if (state.dicBufSize != outSize || lookahead != 0 ||
if (
state.dicBufSize != outSize ||
lookahead != 0 ||
(status != LZMA_STATUS_FINISHED_WITH_MARK &&
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
res = SZ_ERROR_DATA;
break;
}
res = inStream->Skip((void *)inStream, inProcessed);
if (res != SZ_OK)
break;
@ -71,153 +87,185 @@ static SRes SzDecodeLzma(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *in
return res;
}
static SRes SzDecodeLzma2(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *inStream,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
static SRes SzDecodeLzma2(CSzCoderInfo *coder,
uint64_t inSize, ILookInStream *inStream,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
CLzma2Dec state;
SRes res = SZ_OK;
int result;
CLzma2Dec state;
SRes res = SZ_OK;
Lzma2Dec_Construct(&state);
if (coder->Props.size != 1)
return SZ_ERROR_DATA;
RINOK(Lzma2Dec_AllocateProbs(&state, coder->Props.data[0], allocMain));
state.decoder.dic = outBuffer;
state.decoder.dicBufSize = outSize;
Lzma2Dec_Init(&state);
Lzma2Dec_Construct(&state);
if (coder->Props.size != 1)
return SZ_ERROR_DATA;
for (;;)
{
uint8_t *inBuf = NULL;
size_t lookahead = (1 << 18);
if (lookahead > inSize)
lookahead = (size_t)inSize;
res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
if (res != SZ_OK)
break;
result = Lzma2Dec_AllocateProbs(&state, coder->Props.data[0], allocMain);
if (result != 0)
return result;
{
size_t inProcessed = (size_t)lookahead, dicPos = state.decoder.dicPos;
ELzmaStatus status;
res = Lzma2Dec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
lookahead -= inProcessed;
inSize -= inProcessed;
state.decoder.dic = outBuffer;
state.decoder.dicBufSize = outSize;
Lzma2Dec_Init(&state);
for (;;)
{
uint8_t *inBuf = NULL;
size_t lookahead = (1 << 18);
if (lookahead > inSize)
lookahead = (size_t)inSize;
res = inStream->Look(
(void *)inStream, (const void **)&inBuf, &lookahead);
if (res != SZ_OK)
break;
if (state.decoder.dicPos == state.decoder.dicBufSize || (inProcessed == 0 && dicPos == state.decoder.dicPos))
break;
{
if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
(status != LZMA_STATUS_FINISHED_WITH_MARK))
res = SZ_ERROR_DATA;
break;
ELzmaStatus status;
size_t inProcessed = (size_t)lookahead, dicPos = state.decoder.dicPos;
res = Lzma2Dec_DecodeToDic(
&state, outSize, inBuf, &inProcessed,
LZMA_FINISH_END, &status);
lookahead -= inProcessed;
inSize -= inProcessed;
if (res != SZ_OK)
break;
if (
state.decoder.dicPos == state.decoder.dicBufSize ||
(inProcessed == 0 && dicPos == state.decoder.dicPos))
{
if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
(status != LZMA_STATUS_FINISHED_WITH_MARK))
res = SZ_ERROR_DATA;
break;
}
res = inStream->Skip((void *)inStream, inProcessed);
if (res != SZ_OK)
break;
}
res = inStream->Skip((void *)inStream, inProcessed);
if (res != SZ_OK)
break;
}
}
}
Lzma2Dec_FreeProbs(&state, allocMain);
return res;
Lzma2Dec_FreeProbs(&state, allocMain);
return res;
}
static SRes SzDecodeCopy(uint64_t inSize, ILookInStream *inStream, uint8_t *outBuffer)
static SRes SzDecodeCopy(uint64_t inSize,
ILookInStream *inStream, uint8_t *outBuffer)
{
while (inSize > 0)
{
void *inBuf;
size_t curSize = (1 << 18);
if (curSize > inSize)
curSize = (size_t)inSize;
RINOK(inStream->Look((void *)inStream, (const void **)&inBuf, &curSize));
if (curSize == 0)
return SZ_ERROR_INPUT_EOF;
memcpy(outBuffer, inBuf, curSize);
outBuffer += curSize;
inSize -= curSize;
RINOK(inStream->Skip((void *)inStream, curSize));
}
return SZ_OK;
while (inSize > 0)
{
int result;
void *inBuf = NULL;
size_t curSize = (1 << 18);
if (curSize > inSize)
curSize = (size_t)inSize;
result = inStream->Look(
(void *)inStream, (const void **)&inBuf, &curSize);
if (result != 0)
return result;
if (curSize == 0)
return SZ_ERROR_INPUT_EOF;
memcpy(outBuffer, inBuf, curSize);
outBuffer += curSize;
inSize -= curSize;
result = inStream->Skip((void *)inStream, curSize);
if (result != 0)
return result;
}
return SZ_OK;
}
static bool IS_MAIN_METHOD(uint32_t m)
static bool is_main_method(uint32_t m)
{
switch(m)
{
case k_Copy:
case k_LZMA:
case k_LZMA2:
return true;
}
return false;
switch(m)
{
case k_Copy:
case k_LZMA:
case k_LZMA2:
return true;
default:
break;
}
return false;
}
static bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)
static bool is_supported_coder(const CSzCoderInfo *c)
{
return
c->NumInStreams == 1 &&
c->NumOutStreams == 1 &&
c->MethodID <= (uint32_t)0xFFFFFFFF &&
IS_MAIN_METHOD((uint32_t)c->MethodID);
is_main_method((uint32_t)c->MethodID);
}
#define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumInStreams == 4 && (c)->NumOutStreams == 1)
static SRes CheckSupportedFolder(const CSzFolder *f)
static SRes check_supported_folder(const CSzFolder *f)
{
if (f->NumCoders < 1 || f->NumCoders > 4)
return SZ_ERROR_UNSUPPORTED;
if (!IS_SUPPORTED_CODER(&f->Coders[0]))
if (!is_supported_coder(&f->Coders[0]))
return SZ_ERROR_UNSUPPORTED;
if (f->NumCoders == 1)
switch (f->NumCoders)
{
if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)
return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
if (f->NumCoders == 2)
{
CSzCoderInfo *c = &f->Coders[1];
if (c->MethodID > (uint32_t)0xFFFFFFFF ||
c->NumInStreams != 1 ||
c->NumOutStreams != 1 ||
f->NumPackStreams != 1 ||
f->PackStreams[0] != 0 ||
f->NumBindPairs != 1 ||
f->BindPairs[0].InIndex != 1 ||
f->BindPairs[0].OutIndex != 0)
return SZ_ERROR_UNSUPPORTED;
switch ((uint32_t)c->MethodID)
{
case k_BCJ:
case k_ARM:
break;
default:
return SZ_ERROR_UNSUPPORTED;
}
return SZ_OK;
}
if (f->NumCoders == 4)
{
if (!IS_SUPPORTED_CODER(&f->Coders[1]) ||
!IS_SUPPORTED_CODER(&f->Coders[2]) ||
!IS_BCJ2(&f->Coders[3]))
return SZ_ERROR_UNSUPPORTED;
if (f->NumPackStreams != 4 ||
f->PackStreams[0] != 2 ||
f->PackStreams[1] != 6 ||
f->PackStreams[2] != 1 ||
f->PackStreams[3] != 0 ||
f->NumBindPairs != 3 ||
f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||
f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||
f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)
return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
case 1:
if ( f->NumPackStreams != 1
|| f->PackStreams[0] != 0
|| f->NumBindPairs != 0)
return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
case 2:
{
CSzCoderInfo *c = &f->Coders[1];
if (c->MethodID > (uint32_t)0xFFFFFFFF ||
c->NumInStreams != 1 ||
c->NumOutStreams != 1 ||
f->NumPackStreams != 1 ||
f->PackStreams[0] != 0 ||
f->NumBindPairs != 1 ||
f->BindPairs[0].InIndex != 1 ||
f->BindPairs[0].OutIndex != 0)
return SZ_ERROR_UNSUPPORTED;
switch ((uint32_t)c->MethodID)
{
case k_BCJ:
case k_ARM:
break;
default:
return SZ_ERROR_UNSUPPORTED;
}
}
return SZ_OK;
case 4:
if (!is_supported_coder(&f->Coders[1]) ||
!is_supported_coder(&f->Coders[2]) ||
!IS_BCJ2(&f->Coders[3]))
return SZ_ERROR_UNSUPPORTED;
if (f->NumPackStreams != 4 ||
f->PackStreams[0] != 2 ||
f->PackStreams[1] != 6 ||
f->PackStreams[2] != 1 ||
f->PackStreams[3] != 0 ||
f->NumBindPairs != 3 ||
f->BindPairs[0].InIndex != 5 ||
f->BindPairs[0].OutIndex != 0 ||
f->BindPairs[1].InIndex != 4 ||
f->BindPairs[1].OutIndex != 1 ||
f->BindPairs[2].InIndex != 3 ||
f->BindPairs[2].OutIndex != 2)
return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
return SZ_ERROR_UNSUPPORTED;
}
static uint64_t GetSum(const uint64_t *values, uint32_t idx)
static uint64_t get_sum(const uint64_t *values, uint32_t idx)
{
uint64_t sum = 0;
uint32_t i;
@ -226,134 +274,169 @@ static uint64_t GetSum(const uint64_t *values, uint32_t idx)
return sum;
}
#define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break;
static SRes SzFolder_Decode2(const CSzFolder *folder, const uint64_t *packSizes,
ILookInStream *inStream, uint64_t startPos,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain,
uint8_t *tempBuf[])
static SRes SzFolder_Decode2(const CSzFolder *folder,
const uint64_t *packSizes,
ILookInStream *inStream, uint64_t startPos,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain,
uint8_t *tempBuf[])
{
uint32_t ci;
size_t tempSizes[3] = { 0, 0, 0};
size_t tempSize3 = 0;
uint8_t *tempBuf3 = 0;
uint32_t ci;
size_t tempSizes[3] = { 0, 0, 0};
size_t tempSize3 = 0;
uint8_t *tempBuf3 = 0;
int result = check_supported_folder(folder);
RINOK(CheckSupportedFolder(folder));
if (result != 0)
return result;
for (ci = 0; ci < folder->NumCoders; ci++)
{
CSzCoderInfo *coder = &folder->Coders[ci];
for (ci = 0; ci < folder->NumCoders; ci++)
{
CSzCoderInfo *coder = &folder->Coders[ci];
if (IS_MAIN_METHOD((uint32_t)coder->MethodID))
{
uint32_t si = 0;
uint64_t offset;
uint64_t inSize;
uint8_t *outBufCur = outBuffer;
size_t outSizeCur = outSize;
if (folder->NumCoders == 4)
if (is_main_method((uint32_t)coder->MethodID))
{
uint32_t indices[] = { 3, 2, 0 };
uint64_t unpackSize = folder->UnpackSizes[ci];
si = indices[ci];
if (ci < 2)
{
uint8_t *temp;
outSizeCur = (size_t)unpackSize;
if (outSizeCur != unpackSize)
int result;
uint64_t offset = 0;
uint64_t inSize = 0;
uint32_t si = 0;
uint8_t *outBufCur = outBuffer;
size_t outSizeCur = outSize;
if (folder->NumCoders == 4)
{
uint32_t indices[] = { 3, 2, 0 };
uint64_t unpackSize = folder->UnpackSizes[ci];
si = indices[ci];
if (ci < 2)
{
uint8_t *temp;
outSizeCur = (size_t)unpackSize;
if (outSizeCur != unpackSize)
return SZ_ERROR_MEM;
temp = (uint8_t *)IAlloc_Alloc(allocMain, outSizeCur);
if (temp == 0 && outSizeCur != 0)
return SZ_ERROR_MEM;
outBufCur = tempBuf[1 - ci] = temp;
tempSizes[1 - ci] = outSizeCur;
}
else if (ci == 2)
{
if (unpackSize > outSize) /* check it */
return SZ_ERROR_PARAM;
tempBuf3 = outBufCur = outBuffer
+ (outSize - (size_t)unpackSize);
tempSize3 = outSizeCur = (size_t)unpackSize;
}
else
return SZ_ERROR_UNSUPPORTED;
}
offset = get_sum(packSizes, si);
inSize = packSizes[si];
result = LookInStream_SeekTo(inStream, startPos + offset);
if (result != 0)
return result;
switch (coder->MethodID)
{
case k_Copy:
if (inSize != outSizeCur) /* check it */
return SZ_ERROR_DATA;
result = SzDecodeCopy(inSize, inStream, outBufCur);
if (result != 0)
return result;
break;
case k_LZMA:
result = SzDecodeLzma(
coder, inSize, inStream,
outBufCur, outSizeCur, allocMain);
if (result != 0)
return result;
break;
case k_LZMA2:
result = SzDecodeLzma2(
coder, inSize, inStream,
outBufCur, outSizeCur, allocMain);
if (result != 0)
return result;
break;
default:
return SZ_ERROR_UNSUPPORTED;
}
}
else if (coder->MethodID == k_BCJ2)
{
SRes res;
int result;
uint64_t offset = get_sum(packSizes, 1);
uint64_t s3Size = packSizes[1];
if (ci != 3)
return SZ_ERROR_UNSUPPORTED;
result = LookInStream_SeekTo(inStream, startPos + offset);
if (result != 0)
return result;
tempSizes[2] = (size_t)s3Size;
if (tempSizes[2] != s3Size)
return SZ_ERROR_MEM;
temp = (uint8_t *)IAlloc_Alloc(allocMain, outSizeCur);
if (temp == 0 && outSizeCur != 0)
return SZ_ERROR_MEM;
outBufCur = tempBuf[1 - ci] = temp;
tempSizes[1 - ci] = outSizeCur;
}
else if (ci == 2)
{
if (unpackSize > outSize) /* check it */
return SZ_ERROR_PARAM;
tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
tempSize3 = outSizeCur = (size_t)unpackSize;
}
else
return SZ_ERROR_UNSUPPORTED;
}
offset = GetSum(packSizes, si);
inSize = packSizes[si];
RINOK(LookInStream_SeekTo(inStream, startPos + offset));
if (coder->MethodID == k_Copy)
{
if (inSize != outSizeCur) /* check it */
return SZ_ERROR_DATA;
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
}
else if (coder->MethodID == k_LZMA)
{
RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
}
else if (coder->MethodID == k_LZMA2)
{
RINOK(SzDecodeLzma2(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
tempBuf[2] = (uint8_t *)IAlloc_Alloc(allocMain, tempSizes[2]);
if (tempBuf[2] == 0 && tempSizes[2] != 0)
return SZ_ERROR_MEM;
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
if (res != 0)
return res;
res = Bcj2_Decode(
tempBuf3, tempSize3,
tempBuf[0], tempSizes[0],
tempBuf[1], tempSizes[1],
tempBuf[2], tempSizes[2],
outBuffer, outSize);
if (res != 0)
return res;
}
else
return SZ_ERROR_UNSUPPORTED;
}
else if (coder->MethodID == k_BCJ2)
{
uint64_t offset = GetSum(packSizes, 1);
uint64_t s3Size = packSizes[1];
SRes res;
if (ci != 3)
return SZ_ERROR_UNSUPPORTED;
RINOK(LookInStream_SeekTo(inStream, startPos + offset));
tempSizes[2] = (size_t)s3Size;
if (tempSizes[2] != s3Size)
return SZ_ERROR_MEM;
tempBuf[2] = (uint8_t *)IAlloc_Alloc(allocMain, tempSizes[2]);
if (tempBuf[2] == 0 && tempSizes[2] != 0)
return SZ_ERROR_MEM;
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
RINOK(res)
res = Bcj2_Decode(
tempBuf3, tempSize3,
tempBuf[0], tempSizes[0],
tempBuf[1], tempSizes[1],
tempBuf[2], tempSizes[2],
outBuffer, outSize);
RINOK(res)
}
else
{
if (ci != 1)
return SZ_ERROR_UNSUPPORTED;
switch(coder->MethodID)
{
case k_BCJ:
{
uint32_t state;
x86_Convert_Init(state);
x86_Convert(outBuffer, outSize, 0, &state, 0);
break;
}
CASE_BRA_CONV(ARM)
default:
return SZ_ERROR_UNSUPPORTED;
if (ci != 1)
return SZ_ERROR_UNSUPPORTED;
switch(coder->MethodID)
{
case k_BCJ:
{
uint32_t state;
x86_Convert_Init(state);
x86_Convert(outBuffer, outSize, 0, &state, 0);
break;
}
case k_ARM:
ARM_Convert(outBuffer, outSize, 0, 0);
break;
default:
return SZ_ERROR_UNSUPPORTED;
}
}
}
}
return SZ_OK;
}
return SZ_OK;
}
SRes SzFolder_Decode(const CSzFolder *folder, const uint64_t *packSizes,
ILookInStream *inStream, uint64_t startPos,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
uint8_t *tempBuf[3] = { 0, 0, 0};
int i;
SRes res = SzFolder_Decode2(folder, packSizes, inStream, startPos,
outBuffer, (size_t)outSize, allocMain, tempBuf);
uint8_t *tempBuf[3] = { 0, 0, 0};
SRes res = SzFolder_Decode2(folder,
packSizes, inStream, startPos,
outBuffer, (size_t)outSize, allocMain, tempBuf);
for (i = 0; i < 3; i++)
IAlloc_Free(allocMain, tempBuf[i]);
return res;

217
deps/7zip/7zFile.c vendored
View File

@ -2,236 +2,110 @@
2009-11-24 : Igor Pavlov : Public domain */
#include <stdint.h>
#define SKIP_STDIO_REDEFINES
#include <streams/file_stream_transforms.h>
#include "7zFile.h"
#ifndef USE_WINDOWS_FILE
#ifndef UNDER_CE
#include <errno.h>
#endif
#else
/*
ReadFile and WriteFile functions in Windows have BUG:
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
(Insufficient system resources exist to complete the requested service).
Probably in some version of Windows there are problems with other sizes:
for 32 MB (maybe also for 16 MB).
And message can be "Network connection was lost"
*/
#define kChunkSizeMax (1 << 22)
#endif
void File_Construct(CSzFile *p)
{
#ifdef USE_WINDOWS_FILE
p->handle = INVALID_HANDLE_VALUE;
#else
p->file = NULL;
#endif
}
#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
{
#ifdef USE_WINDOWS_FILE
p->handle = CreateFileA(name,
writeMode ? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ, NULL,
writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
#else
p->file = fopen(name, writeMode ? "wb+" : "rb");
return (p->file != 0) ? 0 :
p->file = rfopen(name, writeMode ? "wb+" : "rb");
if (!p->file)
{
#ifdef UNDER_CE
2; /* ENOENT */
return 2; /* ENOENT */
#else
errno;
#endif
return errno;
#endif
}
return 0;
}
WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
#endif
#ifdef USE_WINDOWS_FILE
static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)
WRes InFile_Open(CSzFile *p, const char *name)
{
p->handle = CreateFileW(name,
writeMode ? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ, NULL,
writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
return File_Open(p, name, 0);
}
WRes OutFile_Open(CSzFile *p, const char *name)
{
return File_Open(p, name, 1);
}
WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }
WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); }
#endif
WRes File_Close(CSzFile *p)
{
#ifdef USE_WINDOWS_FILE
if (p->handle != INVALID_HANDLE_VALUE)
if (p->file)
{
if (!CloseHandle(p->handle))
return GetLastError();
p->handle = INVALID_HANDLE_VALUE;
}
#else
if (p->file != NULL)
{
int res = fclose(p->file);
int res = rfclose((RFILE*)p->file);
if (res != 0)
return res;
p->file = NULL;
}
#endif
return 0;
}
WRes File_Read(CSzFile *p, void *data, size_t *size)
{
size_t originalSize = *size;
int64_t originalSize = *size;
if (originalSize == 0)
return 0;
#ifdef USE_WINDOWS_FILE
*size = 0;
do
{
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0;
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((uint8_t*)data + processed);
originalSize -= processed;
*size += processed;
if (!res)
return GetLastError();
if (processed == 0)
break;
}
while (originalSize > 0);
return 0;
#else
*size = fread(data, 1, originalSize, p->file);
*size = rfread(data, 1, originalSize, (RFILE*)p->file);
if (*size == originalSize)
return 0;
return ferror(p->file);
#endif
return rferror((RFILE*)p->file);
}
WRes File_Write(CSzFile *p, const void *data, size_t *size)
{
size_t originalSize = *size;
int64_t originalSize = *size;
if (originalSize == 0)
return 0;
#ifdef USE_WINDOWS_FILE
*size = 0;
do
{
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0;
BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((uint8_t*)data + processed);
originalSize -= processed;
*size += processed;
if (!res)
return GetLastError();
if (processed == 0)
break;
}
while (originalSize > 0);
return 0;
#else
*size = fwrite(data, 1, originalSize, p->file);
*size = rfwrite(data, 1, originalSize, (RFILE*)p->file);
if (*size == originalSize)
return 0;
return ferror(p->file);
#endif
return rferror((RFILE*)p->file);
}
WRes File_Seek(CSzFile *p, int64_t *pos, ESzSeek origin)
{
#ifdef USE_WINDOWS_FILE
LARGE_INTEGER value;
DWORD moveMethod;
value.LowPart = (DWORD)*pos;
value.HighPart = (LONG)((uint64_t)*pos >> 16 >> 16); /* for case when uint64_t is 32-bit only */
int whence;
int64_t res;
switch (origin)
{
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
case SZ_SEEK_END: moveMethod = FILE_END; break;
default: return ERROR_INVALID_PARAMETER;
case SZ_SEEK_SET:
whence = SEEK_SET;
break;
case SZ_SEEK_CUR:
whence = SEEK_CUR;
break;
case SZ_SEEK_END:
whence = SEEK_END;
break;
default:
return 1;
}
value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
if (value.LowPart == 0xFFFFFFFF)
{
WRes res = GetLastError();
if (res != NO_ERROR)
return res;
}
*pos = ((int64_t)value.HighPart << 32) | value.LowPart;
return 0;
#else
int moveMethod;
int res;
switch (origin)
{
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
case SZ_SEEK_END: moveMethod = SEEK_END; break;
default: return 1;
}
res = fseek(p->file, (long)*pos, moveMethod);
*pos = ftell(p->file);
res = rfseek((RFILE*)p->file, (int64_t)*pos, whence);
*pos = rftell((RFILE*)p->file);
return res;
#endif
}
WRes File_GetLength(CSzFile *p, uint64_t *length)
{
#ifdef USE_WINDOWS_FILE
DWORD sizeHigh;
DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
if (sizeLow == 0xFFFFFFFF)
{
DWORD res = GetLastError();
if (res != NO_ERROR)
return res;
}
*length = (((uint64_t)sizeHigh) << 32) + sizeLow;
return 0;
#else
long pos = ftell(p->file);
int res = fseek(p->file, 0, SEEK_END);
*length = ftell(p->file);
fseek(p->file, pos, SEEK_SET);
int64_t pos = rftell((RFILE*)p->file);
int64_t res = rfseek((RFILE*)p->file, 0, SEEK_END);
*length = rftell((RFILE*)p->file);
rfseek((RFILE*)p->file, pos, SEEK_SET);
return res;
#endif
}
@ -248,7 +122,6 @@ void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
p->s.Read = FileSeqInStream_Read;
}
/* ---------- FileInStream ---------- */
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
@ -283,3 +156,5 @@ void FileOutStream_CreateVTable(CFileOutStream *p)
{
p->s.Write = FileOutStream_Write;
}
#undef SKIP_STDIO_REDEFINES

20
deps/7zip/7zFile.h vendored
View File

@ -4,15 +4,7 @@
#ifndef __7Z_FILE_H
#define __7Z_FILE_H
#ifdef _WIN32
#define USE_WINDOWS_FILE
#endif
#ifdef USE_WINDOWS_FILE
#include <windows.h>
#else
#include <stdio.h>
#endif
#include "7zTypes.h"
@ -24,22 +16,12 @@ extern "C" {
typedef struct
{
#ifdef USE_WINDOWS_FILE
HANDLE handle;
#else
FILE *file;
#endif
void *file;
} CSzFile;
void File_Construct(CSzFile *p);
#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
WRes InFile_Open(CSzFile *p, const char *name);
WRes OutFile_Open(CSzFile *p, const char *name);
#endif
#ifdef USE_WINDOWS_FILE
WRes InFile_OpenW(CSzFile *p, const WCHAR *name);
WRes OutFile_OpenW(CSzFile *p, const WCHAR *name);
#endif
WRes File_Close(CSzFile *p);
/* reads max(*size, remain file's size) bytes */

780
deps/7zip/7zIn.c vendored

File diff suppressed because it is too large Load Diff

41
deps/7zip/7zStream.c vendored
View File

@ -7,18 +7,29 @@
#include "7zTypes.h"
SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf);
SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf)
{
size_t processed = 1;
int result = stream->Read(stream, buf, &processed);
if (result != 0)
return result;
if (processed != 1)
return SZ_ERROR_INPUT_EOF;
return SZ_OK;
}
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
{
while (size != 0)
{
size_t processed = size;
RINOK(stream->Read(stream, buf, &processed));
int result = stream->Read(stream, buf, &processed);
if (result != 0)
return result;
if (processed == 0)
return errorType;
buf = (void *)((uint8_t *)buf + processed);
size -= processed;
buf = (void *)((uint8_t *)buf + processed);
size -= processed;
}
return SZ_OK;
}
@ -28,12 +39,6 @@ SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
}
SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf)
{
size_t processed = 1;
RINOK(stream->Read(stream, buf, &processed));
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
}
SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset)
{
@ -43,24 +48,30 @@ SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset)
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
{
int result;
const void *lookBuf;
if (*size == 0)
return SZ_OK;
RINOK(stream->Look(stream, &lookBuf, size));
result = stream->Look(stream, &lookBuf, size);
if (result != 0)
return result;
memcpy(buf, lookBuf, *size);
return stream->Skip(stream, *size);
}
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
SRes LookInStream_Read2(ILookInStream *stream,
void *buf, size_t size, SRes errorType)
{
while (size != 0)
{
size_t processed = size;
RINOK(stream->Read(stream, buf, &processed));
int result = stream->Read(stream, buf, &processed);
if (result != 0)
return result;
if (processed == 0)
return errorType;
buf = (void *)((uint8_t *)buf + processed);
size -= processed;
buf = (void *)((uint8_t *)buf + processed);
size -= processed;
}
return SZ_OK;
}

8
deps/7zip/7zTypes.h vendored
View File

@ -41,13 +41,9 @@ EXTERN_C_BEGIN
#define SZ_ERROR_ARCHIVE 16
#define SZ_ERROR_NO_ARCHIVE 17
typedef int SRes;
typedef int64_t SRes;
#ifdef _WIN32
typedef unsigned WRes;
#else
typedef int WRes;
#endif
typedef int64_t WRes;
#ifndef RINOK
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }

24
deps/7zip/CpuArch.h vendored
View File

@ -11,9 +11,10 @@
extern "C" {
#endif
/*
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
/* MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and
CPU supports unaligned memory accesses.
If MY_CPU_LE_UNALIGN is not defined, we don't know
about these properties of platform.
*/
#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
@ -48,23 +49,6 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
#define MY_CPU_LE_UNALIGN
#endif
#ifdef MY_CPU_LE_UNALIGN
#define GetUi16(p) (*(const uint16_t *)(p))
#define GetUi32(p) (*(const uint32_t *)(p))
#define GetUi64(p) (*(const uint64_t *)(p))
#else
#define GetUi16(p) (((const uint8_t *)(p))[0] | ((uint16_t)((const uint8_t *)(p))[1] << 8))
#define GetUi32(p) ( \
((const uint8_t *)(p))[0] | \
((uint32_t)((const uint8_t *)(p))[1] << 8) | \
((uint32_t)((const uint8_t *)(p))[2] << 16) | \
((uint32_t)((const uint8_t *)(p))[3] << 24))
#define GetUi64(p) (GetUi32(p) | ((uint64_t)GetUi32(((const uint8_t *)(p)) + 4) << 32))
#endif
#ifdef __cplusplus
}
#endif

22
deps/7zip/Lzma2Dec.c vendored
View File

@ -66,14 +66,18 @@ static SRes Lzma2Dec_GetOldProps(uint8_t prop, uint8_t *props)
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, uint8_t prop, ISzAlloc *alloc)
{
uint8_t props[LZMA_PROPS_SIZE];
RINOK(Lzma2Dec_GetOldProps(prop, props));
int result = Lzma2Dec_GetOldProps(prop, props);
if (result != 0)
return result;
return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
}
SRes Lzma2Dec_Allocate(CLzma2Dec *p, uint8_t prop, ISzAlloc *alloc)
{
uint8_t props[LZMA_PROPS_SIZE];
RINOK(Lzma2Dec_GetOldProps(prop, props));
int result = Lzma2Dec_GetOldProps(prop, props);
if (result != 0)
return result;
return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
}
@ -259,7 +263,8 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, size_t dicLimit,
outSizeProcessed = p->decoder.dicPos - dicPos;
p->unpackSize -= (uint32_t)outSizeProcessed;
RINOK(res);
if (res != 0)
return res;
if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
return res;
@ -321,8 +326,9 @@ SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, uint8_t *dest, size_t *destLen, const ui
SRes Lzma2Decode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
uint8_t prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
{
CLzma2Dec decoder;
SRes res;
int result;
CLzma2Dec decoder;
size_t outSize = *destLen, inSize = *srcLen;
uint8_t props[LZMA_PROPS_SIZE];
@ -333,8 +339,12 @@ SRes Lzma2Decode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *src
decoder.decoder.dic = dest;
decoder.decoder.dicBufSize = outSize;
RINOK(Lzma2Dec_GetOldProps(prop, props));
RINOK(LzmaDec_AllocateProbs(&decoder.decoder, props, LZMA_PROPS_SIZE, alloc));
result = Lzma2Dec_GetOldProps(prop, props);
if (result != 0)
return result;
result = LzmaDec_AllocateProbs(&decoder.decoder, props, LZMA_PROPS_SIZE, alloc);
if (result != 0)
return result;
*srcLen = inSize;
res = Lzma2Dec_DecodeToDic(&decoder, outSize, src, srcLen, finishMode, status);

395
deps/7zip/LzmaDec.c vendored
View File

@ -494,6 +494,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uin
{
do
{
int result;
size_t limit2 = limit;
if (p->checkDicSize == 0)
{
@ -501,12 +502,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uin
if (limit - p->dicPos > rem)
limit2 = p->dicPos + rem;
}
RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
result = LzmaDec_DecodeReal(p, limit2, bufLimit);
if (result != 0)
return result;
if (p->processedPos >= p->prop.dicSize)
p->checkDicSize = p->prop.dicSize;
LzmaDec_WriteRem(p, limit);
}
while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
while (
p->dicPos < limit &&
p->buf < bufLimit &&
p->remainLen < kMatchSpecLenStart);
if (p->remainLen > kMatchSpecLenStart)
{
@ -517,101 +523,108 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uin
typedef enum
{
DUMMY_ERROR, /* unexpected end of input stream */
DUMMY_ERROR = 0, /* unexpected end of input stream */
DUMMY_LIT,
DUMMY_MATCH,
DUMMY_REP
} ELzmaDummy;
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t inSize)
static ELzmaDummy LzmaDec_TryDummy(
const CLzmaDec *p, const uint8_t *buf, size_t inSize)
{
uint32_t range = p->range;
uint32_t codes = p->code;
const uint8_t *bufLimit = buf + inSize;
uint16_t *probs = p->probs;
unsigned state = p->state;
ELzmaDummy res;
uint32_t bound;
unsigned ttt;
uint32_t range = p->range;
uint32_t codes = p->code;
const uint8_t *bufLimit = buf + inSize;
uint16_t *probs = p->probs;
unsigned state = p->state;
unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
uint16_t *prob = probs + IsMatch +
(state << kNumPosBitsMax) + posState;
IF_BIT_0_CHECK(prob)
{
uint16_t *prob;
uint32_t bound;
unsigned ttt;
unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
UPDATE_0_CHECK
prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
IF_BIT_0_CHECK(prob)
/* if (bufLimit - buf >= 7) return DUMMY_LIT; */
prob = probs + Literal;
if (p->checkDicSize != 0 || p->processedPos != 0)
prob += (LZMA_LIT_SIZE *
((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
(p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
if (state < kNumLitStates)
{
UPDATE_0_CHECK
/* if (bufLimit - buf >= 7) return DUMMY_LIT; */
prob = probs + Literal;
if (p->checkDicSize != 0 || p->processedPos != 0)
prob += (LZMA_LIT_SIZE *
((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
(p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
if (state < kNumLitStates)
{
unsigned symbol = 1;
do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
}
else
{
unsigned matchuint8_t = p->dic[p->dicPos - p->reps[0] +
((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
unsigned offs = 0x100;
unsigned symbol = 1;
do
{
unsigned bit;
uint16_t *probLit;
matchuint8_t <<= 1;
bit = (matchuint8_t & offs);
probLit = prob + offs + bit + symbol;
GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
}
while (symbol < 0x100);
}
res = DUMMY_LIT;
unsigned symbol = 1;
do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
}
else
{
unsigned len;
UPDATE_1_CHECK;
unsigned matchuint8_t = p->dic[p->dicPos - p->reps[0] +
((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
unsigned offs = 0x100;
unsigned symbol = 1;
do
{
unsigned bit;
uint16_t *probLit;
matchuint8_t <<= 1;
bit = (matchuint8_t & offs);
probLit = prob + offs + bit + symbol;
GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
}
while (symbol < 0x100);
}
res = DUMMY_LIT;
}
else
{
unsigned len;
UPDATE_1_CHECK;
prob = probs + IsRep + state;
prob = probs + IsRep + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
state = 0;
prob = probs + LenCoder;
res = DUMMY_MATCH;
}
else
{
UPDATE_1_CHECK;
res = DUMMY_REP;
prob = probs + IsRepG0 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
state = 0;
prob = probs + LenCoder;
res = DUMMY_MATCH;
prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
NORMALIZE_CHECK;
return DUMMY_REP;
}
else
{
UPDATE_1_CHECK;
}
}
else
{
UPDATE_1_CHECK;
res = DUMMY_REP;
prob = probs + IsRepG0 + state;
prob = probs + IsRepG1 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
NORMALIZE_CHECK;
return DUMMY_REP;
}
else
{
UPDATE_1_CHECK;
}
}
else
{
UPDATE_1_CHECK;
prob = probs + IsRepG1 + state;
prob = probs + IsRepG2 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
@ -619,92 +632,83 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t
else
{
UPDATE_1_CHECK;
prob = probs + IsRepG2 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
}
else
{
UPDATE_1_CHECK;
}
}
}
state = kNumStates;
prob = probs + RepLenCoder;
}
state = kNumStates;
prob = probs + RepLenCoder;
}
{
unsigned limit, offset;
uint16_t *probLen = prob + LenChoice;
IF_BIT_0_CHECK(probLen)
{
unsigned limit, offset;
uint16_t *probLen = prob + LenChoice;
UPDATE_0_CHECK;
probLen = prob + LenLow + (posState << kLenNumLowBits);
offset = 0;
limit = 1 << kLenNumLowBits;
}
else
{
UPDATE_1_CHECK;
probLen = prob + LenChoice2;
IF_BIT_0_CHECK(probLen)
{
UPDATE_0_CHECK;
probLen = prob + LenLow + (posState << kLenNumLowBits);
offset = 0;
limit = 1 << kLenNumLowBits;
probLen = prob + LenMid + (posState << kLenNumMidBits);
offset = kLenNumLowSymbols;
limit = 1 << kLenNumMidBits;
}
else
{
UPDATE_1_CHECK;
probLen = prob + LenChoice2;
IF_BIT_0_CHECK(probLen)
{
UPDATE_0_CHECK;
probLen = prob + LenMid + (posState << kLenNumMidBits);
offset = kLenNumLowSymbols;
limit = 1 << kLenNumMidBits;
}
else
{
UPDATE_1_CHECK;
probLen = prob + LenHigh;
offset = kLenNumLowSymbols + kLenNumMidSymbols;
limit = 1 << kLenNumHighBits;
}
probLen = prob + LenHigh;
offset = kLenNumLowSymbols + kLenNumMidSymbols;
limit = 1 << kLenNumHighBits;
}
TREE_DECODE_CHECK(probLen, limit, len);
len += offset;
}
TREE_DECODE_CHECK(probLen, limit, len);
len += offset;
}
if (state < 4)
if (state < 4)
{
unsigned posSlot;
prob = probs + PosSlot +
((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
kNumPosSlotBits);
TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
if (posSlot >= kStartPosModelIndex)
{
unsigned posSlot;
prob = probs + PosSlot +
((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
kNumPosSlotBits);
TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
if (posSlot >= kStartPosModelIndex)
int numDirectBits = ((posSlot >> 1) - 1);
/* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
if (posSlot < kEndPosModelIndex)
{
int numDirectBits = ((posSlot >> 1) - 1);
/* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
if (posSlot < kEndPosModelIndex)
prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
}
else
{
numDirectBits -= kNumAlignBits;
do
{
prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
NORMALIZE_CHECK
range >>= 1;
codes -= range & (((codes - range) >> 31) - 1);
/* if (codes >= range) codes -= range; */
}
else
while (--numDirectBits != 0);
prob = probs + Align;
numDirectBits = kNumAlignBits;
}
{
unsigned i = 1;
do
{
numDirectBits -= kNumAlignBits;
do
{
NORMALIZE_CHECK
range >>= 1;
codes -= range & (((codes - range) >> 31) - 1);
/* if (codes >= range) codes -= range; */
}
while (--numDirectBits != 0);
prob = probs + Align;
numDirectBits = kNumAlignBits;
}
{
unsigned i = 1;
do
{
GET_BIT_CHECK(prob + i, i);
}
while (--numDirectBits != 0);
GET_BIT_CHECK(prob + i, i);
}
while (--numDirectBits != 0);
}
}
}
@ -713,26 +717,27 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t
return res;
}
static void LzmaDec_InitRc(CLzmaDec *p, const uint8_t *data)
{
p->code = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 8) | ((uint32_t)data[4]);
p->range = 0xFFFFFFFF;
p->code = (
(uint32_t)data[1] << 24) |
((uint32_t)data[2] << 16) |
((uint32_t)data[3] << 8) |
((uint32_t)data[4]);
p->range = 0xFFFFFFFF;
p->needFlush = 0;
}
void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState);
void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState)
{
p->needFlush = 1;
p->remainLen = 0;
p->tempBufSize = 0;
p->needFlush = 1;
p->remainLen = 0;
p->tempBufSize = 0;
if (initDic)
{
p->processedPos = 0;
p->checkDicSize = 0;
p->processedPos = 0;
p->checkDicSize = 0;
p->needInitState = 1;
}
if (initState)
@ -747,17 +752,19 @@ void LzmaDec_Init(CLzmaDec *p)
static void LzmaDec_InitStateReal(CLzmaDec *p)
{
uint32_t numProbs = Literal + ((uint32_t)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
uint32_t i;
uint16_t *probs = p->probs;
uint32_t numProbs = Literal +
((uint32_t)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
uint16_t *probs = p->probs;
for (i = 0; i < numProbs; i++)
probs[i] = kBitModelTotal >> 1;
p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
p->state = 0;
p->needInitState = 0;
probs[i] = kBitModelTotal >> 1;
p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
p->state = 0;
p->needInitState = 0;
}
SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_t *srcLen,
SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit,
const uint8_t *src, size_t *srcLen,
ELzmaFinishMode finishMode, ELzmaStatus *status)
{
size_t inSize = *srcLen;
@ -772,7 +779,8 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_
if (p->needFlush != 0)
{
for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE;
(*srcLen)++, inSize--)
p->tempBuf[p->tempBufSize++] = *src++;
if (p->tempBufSize < RC_INIT_SIZE)
{
@ -881,36 +889,37 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{
size_t outSize = *destLen;
size_t inSize = *srcLen;
*srcLen = *destLen = 0;
size_t inSize = *srcLen;
*srcLen = *destLen = 0;
for (;;)
{
size_t inSizeCur = inSize, outSizeCur, dicPos;
ELzmaFinishMode curFinishMode;
SRes res;
ELzmaFinishMode curFinishMode;
size_t inSizeCur = inSize, outSizeCur, dicPos;
if (p->dicPos == p->dicBufSize)
p->dicPos = 0;
dicPos = p->dicPos;
p->dicPos = 0;
dicPos = p->dicPos;
if (outSize > p->dicBufSize - dicPos)
{
outSizeCur = p->dicBufSize;
outSizeCur = p->dicBufSize;
curFinishMode = LZMA_FINISH_ANY;
}
else
{
outSizeCur = dicPos + outSize;
outSizeCur = dicPos + outSize;
curFinishMode = finishMode;
}
res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
src += inSizeCur;
inSize -= inSizeCur;
*srcLen += inSizeCur;
outSizeCur = p->dicPos - dicPos;
res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
src += inSizeCur;
inSize -= inSizeCur;
*srcLen += inSizeCur;
outSizeCur = p->dicPos - dicPos;
memcpy(dest, p->dic + dicPos, outSizeCur);
dest += outSizeCur;
outSize -= outSizeCur;
*destLen += outSizeCur;
dest += outSizeCur;
outSize -= outSizeCur;
*destLen += outSizeCur;
if (res != 0)
return res;
if (outSizeCur == 0 || outSize == 0)
@ -944,25 +953,29 @@ SRes LzmaProps_Decode(CLzmaProps *p, const uint8_t *data, unsigned size)
if (size < LZMA_PROPS_SIZE)
return SZ_ERROR_UNSUPPORTED;
else
dicSize = data[1] | ((uint32_t)data[2] << 8) | ((uint32_t)data[3] << 16) | ((uint32_t)data[4] << 24);
dicSize = data[1] |
((uint32_t)data[2] << 8) |
((uint32_t)data[3] << 16) |
((uint32_t)data[4] << 24);
if (dicSize < LZMA_DIC_MIN)
dicSize = LZMA_DIC_MIN;
p->dicSize = dicSize;
d = data[0];
d = data[0];
if (d >= (9 * 5 * 5))
return SZ_ERROR_UNSUPPORTED;
p->lc = d % 9;
d /= 9;
p->pb = d / 5;
p->lp = d % 5;
p->lc = d % 9;
d /= 9;
p->pb = d / 5;
p->lp = d % 5;
return SZ_OK;
}
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
static SRes LzmaDec_AllocateProbs2(
CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
{
uint32_t numProbs = LzmaProps_GetNumProbs(propNew);
if (p->probs == 0 || numProbs != p->numProbs)
@ -976,22 +989,37 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
return SZ_OK;
}
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
SRes LzmaDec_AllocateProbs(CLzmaDec *p,
const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
{
CLzmaProps propNew;
RINOK(LzmaProps_Decode(&propNew, props, propsSize));
RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
p->prop = propNew;
int result = LzmaProps_Decode(&propNew, props, propsSize);
if (result != 0)
return result;
result = LzmaDec_AllocateProbs2(p, &propNew, alloc);
if (result != 0)
return result;
p->prop = propNew;
return SZ_OK;
}
SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props,
unsigned propsSize, ISzAlloc *alloc)
{
CLzmaProps propNew;
size_t dicBufSize;
RINOK(LzmaProps_Decode(&propNew, props, propsSize));
RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
int result = LzmaProps_Decode(&propNew, props, propsSize);
if (result != 0)
return result;
result = LzmaDec_AllocateProbs2(p, &propNew, alloc);
if (result != 0)
return result;
dicBufSize = propNew.dicSize;
if (p->dic == 0 || dicBufSize != p->dicBufSize)
{
LzmaDec_FreeDict(p, alloc);
@ -1007,7 +1035,8 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISz
return SZ_OK;
}
SRes LzmaDecode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
SRes LzmaDecode(uint8_t *dest, size_t *destLen,
const uint8_t *src, size_t *srcLen,
const uint8_t *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc)
{

1160
deps/7zip/LzmaEnc.c vendored

File diff suppressed because it is too large Load Diff

10
deps/libz/adler32.c vendored
View File

@ -48,17 +48,19 @@
/* ========================================================================= */
uint32_t adler32(uint32_t adler, const uint8_t *buf, size_t len)
{
int k;
uint32_t s1 = adler & 0xffff;
uint32_t s2 = (adler >> 16) & 0xffff;
int k;
if (buf == NULL)
return 1L;
while (len > 0) {
k = len < NMAX ? (int)len : NMAX;
while (len > 0)
{
k = len < NMAX ? (int)len : NMAX;
len -= k;
while (k >= 16) {
while (k >= 16)
{
DO16(buf);
buf += 16;
k -= 16;

34
deps/libz/compress.c vendored
View File

@ -21,34 +21,38 @@
*/
int compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
{
z_stream stream;
int err;
z_stream stream;
stream.next_in = (Bytef *)source;
stream.next_in = (Bytef *)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
if ((uLong)stream.avail_in != sourceLen)
return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
if ((uLong)stream.avail_out != *destLen)
return Z_BUF_ERROR;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = (voidpf)0;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflateInit(&stream, level);
if (err != Z_OK)
return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
{
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
err = deflateEnd(&stream);
return err;
}
@ -65,6 +69,8 @@ int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen
*/
uLong compressBound (uLong sourceLen)
{
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
return sourceLen +
(sourceLen >> 12) +
(sourceLen >> 14) +
(sourceLen >> 25) + 13;
}

1201
deps/libz/deflate.c vendored

File diff suppressed because it is too large Load Diff

20
deps/libz/deflate.h vendored
View File

@ -249,11 +249,6 @@ typedef struct internal_state_deflate {
uInt matches; /* number of string matches in current block */
uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
ush bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least
* significant bits).
@ -309,16 +304,10 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
* used.
*/
#ifndef DEBUG
/* Inline versions of _tr_tally for speed: */
#if defined(GEN_TREES_H) || !defined(STDC)
extern uch ZLIB_INTERNAL _length_code[];
extern uch ZLIB_INTERNAL _dist_code[];
#else
extern const uch ZLIB_INTERNAL _length_code[];
extern const uch ZLIB_INTERNAL _dist_code[];
#endif
extern const uch ZLIB_INTERNAL _length_code[];
extern const uch ZLIB_INTERNAL _dist_code[];
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
@ -337,10 +326,5 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \
}
#else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
# define _tr_tally_dist(s, distance, length, flush) \
flush = _tr_tally(s, distance, length)
#endif
#endif /* DEFLATE_H */

6
deps/libz/gzclose.c vendored
View File

@ -20,8 +20,8 @@ int gzclose(gzFile file)
return Z_STREAM_ERROR;
state = (gz_statep)file;
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
#else
return gzclose_r(file);
if (state->mode != GZ_READ)
return gzclose_w(file);
#endif
return gzclose_r(file);
}

151
deps/libz/gzlib.c vendored
View File

@ -15,14 +15,6 @@
#endif
#endif
/* Forward declarations */
z_off_t gzoffset(gzFile file);
int gzbuffer(gzFile file, unsigned size);
/* Local functions */
static void gz_reset OF((gz_statep));
static gzFile gz_open OF((const void *, int, const char *));
#if defined UNDER_CE
/* Map the Windows error number in ERROR to a locale-dependent error message
@ -34,8 +26,7 @@ static gzFile gz_open OF((const void *, int, const char *));
The gz_strwinerror function does not change the current setting of
GetLastError. */
char ZLIB_INTERNAL *gz_strwinerror (error)
DWORD error;
char ZLIB_INTERNAL *gz_strwinerror (DWORD error)
{
static char buf[1024];
@ -78,24 +69,25 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
/* Reset gzip file state */
static void gz_reset(gz_statep state)
{
state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */
state->eof = 0; /* not at end of file */
state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */
state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) /* for reading ... */
{
state->eof = 0; /* not at end of file */
state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */
}
state->seek = 0; /* no seek request pending */
state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */
state->x.pos = 0; /* no uncompressed data yet */
state->x.pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */
}
/* Open a gzip file either by name or file descriptor. */
static gzFile gz_open(const void *path, int fd, const char *mode)
{
int oflag;
gz_statep state;
size_t len;
int oflag;
#ifdef O_CLOEXEC
int cloexec = 0;
#endif
@ -108,23 +100,25 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
return NULL;
/* allocate gzFile structure to return */
state = (gz_statep)malloc(sizeof(gz_state));
state = (gz_statep)malloc(sizeof(gz_state));
if (state == NULL)
return NULL;
state->size = 0; /* no buffers allocated yet */
state->want = GZBUFSIZE; /* requested buffer size */
state->msg = NULL; /* no error message yet */
state->msg = NULL; /* no error message yet */
/* interpret mode */
state->mode = GZ_NONE;
state->level = Z_DEFAULT_COMPRESSION;
state->mode = GZ_NONE;
state->level = Z_DEFAULT_COMPRESSION;
state->strategy = Z_DEFAULT_STRATEGY;
state->direct = 0;
while (*mode) {
state->direct = 0;
while (*mode)
{
if (*mode >= '0' && *mode <= '9')
state->level = *mode - '0';
else
switch (*mode) {
switch (*mode)
{
case 'r':
state->mode = GZ_READ;
break;
@ -173,14 +167,17 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
}
/* must provide an "r", "w", or "a" */
if (state->mode == GZ_NONE) {
if (state->mode == GZ_NONE)
{
free(state);
return NULL;
}
/* can't force transparent read */
if (state->mode == GZ_READ) {
if (state->direct) {
if (state->mode == GZ_READ)
{
if (state->direct)
{
free(state);
return NULL;
}
@ -189,7 +186,8 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
/* save the path name for error messages */
#ifdef _WIN32
if (fd == -2) {
if (fd == -2)
{
len = wcstombs(NULL, (const wchar_t*)path, 0);
if (len == (size_t)-1)
len = 0;
@ -198,7 +196,8 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
#endif
len = strlen((const char *)path);
state->path = (char *)malloc(len + 1);
if (state->path == NULL) {
if (state->path == NULL)
{
free(state);
return NULL;
}
@ -252,7 +251,8 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
state->mode = GZ_WRITE; /* simplify later checks */
/* save the current position for rewinding (only if reading) */
if (state->mode == GZ_READ) {
if (state->mode == GZ_READ)
{
state->start = LSEEK(state->fd, 0, SEEK_CUR);
if (state->start == -1) state->start = 0;
}
@ -330,8 +330,10 @@ int gzrewind(gzFile file)
state = (gz_statep)file;
/* check that we're reading and that there's no error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
if (
state->mode != GZ_READ ||
( state->err != Z_OK
&& state->err != Z_BUF_ERROR))
return -1;
/* back up and start over */
@ -344,22 +346,24 @@ int gzrewind(gzFile file)
z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
{
unsigned n;
z_off64_t ret;
gz_statep state;
/* get internal structure and check integrity */
if (file == NULL)
return -1;
state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
if ( state->mode != GZ_READ &&
state->mode != GZ_WRITE)
return -1;
/* check that there's no error */
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
if ( state->err != Z_OK &&
state->err != Z_BUF_ERROR)
return -1;
/* can only seek from start or relative to current position */
if (whence != SEEK_SET && whence != SEEK_CUR)
if ( whence != SEEK_SET &&
whence != SEEK_CUR)
return -1;
/* normalize offset to a SEEK_CUR specification */
@ -370,23 +374,28 @@ z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
state->seek = 0;
/* if within raw area while reading, just go there */
if (state->mode == GZ_READ && state->how == MODE_COPY &&
state->x.pos + offset >= 0) {
ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
if ( state->mode == GZ_READ &&
state->how == MODE_COPY &&
state->x.pos + offset >= 0)
{
z_off64_t ret = LSEEK(
state->fd, offset - state->x.have, SEEK_CUR);
if (ret == -1)
return -1;
state->x.have = 0;
state->eof = 0;
state->past = 0;
state->seek = 0;
state->x.have = 0;
state->eof = 0;
state->past = 0;
state->seek = 0;
gz_error(state, Z_OK, NULL);
state->strm.avail_in = 0;
state->x.pos += offset;
state->strm.avail_in = 0;
state->x.pos += offset;
return state->x.pos;
}
/* calculate skip amount, rewinding if needed for back seek when reading */
if (offset < 0) {
/* calculate skip amount, rewinding if
* needed for back seek when reading */
if (offset < 0)
{
if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1;
offset += state->x.pos;
@ -397,17 +406,19 @@ z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
}
/* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) {
if (state->mode == GZ_READ)
{
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
(unsigned)offset : state->x.have;
state->x.have -= n;
state->x.next += n;
state->x.pos += n;
offset -= n;
state->x.pos += n;
offset -= n;
}
/* request skip (if not zero) */
if (offset) {
if (offset)
{
state->seek = 1;
state->skip = offset;
}
@ -416,9 +427,7 @@ z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
z_off_t gzseek(gzFile file, z_off_t offset, int whence)
{
z_off64_t ret;
ret = gzseek64(file, (z_off64_t)offset, whence);
z_off64_t ret = gzseek64(file, (z_off64_t)offset, whence);
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
}
@ -430,7 +439,8 @@ z_off64_t gztell64(gzFile file)
if (file == NULL)
return -1;
state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
if ( state->mode != GZ_READ &&
state->mode != GZ_WRITE)
return -1;
/* return position */
@ -439,9 +449,7 @@ z_off64_t gztell64(gzFile file)
z_off_t gztell(gzFile file)
{
z_off64_t ret;
ret = gztell64(file);
z_off64_t ret = gztell64(file);
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
}
@ -480,7 +488,8 @@ int gzeof(gzFile file)
if (file == NULL)
return 0;
state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
if ( state->mode != GZ_READ &&
state->mode != GZ_WRITE)
return 0;
/* return end-of-file state */
@ -495,7 +504,9 @@ const char * gzerror(gzFile file, int *errnum)
if (file == NULL)
return NULL;
state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
if ( state->mode != GZ_READ &&
state->mode != GZ_WRITE)
return NULL;
/* return error information */
@ -513,12 +524,15 @@ void gzclearerr(gzFile file)
if (file == NULL)
return;
state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
if ( state->mode != GZ_READ &&
state->mode != GZ_WRITE)
return;
/* clear error and end-of-file */
if (state->mode == GZ_READ) {
state->eof = 0;
if (state->mode == GZ_READ)
{
state->eof = 0;
state->past = 0;
}
gz_error(state, Z_OK, NULL);
@ -533,7 +547,8 @@ void gzclearerr(gzFile file)
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
{
/* free previously allocated message and clear */
if (state->msg != NULL) {
if (state->msg != NULL)
{
if (state->err != Z_MEM_ERROR)
free(state->msg);
state->msg = NULL;
@ -554,7 +569,8 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
/* construct error message with path */
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
NULL) {
NULL)
{
state->err = Z_MEM_ERROR;
return;
}
@ -566,7 +582,6 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
strlcat(state->msg, ": ", sizeof(state->msg));
strlcat(state->msg, msg, sizeof(state->msg));
#endif
return;
}
#ifndef INT_MAX
@ -574,7 +589,7 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */
unsigned ZLIB_INTERNAL gz_intmax()
unsigned ZLIB_INTERNAL gz_intmax(void)
{
unsigned p, q;

198
deps/libz/gzread.c vendored
View File

@ -5,16 +5,6 @@
#include "gzguts.h"
/* Local functions */
static int gz_load (gz_statep, unsigned char *, unsigned, unsigned *);
static int gz_avail (gz_statep);
static int gz_look (gz_statep);
static int gz_decomp (gz_statep);
static int gz_fetch (gz_statep);
static int gz_skip (gz_statep, z_off64_t);
int gzgetc_(gzFile file);
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
state->fd, and update state->eof, state->err, and state->msg as appropriate.
This function needs to loop on read(), since read() is not guaranteed to
@ -30,7 +20,8 @@ static int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *
break;
*have += ret;
} while (*have < len);
if (ret < 0) {
if (ret < 0)
{
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
@ -53,8 +44,10 @@ static int gz_avail(gz_statep state)
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
if (state->eof == 0) {
if (strm->avail_in) { /* copy what's there to the start */
if (state->eof == 0)
{
if (strm->avail_in) /* copy what's there to the start */
{
unsigned char *p = state->in;
unsigned const char *q = strm->next_in;
unsigned n = strm->avail_in;
@ -85,11 +78,13 @@ static int gz_look(gz_statep state)
z_streamp strm = &(state->strm);
/* allocate read buffers and inflate memory */
if (state->size == 0) {
if (state->size == 0)
{
/* allocate buffers */
state->in = (unsigned char *)malloc(state->want);
state->out = (unsigned char *)malloc(state->want << 1);
if (state->in == NULL || state->out == NULL) {
if (state->in == NULL || state->out == NULL)
{
if (state->out != NULL)
free(state->out);
if (state->in != NULL)
@ -105,7 +100,8 @@ static int gz_look(gz_statep state)
state->strm.opaque = Z_NULL;
state->strm.avail_in = 0;
state->strm.next_in = Z_NULL;
if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) /* gunzip */
{
free(state->out);
free(state->in);
state->size = 0;
@ -115,7 +111,8 @@ static int gz_look(gz_statep state)
}
/* get at least the magic bytes in the input buffer */
if (strm->avail_in < 2) {
if (strm->avail_in < 2)
{
if (gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0)
@ -129,8 +126,10 @@ static int gz_look(gz_statep state)
file -- for here we assume that if a gzip file is being written, then
the header will be written in a single operation, so that reading a
single byte is sufficient indication that it is not a gzip file) */
if (strm->avail_in > 1 &&
strm->next_in[0] == 31 && strm->next_in[1] == 139) {
if ( strm->avail_in > 1 &&
strm->next_in[0] == 31 &&
strm->next_in[1] == 139)
{
inflateReset(strm);
state->how = MODE_GZIP;
state->direct = 0;
@ -139,10 +138,11 @@ static int gz_look(gz_statep state)
/* no gzip header -- if we were decoding gzip before, then this is trailing
garbage. Ignore the trailing garbage and finish. */
if (state->direct == 0) {
if (state->direct == 0)
{
strm->avail_in = 0;
state->eof = 1;
state->x.have = 0;
state->eof = 1;
state->x.have = 0;
return 0;
}
@ -150,12 +150,13 @@ static int gz_look(gz_statep state)
the output buffer is larger than the input buffer, which also assures
space for gzungetc() */
state->x.next = state->out;
if (strm->avail_in) {
if (strm->avail_in)
{
memcpy(state->x.next, strm->next_in, strm->avail_in);
state->x.have = strm->avail_in;
strm->avail_in = 0;
}
state->how = MODE_COPY;
state->how = MODE_COPY;
state->direct = 1;
return 0;
}
@ -168,32 +169,36 @@ static int gz_look(gz_statep state)
static int gz_decomp(gz_statep state)
{
int ret = Z_OK;
unsigned had;
z_streamp strm = &(state->strm);
/* fill output buffer up to end of deflate stream */
had = strm->avail_out;
do {
unsigned had = strm->avail_out;
do
{
/* get more input for inflate() */
if (strm->avail_in == 0 && gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0) {
if (strm->avail_in == 0)
{
gz_error(state, Z_BUF_ERROR, "unexpected end of file");
break;
}
/* decompress and handle errors */
ret = inflate(strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT)
{
gz_error(state, Z_STREAM_ERROR,
"internal error: inflate stream corrupt");
return -1;
}
if (ret == Z_MEM_ERROR) {
if (ret == Z_MEM_ERROR)
{
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
if (ret == Z_DATA_ERROR) /* deflate stream invalid */
{
gz_error(state, Z_DATA_ERROR,
strm->msg == NULL ? "compressed data error" : strm->msg);
return -1;
@ -201,7 +206,7 @@ static int gz_decomp(gz_statep state)
} while (strm->avail_out && ret != Z_STREAM_END);
/* update available output */
state->x.have = had - strm->avail_out;
state->x.have = had - strm->avail_out;
state->x.next = strm->next_out - state->x.have;
/* if the gzip stream completed successfully, look for another */
@ -222,8 +227,10 @@ static int gz_fetch(gz_statep state)
{
z_streamp strm = &(state->strm);
do {
switch(state->how) {
do
{
switch(state->how)
{
case LOOK: /* -> LOOK, MODE_COPY (only if never GZIP), or MODE_GZIP */
if (gz_look(state) == -1)
return -1;
@ -254,7 +261,8 @@ static int gz_skip(gz_statep state, z_off64_t len)
/* skip over len bytes or reach end-of-file, whichever comes first */
while (len)
/* skip over whatever is in output buffer */
if (state->x.have) {
if (state->x.have)
{
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
(unsigned)len : state->x.have;
state->x.have -= n;
@ -268,7 +276,8 @@ static int gz_skip(gz_statep state, z_off64_t len)
break;
/* need more data to skip -- load up output buffer */
else {
else
{
/* get more output, looking for header if required */
if (gz_fetch(state) == -1)
return -1;
@ -286,16 +295,19 @@ int gzread(gzFile file, voidp buf, unsigned len)
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
strm = &(state->strm);
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
if (
state->mode != GZ_READ ||
( state->err != Z_OK &&
state->err != Z_BUF_ERROR))
return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
if ((int)len < 0)
{
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return -1;
}
@ -305,7 +317,8 @@ int gzread(gzFile file, voidp buf, unsigned len)
return 0;
/* process a skip request */
if (state->seek) {
if (state->seek)
{
state->seek = 0;
if (gz_skip(state, state->skip) == -1)
return -1;
@ -313,10 +326,12 @@ int gzread(gzFile file, voidp buf, unsigned len)
/* get len bytes to buf, or less than len if at the end */
got = 0;
n = 0;
do {
n = 0;
do
{
/* first just try copying data from the output buffer */
if (state->x.have) {
if (state->x.have)
{
n = state->x.have > len ? len : state->x.have;
memcpy(buf, state->x.next, n);
state->x.next += n;
@ -324,14 +339,16 @@ int gzread(gzFile file, voidp buf, unsigned len)
}
/* output buffer empty -- return if we're at the end of the input */
else if (state->eof && strm->avail_in == 0) {
else if (state->eof && strm->avail_in == 0)
{
state->past = 1; /* tried to read past end */
break;
}
/* need output data -- for small len or new stream load up our output
buffer */
else if (state->how == LOOK || len < (state->size << 1)) {
else if (state->how == LOOK || len < (state->size << 1))
{
/* get more output, looking for header if required */
if (gz_fetch(state) == -1)
return -1;
@ -341,26 +358,28 @@ int gzread(gzFile file, voidp buf, unsigned len)
}
/* large len -- read directly into user buffer */
else if (state->how == MODE_COPY) { /* read directly */
else if (state->how == MODE_COPY) /* read directly */
{
if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
return -1;
}
/* large len -- decompress directly into user buffer */
else { /* state->how == GZIP */
else /* state->how == GZIP */
{
strm->avail_out = len;
strm->next_out = (unsigned char *)buf;
strm->next_out = (unsigned char *)buf;
if (gz_decomp(state) == -1)
return -1;
n = state->x.have;
state->x.have = 0;
n = state->x.have;
state->x.have = 0;
}
/* update progress */
len -= n;
buf = (char *)buf + n;
got += n;
state->x.pos += n;
len -= n;
buf = (char *)buf + n;
got += n;
state->x.pos += n;
} while (len);
/* return number of bytes read into user buffer (will fit in int) */
@ -384,12 +403,15 @@ int gzgetc(gzFile file)
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
if (
state->mode != GZ_READ ||
(state->err != Z_OK &&
state->err != Z_BUF_ERROR))
return -1;
/* try output buffer (no need to check for skip request) */
if (state->x.have) {
if (state->x.have)
{
state->x.have--;
state->x.pos++;
return *(state->x.next)++;
@ -415,12 +437,15 @@ int gzungetc(int c, gzFile file)
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
if (
state->mode != GZ_READ ||
(state->err != Z_OK &&
state->err != Z_BUF_ERROR))
return -1;
/* process a skip request */
if (state->seek) {
if (state->seek)
{
state->seek = 0;
if (gz_skip(state, state->skip) == -1)
return -1;
@ -431,34 +456,37 @@ int gzungetc(int c, gzFile file)
return -1;
/* if output buffer empty, put byte at end (allows more pushing) */
if (state->x.have == 0) {
state->x.have = 1;
state->x.next = state->out + (state->size << 1) - 1;
if (state->x.have == 0)
{
state->x.have = 1;
state->x.next = state->out + (state->size << 1) - 1;
state->x.next[0] = c;
state->x.pos--;
state->past = 0;
state->past = 0;
return c;
}
/* if no room, give up (must have already done a gzungetc()) */
if (state->x.have == (state->size << 1)) {
if (state->x.have == (state->size << 1))
{
gz_error(state, Z_DATA_ERROR, "out of room to push characters");
return -1;
}
/* slide output data if needed and insert byte before existing data */
if (state->x.next == state->out) {
unsigned char *src = state->out + state->x.have;
if (state->x.next == state->out)
{
unsigned char *src = state->out + state->x.have;
unsigned char *dest = state->out + (state->size << 1);
while (src > state->out)
*--dest = *--src;
state->x.next = dest;
state->x.next = dest;
}
state->x.have++;
state->x.next--;
state->x.next[0] = c;
state->x.pos--;
state->past = 0;
state->past = 0;
return c;
}
@ -475,12 +503,15 @@ char * gzgets(gzFile file, char *buf, int len)
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
if (
state->mode != GZ_READ ||
(state->err != Z_OK &&
state->err != Z_BUF_ERROR))
return NULL;
/* process a skip request */
if (state->seek) {
if (state->seek)
{
state->seek = 0;
if (gz_skip(state, state->skip) == -1)
return NULL;
@ -495,13 +526,15 @@ char * gzgets(gzFile file, char *buf, int len)
/* assure that something is in the output buffer */
if (state->x.have == 0 && gz_fetch(state) == -1)
return NULL; /* error */
if (state->x.have == 0) { /* end of file */
if (state->x.have == 0) /* end of file */
{
state->past = 1; /* read past end */
break; /* return what we have */
}
/* look for end-of-line in current output buffer */
n = state->x.have > left ? left : state->x.have;
n = state->x.have > left ? left : state->x.have;
eol = (unsigned char *)memchr(state->x.next, '\n', n);
if (eol != NULL)
n = (unsigned)(eol - state->x.next) + 1;
@ -510,9 +543,9 @@ char * gzgets(gzFile file, char *buf, int len)
memcpy(buf, state->x.next, n);
state->x.have -= n;
state->x.next += n;
state->x.pos += n;
left -= n;
buf += n;
state->x.pos += n;
left -= n;
buf += n;
} while (left && eol == NULL);
/* return terminated string, or if nothing, end of file */
@ -533,7 +566,9 @@ int gzdirect(gzFile file)
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
if ( state->mode == GZ_READ &&
state->how == LOOK &&
state->x.have == 0)
(void)gz_look(state);
/* return 1 if transparent, 0 if processing a gzip stream */
@ -555,7 +590,8 @@ int gzclose_r(gzFile file)
return Z_STREAM_ERROR;
/* free memory and close file */
if (state->size) {
if (state->size)
{
inflateEnd(&(state->strm));
free(state->out);
free(state->in);

616
deps/libz/gzwrite.c vendored
View File

@ -3,15 +3,10 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <stdarg.h>
#include "gzguts.h"
/* Local functions */
static int gz_init (gz_statep);
static int gz_comp (gz_statep, int);
static int gz_zero (gz_statep, z_off64_t);
int gzvprintf(gzFile file, const char *format, va_list va);
/* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on failure or 0 on success. */
static int gz_init(gz_statep state)
@ -21,43 +16,48 @@ static int gz_init(gz_statep state)
/* allocate input buffer */
state->in = (unsigned char *)malloc(state->want);
if (state->in == NULL) {
if (state->in == NULL)
{
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
/* only need output buffer and deflate state if compressing */
if (!state->direct) {
/* allocate output buffer */
state->out = (unsigned char *)malloc(state->want);
if (state->out == NULL) {
free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
if (!state->direct)
{
/* allocate output buffer */
state->out = (unsigned char *)malloc(state->want);
if (state->out == NULL)
{
free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
/* allocate deflate memory, set up for gzip compression */
strm->zalloc = Z_NULL;
strm->zfree = Z_NULL;
strm->opaque = Z_NULL;
ret = deflateInit2(strm, state->level, Z_DEFLATED,
MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
if (ret != Z_OK) {
free(state->out);
free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
/* allocate deflate memory, set up for gzip compression */
strm->zalloc = Z_NULL;
strm->zfree = Z_NULL;
strm->opaque = Z_NULL;
ret = deflateInit2(strm, state->level, Z_DEFLATED,
MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
if (ret != Z_OK)
{
free(state->out);
free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
}
/* mark state as initialized */
state->size = state->want;
state->size = state->want;
/* initialize write buffer if compressing */
if (!state->direct) {
strm->avail_out = state->size;
strm->next_out = state->out;
state->x.next = strm->next_out;
if (!state->direct)
{
strm->avail_out = state->size;
strm->next_out = state->out;
state->x.next = strm->next_out;
}
return 0;
}
@ -79,9 +79,11 @@ static int gz_comp(gz_statep state, int flush)
return -1;
/* write directly if requested */
if (state->direct) {
if (state->direct)
{
got = write(state->fd, strm->next_in, strm->avail_in);
if (got < 0 || (unsigned)got != strm->avail_in) {
if (got < 0 || (unsigned)got != strm->avail_in)
{
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
@ -95,24 +97,28 @@ static int gz_comp(gz_statep state, int flush)
/* write out current buffer contents if full, or if flushing, but if
doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) {
have = (unsigned)(strm->next_out - state->x.next);
if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
(unsigned)got != have)) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
if (strm->avail_out == 0) {
strm->avail_out = state->size;
strm->next_out = state->out;
}
state->x.next = strm->next_out;
(flush != Z_FINISH || ret == Z_STREAM_END)))
{
have = (unsigned)(strm->next_out - state->x.next);
if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
(unsigned)got != have))
{
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
if (strm->avail_out == 0)
{
strm->avail_out = state->size;
strm->next_out = state->out;
}
state->x.next = strm->next_out;
}
/* compress */
have = strm->avail_out;
ret = deflate(strm, flush);
if (ret == Z_STREAM_ERROR) {
ret = deflate(strm, flush);
if (ret == Z_STREAM_ERROR)
{
gz_error(state, Z_STREAM_ERROR,
"internal error: deflate stream corrupt");
return -1;
@ -132,7 +138,6 @@ static int gz_comp(gz_statep state, int flush)
static int gz_zero(gz_statep state, z_off64_t len)
{
int first;
unsigned n;
z_streamp strm = &(state->strm);
/* consume whatever's left in the input buffer */
@ -141,16 +146,18 @@ static int gz_zero(gz_statep state, z_off64_t len)
/* compress len zeros (len guaranteed > 0) */
first = 1;
while (len) {
n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
while (len)
{
unsigned n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
(unsigned)len : state->size;
if (first) {
if (first)
{
memset(state->in, 0, n);
first = 0;
}
strm->avail_in = n;
strm->next_in = state->in;
state->x.pos += n;
strm->next_in = state->in;
state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return -1;
len -= n;
@ -160,23 +167,25 @@ static int gz_zero(gz_statep state, z_off64_t len)
int gzwrite(gzFile file, voidpc buf, unsigned len)
{
unsigned put = len;
gz_statep state;
z_streamp strm;
unsigned put = len;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
strm = &(state->strm);
strm = &(state->strm);
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
if ( state->mode != GZ_WRITE ||
state->err != Z_OK)
return 0;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
if ((int)len < 0)
{
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
@ -190,44 +199,47 @@ int gzwrite(gzFile file, voidpc buf, unsigned len)
return 0;
/* check for seek request */
if (state->seek) {
if (state->seek)
{
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return 0;
}
/* for small len, copy to input buffer, otherwise compress directly */
if (len < state->size) {
/* copy to input buffer, compress when full */
do {
unsigned have, copy;
if (len < state->size)
{
/* copy to input buffer, compress when full */
do {
unsigned have, copy;
if (strm->avail_in == 0)
strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
copy = state->size - have;
if (copy > len)
copy = len;
memcpy(state->in + have, buf, copy);
strm->avail_in += copy;
state->x.pos += copy;
buf = (const char *)buf + copy;
len -= copy;
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
} while (len);
if (strm->avail_in == 0)
strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
copy = state->size - have;
if (copy > len)
copy = len;
memcpy(state->in + have, buf, copy);
strm->avail_in += copy;
state->x.pos += copy;
buf = (const char *)buf + copy;
len -= copy;
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
} while (len);
}
else {
/* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
else
{
/* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
/* directly compress user buffer to file */
strm->avail_in = len;
strm->next_in = (Bytef *)buf;
state->x.pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
/* directly compress user buffer to file */
strm->avail_in = len;
strm->next_in = (Bytef *)buf;
state->x.pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
}
/* input was all buffered or compressed (put will fit in int) */
@ -236,314 +248,244 @@ int gzwrite(gzFile file, voidpc buf, unsigned len)
int gzputc(gzFile file, int c)
{
unsigned have;
unsigned char buf[1];
gz_statep state;
z_streamp strm;
unsigned have;
unsigned char buf[1];
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return -1;
/* check that we're writing and that there's no error */
if ( state->mode != GZ_WRITE ||
state->err != Z_OK)
return -1;
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* check for seek request */
if (state->seek)
{
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* try writing to input buffer for speed (state->size == 0 if buffer not
initialized) */
if (state->size) {
if (strm->avail_in == 0)
strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
if (have < state->size) {
state->in[have] = c;
strm->avail_in++;
state->x.pos++;
return c & 0xff;
}
}
/* try writing to input buffer for speed (state->size == 0 if buffer not
initialized) */
if (state->size)
{
if (strm->avail_in == 0)
strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
if (have < state->size)
{
state->in[have] = c;
strm->avail_in++;
state->x.pos++;
return c & 0xff;
}
}
/* no room in buffer or not initialized, use gz_write() */
buf[0] = c;
if (gzwrite(file, buf, 1) != 1)
return -1;
return c & 0xff;
/* no room in buffer or not initialized, use gz_write() */
buf[0] = c;
if (gzwrite(file, buf, 1) != 1)
return -1;
return c & 0xff;
}
int gzputs(gzFile file, const char *str)
{
int ret;
unsigned len;
/* write string */
len = (unsigned)strlen(str);
ret = gzwrite(file, str, len);
return ret == 0 && len != 0 ? -1 : ret;
/* write string */
unsigned len = (unsigned)strlen(str);
int ret = gzwrite(file, str, len);
return ret == 0 && len != 0 ? -1 : ret;
}
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
#include <stdarg.h>
int gzvprintf(gzFile file, const char *format, va_list va)
{
int size, len;
gz_statep state;
z_streamp strm;
int size, len;
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
/* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1)
return 0;
/* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1)
return 0;
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return 0;
}
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return 0;
}
/* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
/* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
/* do the printf() into the input buffer, put length in len */
size = (int)(state->size);
state->in[size - 1] = 0;
/* do the printf() into the input buffer, put length in len */
size = (int)(state->size);
state->in[size - 1] = 0;
#ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void
(void)vsprintf((char *)(state->in), format, va);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
(void)vsprintf((char *)(state->in), format, va);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
# else
len = vsprintf((char *)(state->in), format, va);
len = vsprintf((char *)(state->in), format, va);
# endif
#else
# ifdef HAS_vsnprintf_void
(void)vsnprintf((char *)(state->in), size, format, va);
len = strlen((char *)(state->in));
(void)vsnprintf((char *)(state->in), size, format, va);
len = strlen((char *)(state->in));
# else
len = vsnprintf((char *)(state->in), size, format, va);
len = vsnprintf((char *)(state->in), size, format, va);
# endif
#endif
/* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
return 0;
/* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
return 0;
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
state->x.pos += len;
return len;
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
state->x.pos += len;
return len;
}
int gzprintf(gzFile file, const char *format, ...)
{
va_list va;
int ret;
va_list va;
int ret;
va_start(va, format);
ret = gzvprintf(file, format, va);
va_end(va);
return ret;
va_start(va, format);
ret = gzvprintf(file, format, va);
va_end(va);
return ret;
}
#else /* !STDC && !Z_HAVE_STDARG_H */
int gzprintf (gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10,
int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
{
int size, len;
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
/* check that can really pass pointer in ints */
if (sizeof(int) != sizeof(void *))
return 0;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
/* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1)
return 0;
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return 0;
}
/* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
/* do the printf() into the input buffer, put length in len */
size = (int)(state->size);
state->in[size - 1] = 0;
#ifdef NO_snprintf
# ifdef HAS_sprintf_void
sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
# else
len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
# endif
#else
# ifdef HAS_snprintf_void
snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
len = strlen((char *)(state->in));
# else
len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
a19, a20);
# endif
#endif
/* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
return 0;
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
state->x.pos += len;
return len;
}
#endif
int gzflush(gzFile file, int flush)
{
gz_statep state;
gz_statep state;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return Z_STREAM_ERROR;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return Z_STREAM_ERROR;
/* check flush parameter */
if (flush < 0 || flush > Z_FINISH)
return Z_STREAM_ERROR;
/* check flush parameter */
if (flush < 0 || flush > Z_FINISH)
return Z_STREAM_ERROR;
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* check for seek request */
if (state->seek)
{
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* compress remaining data with requested flush */
gz_comp(state, flush);
return state->err;
/* compress remaining data with requested flush */
gz_comp(state, flush);
return state->err;
}
int gzsetparams(gzFile file, int level, int strategy)
{
gz_statep state;
z_streamp strm;
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
state = (gz_statep)file;
strm = &(state->strm);
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
state = (gz_statep)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return Z_STREAM_ERROR;
/* check that we're writing and that there's no error */
if ( state->mode != GZ_WRITE ||
state->err != Z_OK)
return Z_STREAM_ERROR;
/* if no change is requested, then do nothing */
if (level == state->level && strategy == state->strategy)
return Z_OK;
/* if no change is requested, then do nothing */
if ( level == state->level &&
strategy == state->strategy)
return Z_OK;
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* check for seek request */
if (state->seek)
{
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* change compression parameters for subsequent input */
if (state->size) {
/* flush previous input with previous parameters before changing */
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
return state->err;
deflateParams(strm, level, strategy);
}
state->level = level;
state->strategy = strategy;
return Z_OK;
/* change compression parameters for subsequent input */
if (state->size)
{
/* flush previous input with previous parameters before changing */
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
return state->err;
deflateParams(strm, level, strategy);
}
state->level = level;
state->strategy = strategy;
return Z_OK;
}
int gzclose_w(gzFile file)
{
int ret = Z_OK;
gz_statep state;
int ret = Z_OK;
gz_statep state;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
state = (gz_statep)file;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
state = (gz_statep)file;
/* check that we're writing */
if (state->mode != GZ_WRITE)
return Z_STREAM_ERROR;
/* check that we're writing */
if (state->mode != GZ_WRITE)
return Z_STREAM_ERROR;
/* check for seek request */
if (state->seek) {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
ret = state->err;
}
/* check for seek request */
if (state->seek)
{
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
ret = state->err;
}
/* flush, free memory, and close file */
if (gz_comp(state, Z_FINISH) == -1)
ret = state->err;
if (state->size) {
if (!state->direct) {
(void)deflateEnd(&(state->strm));
free(state->out);
}
free(state->in);
}
gz_error(state, Z_OK, NULL);
free(state->path);
if (close(state->fd) == -1)
ret = Z_ERRNO;
free(state);
return ret;
/* flush, free memory, and close file */
if (gz_comp(state, Z_FINISH) == -1)
ret = state->err;
if (state->size)
{
if (!state->direct)
{
(void)deflateEnd(&(state->strm));
free(state->out);
}
free(state->in);
}
gz_error(state, Z_OK, NULL);
free(state->path);
if (close(state->fd) == -1)
ret = Z_ERRNO;
free(state);
return ret;
}

305
deps/libz/inffast.c vendored
View File

@ -10,25 +10,6 @@
#ifndef ASMINF
/* Allow machine dependent optimization for post-increment or pre-increment.
Based on testing to date,
Pre-increment preferred for:
- PowerPC G3 (Adler)
- MIPS R5000 (Randers-Pehrson)
Post-increment preferred for:
- none
No measurable difference:
- Pentium III (Anderson)
- M68060 (Nikl)
*/
#ifdef POSTINC
# define OFF 0
# define PUP(a) *(a)++
#else
# define OFF 1
# define PUP(a) *++(a)
#endif
/*
Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is
@ -66,26 +47,7 @@ output space.
*/
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
{
struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* have enough input while in < last */
unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT
unsigned dmax; /* maximum distance from zlib header */
#endif
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned wnext; /* window write index */
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */
code const FAR *lcode; /* local strm->lencode */
code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */
code here; /* retrieved table entry */
code const *here; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */
@ -93,211 +55,209 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
unsigned char FAR *from; /* where to copy match from */
/* copy state to local variables */
state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF;
last = in + (strm->avail_in - 5);
out = strm->next_out - OFF;
beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT
dmax = state->dmax;
#endif
wsize = state->wsize;
whave = state->whave;
wnext = state->wnext;
window = state->window;
hold = state->hold;
bits = state->bits;
lcode = state->lencode;
dcode = state->distcode;
lmask = (1U << state->lenbits) - 1;
dmask = (1U << state->distbits) - 1;
struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
unsigned char FAR *in = strm->next_in;
unsigned char FAR *last = in + (strm->avail_in - 5);
unsigned char FAR *out = strm->next_out;
unsigned char FAR *beg = out - (start - strm->avail_out);
unsigned char FAR *end = out + (strm->avail_out - 257);
unsigned wsize = state->wsize;
unsigned whave = state->whave;
unsigned wnext = state->wnext;
unsigned char FAR *window = state->window;
unsigned long hold = state->hold;
unsigned bits = state->bits;
code const FAR *lcode = state->lencode;
code const FAR *dcode = state->distcode;
unsigned lmask = (1U << state->lenbits) - 1;
unsigned dmask = (1U << state->distbits) - 1;
/* decode literals and length/distances until end-of-block or not enough
input data or output space */
do {
if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits;
do
{
if (bits < 15)
{
hold += (unsigned long)(*in++) << bits;
bits += 8;
hold += (unsigned long)(PUP(in)) << bits;
hold += (unsigned long)(*in++) << bits;
bits += 8;
}
here = lcode[hold & lmask];
here = lcode + (hold & lmask);
dolen:
op = (unsigned)(here.bits);
op = (unsigned)(here->bits);
hold >>= op;
bits -= op;
op = (unsigned)(here.op);
if (op == 0) { /* literal */
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val));
PUP(out) = (unsigned char)(here.val);
}
else if (op & 16) { /* length base */
len = (unsigned)(here.val);
op = (unsigned)(here->op);
if (op == 0) /* literal */
*out++ = (unsigned char)(here->val);
else if (op & 16) /* length base */
{
len = (unsigned)(here->val);
op &= 15; /* number of extra bits */
if (op) {
if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits;
if (op)
{
if (bits < op)
{
hold += (unsigned long)(*in++) << bits;
bits += 8;
}
len += (unsigned)hold & ((1U << op) - 1);
len += (unsigned)hold & ((1U << op) - 1);
hold >>= op;
bits -= op;
bits -= op;
}
Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits;
if (bits < 15)
{
hold += (unsigned long)(*in++) << bits;
bits += 8;
hold += (unsigned long)(PUP(in)) << bits;
hold += (unsigned long)(*in++) << bits;
bits += 8;
}
here = dcode[hold & dmask];
here = dcode + (hold & dmask);
dodist:
op = (unsigned)(here.bits);
op = (unsigned)(here->bits);
hold >>= op;
bits -= op;
op = (unsigned)(here.op);
if (op & 16) { /* distance base */
dist = (unsigned)(here.val);
op = (unsigned)(here->op);
if (op & 16) /* distance base */
{
dist = (unsigned)(here->val);
op &= 15; /* number of extra bits */
if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits;
if (bits < op)
{
hold += (unsigned long)(*in++) << bits;
bits += 8;
if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits;
if (bits < op)
{
hold += (unsigned long)(*in++) << bits;
bits += 8;
}
}
dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT
if (dist > dmax) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
}
#endif
dist += (unsigned)hold & ((1U << op) - 1);
hold >>= op;
bits -= op;
Tracevv((stderr, "inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */
op = dist - op; /* distance back in window */
if (op > whave) {
if (state->sane) {
bits -= op;
op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) /* see if copy from window */
{
op = dist - op; /* distance back in window */
if (op > whave)
{
if (state->sane)
{
strm->msg =
(char *)"invalid distance too far back";
state->mode = BAD;
break;
}
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
if (len <= op - whave) {
do {
PUP(out) = 0;
} while (--len);
continue;
}
len -= op - whave;
do {
PUP(out) = 0;
} while (--op > whave);
if (op == 0) {
from = out - dist;
do {
PUP(out) = PUP(from);
} while (--len);
continue;
}
#endif
}
from = window - OFF;
if (wnext == 0) { /* very common case */
from = window;
if (wnext == 0) /* very common case */
{
from += wsize - op;
if (op < len) { /* some from window */
if (op < len) /* some from window */
{
len -= op;
do {
PUP(out) = PUP(from);
*out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
else if (wnext < op) { /* wrap around window */
else if (wnext < op) /* wrap around window */
{
from += wsize + wnext - op;
op -= wnext;
if (op < len) { /* some from end of window */
if (op < len) /* some from end of window */
{
len -= op;
do {
PUP(out) = PUP(from);
*out++ = *from++;
} while (--op);
from = window - OFF;
if (wnext < len) { /* some from start of window */
from = window;
if (wnext < len) /* some from start of window */
{
op = wnext;
len -= op;
do {
PUP(out) = PUP(from);
*out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
}
else { /* contiguous in window */
else /* contiguous in window */
{
from += wnext - op;
if (op < len) { /* some from window */
if (op < len) /* some from window */
{
len -= op;
do {
PUP(out) = PUP(from);
*out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
while (len > 2) {
PUP(out) = PUP(from);
PUP(out) = PUP(from);
PUP(out) = PUP(from);
while (len > 2)
{
*out++ = *from++;
*out++ = *from++;
*out++ = *from++;
len -= 3;
}
if (len) {
PUP(out) = PUP(from);
if (len)
{
*out++ = *from++;
if (len > 1)
PUP(out) = PUP(from);
*out++ = *from++;
}
}
else {
else
{
from = out - dist; /* copy direct from output */
do { /* minimum length is three */
PUP(out) = PUP(from);
PUP(out) = PUP(from);
PUP(out) = PUP(from);
*out++ = *from++;
*out++ = *from++;
*out++ = *from++;
len -= 3;
} while (len > 2);
if (len) {
PUP(out) = PUP(from);
}while(len > 2);
if (len)
{
*out++ = *from++;
if (len > 1)
PUP(out) = PUP(from);
*out++ = *from++;
}
}
}
else if ((op & 64) == 0) { /* 2nd level distance code */
here = dcode[here.val + (hold & ((1U << op) - 1))];
else if ((op & 64) == 0) /* 2nd level distance code */
{
here = dcode + here->val + (hold & ((1U << op) - 1));
goto dodist;
}
else {
strm->msg = (char *)"invalid distance code";
else
{
strm->msg = (char *)"invalid distance code";
state->mode = BAD;
break;
}
}
else if ((op & 64) == 0) { /* 2nd level length code */
here = lcode[here.val + (hold & ((1U << op) - 1))];
else if ((op & 64) == 0) /* 2nd level length code */
{
here = lcode + here->val + (hold & ((1U << op) - 1));
goto dolen;
}
else if (op & 32) { /* end-of-block */
Tracevv((stderr, "inflate: end of block\n"));
else if (op & 32) /* end-of-block */
{
state->mode = TYPE;
break;
}
else {
else
{
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
@ -305,20 +265,19 @@ dodist:
} while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3;
in -= len;
bits -= len << 3;
hold &= (1U << bits) - 1;
len = bits >> 3;
in -= len;
bits -= len << 3;
hold &= (1U << bits) - 1;
/* update state and return */
strm->next_in = in + OFF;
strm->next_out = out + OFF;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ?
strm->next_in = in;
strm->next_out = out;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end));
state->hold = hold;
state->bits = bits;
return;
state->hold = hold;
state->bits = bits;
}
/*

673
deps/libz/inflate.c vendored

File diff suppressed because it is too large Load Diff

4
deps/libz/inflate.h vendored
View File

@ -84,10 +84,10 @@ typedef enum {
struct inflate_state {
inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
bit 2 true to validate check value */
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */
gz_headerp head; /* where to save gzip header information */

352
deps/libz/trees.c vendored
View File

@ -32,14 +32,8 @@
/* @(#) $Id$ */
/* #define GEN_TREES_H */
#include "deflate.h"
#ifdef DEBUG
# include <ctype.h>
#endif
/* ===========================================================================
* Constants
*/
@ -80,39 +74,7 @@ static const uch bl_order[BL_CODES]
#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
#if defined(GEN_TREES_H) || !defined(STDC)
/* non ANSI compilers may not accept trees.h */
static ct_data static_ltree[L_CODES+2];
/* The static literal tree. Since the bit lengths are imposed, there is no
* need for the L_CODES extra codes used during heap construction. However
* The codes 286 and 287 are needed to build a canonical tree (see _tr_init
* below).
*/
static ct_data static_dtree[D_CODES];
/* The static distance tree. (Actually a trivial tree since all codes use
* 5 bits.)
*/
uch _dist_code[DIST_CODE_LEN];
/* Distance codes. The first 256 values correspond to the distances
* 3 .. 258, the last 256 values correspond to the top 8 bits of
* the 15 bit distances.
*/
uch _length_code[MAX_MATCH-MIN_MATCH+1];
/* length code for each normalized match length (0 == MIN_MATCH) */
static int base_length[LENGTH_CODES];
/* First normalized length for each code (0 = MIN_MATCH) */
static int base_dist[D_CODES];
/* First normalized distance for each code (0 = distance of 1) */
#else
# include "trees.h"
#endif /* GEN_TREES_H */
#include "trees.h"
struct static_tree_desc_s {
const ct_data *static_tree; /* static tree or NULL */
@ -135,29 +97,12 @@ static static_tree_desc static_bl_desc =
* Local (static) routines in this file.
*/
static void tr_static_init (void);
static void init_block (deflate_state *s);
static void pqdownheap (deflate_state *s, ct_data *tree, int k);
static void gen_bitlen (deflate_state *s, tree_desc *desc);
static void gen_codes (ct_data *tree, int max_code, ushf *bl_count);
static void build_tree (deflate_state *s, tree_desc *desc);
static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
static void send_tree (deflate_state *s, ct_data *tree, int max_code);
static int build_bl_tree (deflate_state *s);
static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
int blcodes);
static void compress_block (deflate_state *s, const ct_data *ltree,
const ct_data *dtree);
static int detect_data_type (deflate_state *s);
static unsigned bi_reverse (unsigned value, int length);
static void bi_windup (deflate_state *s);
static void bi_flush (deflate_state *s);
static void copy_block (deflate_state *s, charf *buf, unsigned len,
int header);
#ifdef GEN_TREES_H
static void gen_trees_header (void);
#endif
# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
/* Send a code of the given tree. c and tree must not have side effects */
@ -175,30 +120,6 @@ static void gen_trees_header (void);
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
#ifdef DEBUG
static void send_bits (deflate_state *s, int value, int length);
static void send_bits(deflate_state *s, int value, int length)
{
Tracevv((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length;
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
* unused bits in value.
*/
if (s->bi_valid > (int)Buf_size - length) {
s->bi_buf |= (ush)value << s->bi_valid;
put_short(s, s->bi_buf);
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
s->bi_valid += length - Buf_size;
} else {
s->bi_buf |= (ush)value << s->bi_valid;
s->bi_valid += length;
}
}
#else /* !DEBUG */
#define send_bits(s, value, length) \
{ int len = length;\
@ -213,184 +134,6 @@ static void send_bits(deflate_state *s, int value, int length)
s->bi_valid += len;\
}\
}
#endif /* DEBUG */
/* the arguments must not have side effects */
/* ===========================================================================
* Initialize the various 'constant' tables.
*/
static void tr_static_init(void)
{
#if defined(GEN_TREES_H) || !defined(STDC)
static int static_init_done = 0;
int n; /* iterates over tree elements */
int bits; /* bit counter */
int length; /* length value */
int codes; /* code value */
int dist; /* distance index */
ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
if (static_init_done) return;
/* For some embedded targets, global variables are not initialized: */
#ifdef NO_INIT_GLOBAL_POINTERS
static_l_desc.static_tree = static_ltree;
static_l_desc.extra_bits = extra_lbits;
static_d_desc.static_tree = static_dtree;
static_d_desc.extra_bits = extra_dbits;
static_bl_desc.extra_bits = extra_blbits;
#endif
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
for (codes = 0; codes < LENGTH_CODES-1; codes++) {
base_length[codes] = length;
for (n = 0; n < (1<<extra_lbits[codes]); n++) {
_length_code[length++] = (uch)codes;
}
}
Assert (length == 256, "tr_static_init: length != 256");
/* Note that the length 255 (match length 258) can be represented
* in two different ways: code 284 + 5 bits or code 285, so we
* overwrite length_code[255] to use the best encoding:
*/
_length_code[length-1] = (uch)codes;
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0;
for (codes = 0 ; codes < 16; codes++) {
base_dist[codes] = dist;
for (n = 0; n < (1<<extra_dbits[codes]); n++) {
_dist_code[dist++] = (uch)codes;
}
}
Assert (dist == 256, "tr_static_init: dist != 256");
dist >>= 7; /* from now on, all distances are divided by 128 */
for ( ; codes < D_CODES; codes++) {
base_dist[codes] = dist << 7;
for (n = 0; n < (1<<(extra_dbits[codes]-7)); n++) {
_dist_code[256 + dist++] = (uch)codes;
}
}
Assert (dist == 256, "tr_static_init: 256+dist != 512");
/* Construct the codes of the static literal tree */
for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
n = 0;
while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
/* Codes 286 and 287 do not exist, but we must include them in the
* tree construction to get a canonical Huffman tree (longest code
* all ones)
*/
gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
/* The static distance tree is trivial: */
for (n = 0; n < D_CODES; n++) {
static_dtree[n].Len = 5;
static_dtree[n].Code = bi_reverse((unsigned)n, 5);
}
static_init_done = 1;
# ifdef GEN_TREES_H
gen_trees_header();
# endif
#endif /* defined(GEN_TREES_H) || !defined(STDC) */
}
/* ===========================================================================
* Genererate the file trees.h describing the static trees.
*/
#ifdef GEN_TREES_H
# ifndef DEBUG
# include <stdio.h>
# endif
# define SEPARATOR(i, last, width) \
((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width)-1 ? ",\n" : ", "))
void gen_trees_header(void)
{
FILE *header = fopen("trees.h", "w");
int i;
Assert (header != NULL, "Can't open trees.h");
fprintf(header,
"/* header created automatically with -DGEN_TREES_H */\n\n");
fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
for (i = 0; i < L_CODES+2; i++) {
fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
}
fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) {
fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
}
fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
for (i = 0; i < DIST_CODE_LEN; i++) {
fprintf(header, "%2u%s", _dist_code[i],
SEPARATOR(i, DIST_CODE_LEN-1, 20));
}
fprintf(header,
"const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
fprintf(header, "%2u%s", _length_code[i],
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
}
fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
for (i = 0; i < LENGTH_CODES; i++) {
fprintf(header, "%1u%s", base_length[i],
SEPARATOR(i, LENGTH_CODES-1, 20));
}
fprintf(header, "local const int base_dist[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) {
fprintf(header, "%5u%s", base_dist[i],
SEPARATOR(i, D_CODES-1, 10));
}
fclose(header);
}
#endif /* GEN_TREES_H */
/* ===========================================================================
* Initialize the tree data structures for a new zlib stream.
*/
void ZLIB_INTERNAL _tr_init(deflate_state *s)
{
tr_static_init();
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
s->d_desc.dyn_tree = s->dyn_dtree;
s->d_desc.stat_desc = &static_d_desc;
s->bl_desc.dyn_tree = s->bl_tree;
s->bl_desc.stat_desc = &static_bl_desc;
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
#endif
/* Initialize the first block of the first file: */
init_block(s);
}
/* ===========================================================================
* Initialize a new block.
@ -409,6 +152,30 @@ static void init_block(deflate_state *s)
s->last_lit = s->matches = 0;
}
/* the arguments must not have side effects */
/* ===========================================================================
* Initialize the tree data structures for a new zlib stream.
*/
void ZLIB_INTERNAL _tr_init(deflate_state *s)
{
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
s->d_desc.dyn_tree = s->dyn_dtree;
s->d_desc.stat_desc = &static_d_desc;
s->bl_desc.dyn_tree = s->bl_tree;
s->bl_desc.stat_desc = &static_bl_desc;
s->bi_buf = 0;
s->bi_valid = 0;
/* Initialize the first block of the first file: */
init_block(s);
}
#define SMALLEST 1
/* Index within the heap array of least frequent node in the Huffman tree */
@ -573,7 +340,6 @@ static void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
*/
Assert (codes + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
"inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
@ -793,8 +559,6 @@ static int build_bl_tree(deflate_state *s)
}
/* Update opt_len to include the bit length tree and counts */
s->opt_len += 3*(max_blindex+1) + 5+5+4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
s->opt_len, s->static_len));
return max_blindex;
}
@ -811,21 +575,16 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
"too many codes");
Tracev((stderr, "\nbl counts: "));
send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
send_bits(s, dcodes-1, 5);
send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
for (rank = 0; rank < blcodes; rank++) {
Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
}
Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
}
/* ===========================================================================
@ -834,11 +593,11 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
{
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
#ifdef DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3;
#endif
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
bi_windup(s); /* align on byte boundary */
put_short(s, (ush)stored_len);
put_short(s, (ush)~stored_len);
memcpy(s->pending_buf + s->pending, buf, stored_len);
s->pending += stored_len;
}
/* ===========================================================================
@ -857,9 +616,6 @@ void ZLIB_INTERNAL _tr_align(deflate_state *s)
{
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
#ifdef DEBUG
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
#endif
bi_flush(s);
}
@ -881,12 +637,8 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
/* Construct the literal and distance trees */
build_tree(s, (tree_desc *)(&(s->l_desc)));
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
s->static_len));
build_tree(s, (tree_desc *)(&(s->d_desc)));
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
s->static_len));
/* At this point, opt_len and static_len are the total bit lengths of
* the compressed block data, excluding the tree representations.
*/
@ -900,10 +652,6 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3;
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->last_lit));
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
} else {
@ -933,18 +681,12 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree);
#ifdef DEBUG
s->compressed_len += 3 + s->static_len;
#endif
} else {
send_bits(s, (DYN_TREES<<1)+last, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1);
compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree);
#ifdef DEBUG
s->compressed_len += 3 + s->opt_len;
#endif
}
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
/* The above check is made mod 2^32, for files larger than 512 MB
@ -954,12 +696,7 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
if (last) {
bi_windup(s);
#ifdef DEBUG
s->compressed_len += 7; /* align on byte boundary */
#endif
}
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
s->compressed_len-7*last));
}
/* ===========================================================================
@ -997,9 +734,6 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
(5L+extra_dbits[dcode]);
}
out_length >>= 3;
Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
s->last_lit, in_length, out_length,
100L - out_length*100L/in_length));
if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
}
#endif
@ -1141,30 +875,4 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
}
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef DEBUG
s->bits_sent = (s->bits_sent+7) & ~7;
#endif
}
/* ===========================================================================
* Copy a stored block, storing first the length and its
* one's complement if requested.
*/
static void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
{
bi_windup(s); /* align on byte boundary */
if (header) {
put_short(s, (ush)len);
put_short(s, (ush)~len);
#ifdef DEBUG
s->bits_sent += 2*16;
#endif
}
#ifdef DEBUG
s->bits_sent += (ulg)len<<3;
#endif
while (len--) {
put_byte(s, *buf++);
}
}

32
deps/libz/uncompr.c vendored
View File

@ -21,36 +21,44 @@
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
int uncompress (unsigned char *dest, uint32_t *destLen, const unsigned char *source, uint32_t sourceLen)
int uncompress (
unsigned char *dest,
uint32_t *destLen,
const unsigned char *source,
uint32_t sourceLen)
{
z_stream stream;
int err;
z_stream stream;
stream.next_in = (Bytef *)source;
stream.avail_in = (uInt)sourceLen;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */
if ((uint32_t)stream.avail_in != sourceLen) return Z_BUF_ERROR;
if ((uint32_t)stream.avail_in != sourceLen)
return Z_BUF_ERROR;
stream.next_out = dest;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uint32_t)stream.avail_out != *destLen) return Z_BUF_ERROR;
if ((uint32_t)stream.avail_out != *destLen)
return Z_BUF_ERROR;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
err = inflateInit(&stream);
if (err != Z_OK) return err;
if (err != Z_OK)
return err;
err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
{
inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
if ( err == Z_NEED_DICT ||
(err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
*destLen = stream.total_out;
err = inflateEnd(&stream);
err = inflateEnd(&stream);
return err;
}

92
deps/libz/zutil.c vendored
View File

@ -30,36 +30,63 @@ const char * zlibVersion(void)
uLong zlibCompileFlags(void)
{
uLong flags;
uLong flags = 0;
flags = 0;
switch ((int)(sizeof(uInt))) {
case 2: break;
case 4: flags += 1; break;
case 8: flags += 2; break;
default: flags += 3;
switch ((int)(sizeof(uInt)))
{
case 2:
break;
case 4:
flags += 1;
break;
case 8:
flags += 2;
break;
default:
flags += 3;
}
switch ((int)(sizeof(uLong))) {
case 2: break;
case 4: flags += 1 << 2; break;
case 8: flags += 2 << 2; break;
default: flags += 3 << 2;
switch ((int)(sizeof(uLong)))
{
case 2:
break;
case 4:
flags += 1 << 2;
break;
case 8:
flags += 2 << 2;
break;
default:
flags += 3 << 2;
}
switch ((int)(sizeof(voidpf))) {
case 2: break;
case 4: flags += 1 << 4; break;
case 8: flags += 2 << 4; break;
default: flags += 3 << 4;
switch ((int)(sizeof(voidpf)))
{
case 2:
break;
case 4:
flags += 1 << 4;
break;
case 8:
flags += 2 << 4;
break;
default:
flags += 3 << 4;
}
switch ((int)(sizeof(z_off_t))) {
case 2: break;
case 4: flags += 1 << 6; break;
case 8: flags += 2 << 6; break;
default: flags += 3 << 6;
switch ((int)(sizeof(z_off_t)))
{
case 2:
break;
case 4:
flags += 1 << 6;
break;
case 8:
flags += 2 << 6;
break;
default:
flags += 3 << 6;
}
#ifdef DEBUG
flags += 1 << 8;
#endif
#if defined(ASMV) || defined(ASMINF)
flags += 1 << 9;
#endif
@ -111,20 +138,6 @@ uLong zlibCompileFlags(void)
return flags;
}
#ifdef DEBUG
# ifndef verbose
# define verbose 0
# endif
int ZLIB_INTERNAL z_verbose = verbose;
void ZLIB_INTERNAL z_error (char *m)
{
fprintf(stderr, "%s\n", m);
exit(1);
}
#endif
/* exported to allow conversion of error code to string for compress() and
* uncompress()
*/
@ -151,5 +164,4 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
{
free(ptr);
if (opaque) return; /* make compiler happy */
}

746
deps/mbedtls/aes.c vendored
View File

@ -43,15 +43,6 @@
#include "mbedtls/aesni.h"
#endif
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */
#if !defined(MBEDTLS_AES_ALT)
#include "arc4_alt.h"
@ -84,273 +75,6 @@
static int aes_padlock_ace = -1;
#endif
#if defined(MBEDTLS_AES_ROM_TABLES)
/*
* Forward S-box
*/
static const unsigned char FSb[256] =
{
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
};
/*
* Forward tables
*/
#define FT \
\
V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \
V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \
V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \
V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \
V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \
V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \
V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \
V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \
V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \
V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \
V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \
V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \
V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \
V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \
V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \
V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \
V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \
V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \
V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \
V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \
V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \
V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \
V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \
V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \
V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \
V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \
V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \
V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \
V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \
V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \
V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \
V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \
V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \
V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \
V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \
V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \
V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \
V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \
V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \
V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \
V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \
V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \
V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \
V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \
V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \
V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \
V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \
V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \
V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \
V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \
V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \
V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \
V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \
V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \
V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \
V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \
V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \
V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \
V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \
V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \
V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \
V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \
V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \
V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C)
#define V(a,b,c,d) 0x##a##b##c##d
static const uint32_t FT0[256] = { FT };
#undef V
#define V(a,b,c,d) 0x##b##c##d##a
static const uint32_t FT1[256] = { FT };
#undef V
#define V(a,b,c,d) 0x##c##d##a##b
static const uint32_t FT2[256] = { FT };
#undef V
#define V(a,b,c,d) 0x##d##a##b##c
static const uint32_t FT3[256] = { FT };
#undef V
#undef FT
/*
* Reverse S-box
*/
static const unsigned char RSb[256] =
{
0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
};
/*
* Reverse tables
*/
#define RT \
\
V(50,A7,F4,51), V(53,65,41,7E), V(C3,A4,17,1A), V(96,5E,27,3A), \
V(CB,6B,AB,3B), V(F1,45,9D,1F), V(AB,58,FA,AC), V(93,03,E3,4B), \
V(55,FA,30,20), V(F6,6D,76,AD), V(91,76,CC,88), V(25,4C,02,F5), \
V(FC,D7,E5,4F), V(D7,CB,2A,C5), V(80,44,35,26), V(8F,A3,62,B5), \
V(49,5A,B1,DE), V(67,1B,BA,25), V(98,0E,EA,45), V(E1,C0,FE,5D), \
V(02,75,2F,C3), V(12,F0,4C,81), V(A3,97,46,8D), V(C6,F9,D3,6B), \
V(E7,5F,8F,03), V(95,9C,92,15), V(EB,7A,6D,BF), V(DA,59,52,95), \
V(2D,83,BE,D4), V(D3,21,74,58), V(29,69,E0,49), V(44,C8,C9,8E), \
V(6A,89,C2,75), V(78,79,8E,F4), V(6B,3E,58,99), V(DD,71,B9,27), \
V(B6,4F,E1,BE), V(17,AD,88,F0), V(66,AC,20,C9), V(B4,3A,CE,7D), \
V(18,4A,DF,63), V(82,31,1A,E5), V(60,33,51,97), V(45,7F,53,62), \
V(E0,77,64,B1), V(84,AE,6B,BB), V(1C,A0,81,FE), V(94,2B,08,F9), \
V(58,68,48,70), V(19,FD,45,8F), V(87,6C,DE,94), V(B7,F8,7B,52), \
V(23,D3,73,AB), V(E2,02,4B,72), V(57,8F,1F,E3), V(2A,AB,55,66), \
V(07,28,EB,B2), V(03,C2,B5,2F), V(9A,7B,C5,86), V(A5,08,37,D3), \
V(F2,87,28,30), V(B2,A5,BF,23), V(BA,6A,03,02), V(5C,82,16,ED), \
V(2B,1C,CF,8A), V(92,B4,79,A7), V(F0,F2,07,F3), V(A1,E2,69,4E), \
V(CD,F4,DA,65), V(D5,BE,05,06), V(1F,62,34,D1), V(8A,FE,A6,C4), \
V(9D,53,2E,34), V(A0,55,F3,A2), V(32,E1,8A,05), V(75,EB,F6,A4), \
V(39,EC,83,0B), V(AA,EF,60,40), V(06,9F,71,5E), V(51,10,6E,BD), \
V(F9,8A,21,3E), V(3D,06,DD,96), V(AE,05,3E,DD), V(46,BD,E6,4D), \
V(B5,8D,54,91), V(05,5D,C4,71), V(6F,D4,06,04), V(FF,15,50,60), \
V(24,FB,98,19), V(97,E9,BD,D6), V(CC,43,40,89), V(77,9E,D9,67), \
V(BD,42,E8,B0), V(88,8B,89,07), V(38,5B,19,E7), V(DB,EE,C8,79), \
V(47,0A,7C,A1), V(E9,0F,42,7C), V(C9,1E,84,F8), V(00,00,00,00), \
V(83,86,80,09), V(48,ED,2B,32), V(AC,70,11,1E), V(4E,72,5A,6C), \
V(FB,FF,0E,FD), V(56,38,85,0F), V(1E,D5,AE,3D), V(27,39,2D,36), \
V(64,D9,0F,0A), V(21,A6,5C,68), V(D1,54,5B,9B), V(3A,2E,36,24), \
V(B1,67,0A,0C), V(0F,E7,57,93), V(D2,96,EE,B4), V(9E,91,9B,1B), \
V(4F,C5,C0,80), V(A2,20,DC,61), V(69,4B,77,5A), V(16,1A,12,1C), \
V(0A,BA,93,E2), V(E5,2A,A0,C0), V(43,E0,22,3C), V(1D,17,1B,12), \
V(0B,0D,09,0E), V(AD,C7,8B,F2), V(B9,A8,B6,2D), V(C8,A9,1E,14), \
V(85,19,F1,57), V(4C,07,75,AF), V(BB,DD,99,EE), V(FD,60,7F,A3), \
V(9F,26,01,F7), V(BC,F5,72,5C), V(C5,3B,66,44), V(34,7E,FB,5B), \
V(76,29,43,8B), V(DC,C6,23,CB), V(68,FC,ED,B6), V(63,F1,E4,B8), \
V(CA,DC,31,D7), V(10,85,63,42), V(40,22,97,13), V(20,11,C6,84), \
V(7D,24,4A,85), V(F8,3D,BB,D2), V(11,32,F9,AE), V(6D,A1,29,C7), \
V(4B,2F,9E,1D), V(F3,30,B2,DC), V(EC,52,86,0D), V(D0,E3,C1,77), \
V(6C,16,B3,2B), V(99,B9,70,A9), V(FA,48,94,11), V(22,64,E9,47), \
V(C4,8C,FC,A8), V(1A,3F,F0,A0), V(D8,2C,7D,56), V(EF,90,33,22), \
V(C7,4E,49,87), V(C1,D1,38,D9), V(FE,A2,CA,8C), V(36,0B,D4,98), \
V(CF,81,F5,A6), V(28,DE,7A,A5), V(26,8E,B7,DA), V(A4,BF,AD,3F), \
V(E4,9D,3A,2C), V(0D,92,78,50), V(9B,CC,5F,6A), V(62,46,7E,54), \
V(C2,13,8D,F6), V(E8,B8,D8,90), V(5E,F7,39,2E), V(F5,AF,C3,82), \
V(BE,80,5D,9F), V(7C,93,D0,69), V(A9,2D,D5,6F), V(B3,12,25,CF), \
V(3B,99,AC,C8), V(A7,7D,18,10), V(6E,63,9C,E8), V(7B,BB,3B,DB), \
V(09,78,26,CD), V(F4,18,59,6E), V(01,B7,9A,EC), V(A8,9A,4F,83), \
V(65,6E,95,E6), V(7E,E6,FF,AA), V(08,CF,BC,21), V(E6,E8,15,EF), \
V(D9,9B,E7,BA), V(CE,36,6F,4A), V(D4,09,9F,EA), V(D6,7C,B0,29), \
V(AF,B2,A4,31), V(31,23,3F,2A), V(30,94,A5,C6), V(C0,66,A2,35), \
V(37,BC,4E,74), V(A6,CA,82,FC), V(B0,D0,90,E0), V(15,D8,A7,33), \
V(4A,98,04,F1), V(F7,DA,EC,41), V(0E,50,CD,7F), V(2F,F6,91,17), \
V(8D,D6,4D,76), V(4D,B0,EF,43), V(54,4D,AA,CC), V(DF,04,96,E4), \
V(E3,B5,D1,9E), V(1B,88,6A,4C), V(B8,1F,2C,C1), V(7F,51,65,46), \
V(04,EA,5E,9D), V(5D,35,8C,01), V(73,74,87,FA), V(2E,41,0B,FB), \
V(5A,1D,67,B3), V(52,D2,DB,92), V(33,56,10,E9), V(13,47,D6,6D), \
V(8C,61,D7,9A), V(7A,0C,A1,37), V(8E,14,F8,59), V(89,3C,13,EB), \
V(EE,27,A9,CE), V(35,C9,61,B7), V(ED,E5,1C,E1), V(3C,B1,47,7A), \
V(59,DF,D2,9C), V(3F,73,F2,55), V(79,CE,14,18), V(BF,37,C7,73), \
V(EA,CD,F7,53), V(5B,AA,FD,5F), V(14,6F,3D,DF), V(86,DB,44,78), \
V(81,F3,AF,CA), V(3E,C4,68,B9), V(2C,34,24,38), V(5F,40,A3,C2), \
V(72,C3,1D,16), V(0C,25,E2,BC), V(8B,49,3C,28), V(41,95,0D,FF), \
V(71,01,A8,39), V(DE,B3,0C,08), V(9C,E4,B4,D8), V(90,C1,56,64), \
V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0)
#define V(a,b,c,d) 0x##a##b##c##d
static const uint32_t RT0[256] = { RT };
#undef V
#define V(a,b,c,d) 0x##b##c##d##a
static const uint32_t RT1[256] = { RT };
#undef V
#define V(a,b,c,d) 0x##c##d##a##b
static const uint32_t RT2[256] = { RT };
#undef V
#define V(a,b,c,d) 0x##d##a##b##c
static const uint32_t RT3[256] = { RT };
#undef V
#undef RT
/*
* Round constants
*/
static const uint32_t RCON[10] =
{
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080,
0x0000001B, 0x00000036
};
#else /* MBEDTLS_AES_ROM_TABLES */
/*
* Forward S-box & tables
*/
@ -459,8 +183,6 @@ static void aes_gen_tables( void )
}
}
#endif /* MBEDTLS_AES_ROM_TABLES */
void mbedtls_aes_init( mbedtls_aes_context *ctx )
{
memset( ctx, 0, sizeof( mbedtls_aes_context ) );
@ -484,14 +206,12 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
unsigned int i;
uint32_t *RK;
#if !defined(MBEDTLS_AES_ROM_TABLES)
if( aes_init_done == 0 )
{
aes_gen_tables();
aes_init_done = 1;
}
#endif
switch( keybits )
{
@ -762,13 +482,6 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
}
#endif /* !MBEDTLS_AES_ENCRYPT_ALT */
void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
mbedtls_internal_aes_encrypt( ctx, input, output );
}
/*
* AES-ECB block decryption
*/
@ -828,13 +541,6 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
}
#endif /* !MBEDTLS_AES_DECRYPT_ALT */
void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
mbedtls_internal_aes_decrypt( ctx, input, output );
}
/*
* AES-ECB block encryption/decryption
*/
@ -1050,456 +756,4 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
#endif /* !MBEDTLS_AES_ALT */
#if defined(MBEDTLS_SELF_TEST)
/*
* AES test vectors from:
*
* http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip
*/
static const unsigned char aes_test_ecb_dec[3][16] =
{
{ 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 },
{ 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2,
0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 },
{ 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D,
0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
};
static const unsigned char aes_test_ecb_enc[3][16] =
{
{ 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73,
0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F },
{ 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11,
0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 },
{ 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D,
0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
};
#if defined(MBEDTLS_CIPHER_MODE_CBC)
static const unsigned char aes_test_cbc_dec[3][16] =
{
{ 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 },
{ 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75,
0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B },
{ 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75,
0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 }
};
static const unsigned char aes_test_cbc_enc[3][16] =
{
{ 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84,
0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D },
{ 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB,
0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 },
{ 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
};
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
/*
* AES-CFB128 test vectors from:
*
* http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
*/
static const unsigned char aes_test_cfb128_key[3][32] =
{
{ 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
{ 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
{ 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
};
static const unsigned char aes_test_cfb128_iv[16] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
static const unsigned char aes_test_cfb128_pt[64] =
{
0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
};
static const unsigned char aes_test_cfb128_ct[3][64] =
{
{ 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F,
0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B,
0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40,
0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF,
0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E,
0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 },
{ 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21,
0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A,
0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1,
0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9,
0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0,
0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF },
{ 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8,
0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B,
0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92,
0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9,
0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8,
0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 }
};
#endif /* MBEDTLS_CIPHER_MODE_CFB */
#if defined(MBEDTLS_CIPHER_MODE_CTR)
/*
* AES-CTR test vectors from:
*
* http://www.faqs.org/rfcs/rfc3686.html
*/
static const unsigned char aes_test_ctr_key[3][16] =
{
{ 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
{ 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
{ 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
};
static const unsigned char aes_test_ctr_nonce_counter[3][16] =
{
{ 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
{ 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
{ 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
};
static const unsigned char aes_test_ctr_pt[3][48] =
{
{ 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23 }
};
static const unsigned char aes_test_ctr_ct[3][48] =
{
{ 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79,
0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 },
{ 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9,
0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88,
0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8,
0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 },
{ 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
0x25, 0xB2, 0x07, 0x2F }
};
static const int aes_test_ctr_len[3] =
{ 16, 32, 36 };
#endif /* MBEDTLS_CIPHER_MODE_CTR */
/*
* Checkup routine
*/
int mbedtls_aes_self_test( int verbose )
{
int ret = 0, i, j, u, v;
unsigned char key[32];
unsigned char buf[64];
#if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB)
unsigned char iv[16];
#endif
#if defined(MBEDTLS_CIPHER_MODE_CBC)
unsigned char prv[16];
#endif
#if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB)
size_t offset;
#endif
#if defined(MBEDTLS_CIPHER_MODE_CTR)
int len;
unsigned char nonce_counter[16];
unsigned char stream_block[16];
#endif
mbedtls_aes_context ctx;
memset( key, 0, 32 );
mbedtls_aes_init( &ctx );
/*
* ECB mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " AES-ECB-%3d (%s): ", 128 + u * 64,
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
memset( buf, 0, 16 );
if( v == MBEDTLS_AES_DECRYPT )
{
mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
for( j = 0; j < 10000; j++ )
mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
else
{
mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
for( j = 0; j < 10000; j++ )
mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
/*
* CBC mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " AES-CBC-%3d (%s): ", 128 + u * 64,
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
memset( iv , 0, 16 );
memset( prv, 0, 16 );
memset( buf, 0, 16 );
if( v == MBEDTLS_AES_DECRYPT )
{
mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
for( j = 0; j < 10000; j++ )
mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
else
{
mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
for( j = 0; j < 10000; j++ )
{
unsigned char tmp[16];
mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
memcpy( tmp, prv, 16 );
memcpy( prv, buf, 16 );
memcpy( buf, tmp, 16 );
}
if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
/*
* CFB128 mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " AES-CFB128-%3d (%s): ", 128 + u * 64,
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
memcpy( iv, aes_test_cfb128_iv, 16 );
memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 );
offset = 0;
mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
if( v == MBEDTLS_AES_DECRYPT )
{
memcpy( buf, aes_test_cfb128_ct[u], 64 );
mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
if( memcmp( buf, aes_test_cfb128_pt, 64 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
else
{
memcpy( buf, aes_test_cfb128_pt, 64 );
mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
if( memcmp( buf, aes_test_cfb128_ct[u], 64 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#endif /* MBEDTLS_CIPHER_MODE_CFB */
#if defined(MBEDTLS_CIPHER_MODE_CTR)
/*
* CTR mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " AES-CTR-128 (%s): ",
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 );
memcpy( key, aes_test_ctr_key[u], 16 );
offset = 0;
mbedtls_aes_setkey_enc( &ctx, key, 128 );
if( v == MBEDTLS_AES_DECRYPT )
{
len = aes_test_ctr_len[u];
memcpy( buf, aes_test_ctr_ct[u], len );
mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
buf, buf );
if( memcmp( buf, aes_test_ctr_pt[u], len ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
else
{
len = aes_test_ctr_len[u];
memcpy( buf, aes_test_ctr_pt[u], len );
mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
buf, buf );
if( memcmp( buf, aes_test_ctr_ct[u], len ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#endif /* MBEDTLS_CIPHER_MODE_CTR */
ret = 0;
exit:
mbedtls_aes_free( &ctx );
return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_AES_C */

82
deps/mbedtls/arc4.c vendored
View File

@ -36,15 +36,6 @@
#include <string.h>
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */
#if !defined(MBEDTLS_ARC4_ALT)
#include "arc4_alt.h"
@ -126,77 +117,4 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
#endif /* !MBEDTLS_ARC4_ALT */
#if defined(MBEDTLS_SELF_TEST)
/*
* ARC4 tests vectors as posted by Eric Rescorla in sep. 1994:
*
* http://groups.google.com/group/comp.security.misc/msg/10a300c9d21afca0
*/
static const unsigned char arc4_test_key[3][8] =
{
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
static const unsigned char arc4_test_pt[3][8] =
{
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
static const unsigned char arc4_test_ct[3][8] =
{
{ 0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96 },
{ 0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79 },
{ 0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A }
};
/*
* Checkup routine
*/
int mbedtls_arc4_self_test( int verbose )
{
int i, ret = 0;
unsigned char ibuf[8];
unsigned char obuf[8];
mbedtls_arc4_context ctx;
mbedtls_arc4_init( &ctx );
for( i = 0; i < 3; i++ )
{
if( verbose != 0 )
mbedtls_printf( " ARC4 test #%d: ", i + 1 );
memcpy( ibuf, arc4_test_pt[i], 8 );
mbedtls_arc4_setup( &ctx, arc4_test_key[i], 8 );
mbedtls_arc4_crypt( &ctx, 8, ibuf, obuf );
if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
exit:
mbedtls_arc4_free( &ctx );
return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_ARC4_C */

View File

@ -35,13 +35,7 @@
#include "mbedtls/bignum.h"
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
#include "arc4_alt.h"
@ -266,7 +260,7 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
/* Allocate and assign next pointer */
if( *p < end )
{
cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1,
cur->next = (mbedtls_asn1_sequence*)calloc( 1,
sizeof( mbedtls_asn1_sequence ) );
if( cur->next == NULL )
@ -352,8 +346,8 @@ void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur )
if( cur == NULL )
return;
mbedtls_free( cur->oid.p );
mbedtls_free( cur->val.p );
free( cur->oid.p );
free( cur->val.p );
mbedtls_zeroize( cur, sizeof( mbedtls_asn1_named_data ) );
}
@ -366,7 +360,7 @@ void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
{
*head = cur->next;
mbedtls_asn1_free_named_data( cur );
mbedtls_free( cur );
free( cur );
}
}

View File

@ -30,14 +30,7 @@
#include "mbedtls/asn1write.h"
#include <string.h>
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
{
@ -334,27 +327,27 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
{
/* Add new entry if not present yet based on OID */
cur = (mbedtls_asn1_named_data*)mbedtls_calloc( 1,
cur = (mbedtls_asn1_named_data*)calloc( 1,
sizeof(mbedtls_asn1_named_data) );
if( cur == NULL )
return( NULL );
cur->oid.len = oid_len;
cur->oid.p = (unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)mbedtls_calloc( 1, oid_len );
cur->oid.p = (unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)calloc( 1, oid_len );
if( cur->oid.p == NULL )
{
mbedtls_free( cur );
free( cur );
return( NULL );
}
memcpy( cur->oid.p, oid, oid_len );
cur->val.len = val_len;
cur->val.p = (unsigned char*)mbedtls_calloc( 1, val_len );
cur->val.p = (unsigned char*)calloc( 1, val_len );
if( cur->val.p == NULL )
{
mbedtls_free( cur->oid.p );
mbedtls_free( cur );
free( cur->oid.p );
free( cur );
return( NULL );
}
@ -368,11 +361,11 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
* Preserve old data until the allocation succeeded, to leave list in
* a consistent state in case allocation fails.
*/
void *p = mbedtls_calloc( 1, val_len );
void *p = calloc( 1, val_len );
if( p == NULL )
return( NULL );
mbedtls_free( cur->val.p );
free( cur->val.p );
cur->val.p = (unsigned char*)p;
cur->val.len = val_len;
}

73
deps/mbedtls/base64.c vendored
View File

@ -31,16 +31,6 @@
#include <stdint.h>
#if defined(MBEDTLS_SELF_TEST)
#include <string.h>
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */
static const unsigned char base64_enc_map[64] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
@ -227,67 +217,4 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
return( 0 );
}
#if defined(MBEDTLS_SELF_TEST)
static const unsigned char base64_test_dec[64] =
{
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
};
static const unsigned char base64_test_enc[] =
"JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
"swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
/*
* Checkup routine
*/
int mbedtls_base64_self_test( int verbose )
{
size_t len;
const unsigned char *src;
unsigned char buffer[128];
if( verbose != 0 )
mbedtls_printf( " Base64 encoding test: " );
src = base64_test_dec;
if( mbedtls_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 ||
memcmp( base64_test_enc, buffer, 88 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n Base64 decoding test: " );
src = base64_test_enc;
if( mbedtls_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 ||
memcmp( base64_test_dec, buffer, 64 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n\n" );
return( 0 );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_BASE64_C */

193
deps/mbedtls/bignum.c vendored
View File

@ -48,15 +48,8 @@
#include <string.h>
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
/* Implementation that should never be optimized out by the compiler */
static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n ) {
@ -100,7 +93,7 @@ void mbedtls_mpi_free( mbedtls_mpi *X )
if( X->p != NULL )
{
mbedtls_mpi_zeroize( X->p, X->n );
mbedtls_free( X->p );
free( X->p );
}
X->s = 1;
@ -120,14 +113,14 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs )
if( X->n < nblimbs )
{
if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs, ciL ) ) == NULL )
if( ( p = (mbedtls_mpi_uint*)calloc( nblimbs, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
if( X->p != NULL )
{
memcpy( p, X->p, X->n * ciL );
mbedtls_mpi_zeroize( X->p, X->n );
mbedtls_free( X->p );
free( X->p );
}
X->n = nblimbs;
@ -158,14 +151,14 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
if( i < nblimbs )
i = nblimbs;
if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( i, ciL ) ) == NULL )
if( ( p = (mbedtls_mpi_uint*)calloc( i, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
if( X->p != NULL )
{
memcpy( p, X->p, i * ciL );
mbedtls_mpi_zeroize( X->p, X->n );
mbedtls_free( X->p );
free( X->p );
}
X->n = i;
@ -658,7 +651,7 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE
return( MBEDTLS_ERR_MPI_FILE_IO_ERROR );
}
else
mbedtls_printf( "%s%s", p, s );
printf( "%s%s", p, s );
cleanup:
@ -2270,178 +2263,4 @@ cleanup:
#endif /* MBEDTLS_GENPRIME */
#if defined(MBEDTLS_SELF_TEST)
#define GCD_PAIR_COUNT 3
static const int gcd_pairs[GCD_PAIR_COUNT][3] =
{
{ 693, 609, 21 },
{ 1764, 868, 28 },
{ 768454923, 542167814, 1 }
};
/*
* Checkup routine
*/
int mbedtls_mpi_self_test( int verbose )
{
int ret, i;
mbedtls_mpi A, E, N, X, Y, U, V;
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &X );
mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &U ); mbedtls_mpi_init( &V );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &A, 16,
"EFE021C2645FD1DC586E69184AF4A31E" \
"D5F53E93B5F123FA41680867BA110131" \
"944FE7952E2517337780CB0DB80E61AA" \
"E7C8DDC6C5C6AADEB34EB38A2F40D5E6" ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &E, 16,
"B2E7EFD37075B9F03FF989C7C5051C20" \
"34D2A323810251127E7BF8625A4F49A5" \
"F3E27F4DA8BD59C47D6DAABA4C8127BD" \
"5B5C25763222FEFCCFC38B832366C29E" ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &N, 16,
"0066A198186C18C10B2F5ED9B522752A" \
"9830B69916E535C8F047518A889A43A5" \
"94B6BED27A168D31D4A52F88925AA8F5" ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &X, &A, &N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
"602AB7ECA597A3D6B56FF9829A5E8B85" \
"9E857EA95A03512E2BAE7391688D264A" \
"A5663B0341DB9CCFD2C4C5F421FEC814" \
"8001B72E848A38CAE1C65F78E56ABDEF" \
"E12D3C039B8A02D6BE593F0BBBDA56F1" \
"ECF677152EF804370C1A305CAF3B5BF1" \
"30879B56C61DE584A0F53A2447A51E" ) );
if( verbose != 0 )
mbedtls_printf( " MPI test #1 (mul_mpi): " );
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto cleanup;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &X, &Y, &A, &N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
"256567336059E52CAE22925474705F39A94" ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &V, 16,
"6613F26162223DF488E9CD48CC132C7A" \
"0AC93C701B001B092E4E5B9F73BCD27B" \
"9EE50D0657C77F374E903CDFA4C642" ) );
if( verbose != 0 )
mbedtls_printf( " MPI test #2 (div_mpi): " );
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 ||
mbedtls_mpi_cmp_mpi( &Y, &V ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto cleanup;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &X, &A, &E, &N, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
"36E139AEA55215609D2816998ED020BB" \
"BD96C37890F65171D948E9BC7CBAA4D9" \
"325D24D6A3C12710F10A09FA08AB87" ) );
if( verbose != 0 )
mbedtls_printf( " MPI test #3 (exp_mod): " );
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto cleanup;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &X, &A, &N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
"003A0AAEDD7E784FC07D8F9EC6E3BFD5" \
"C3DBA76456363A10869622EAC2DD84EC" \
"C5B8A74DAC4D09E03B5E0BE779F2DF61" ) );
if( verbose != 0 )
mbedtls_printf( " MPI test #4 (inv_mod): " );
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto cleanup;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
if( verbose != 0 )
mbedtls_printf( " MPI test #5 (simple gcd): " );
for( i = 0; i < GCD_PAIR_COUNT; i++ )
{
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &X, gcd_pairs[i][0] ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Y, gcd_pairs[i][1] ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &A, &X, &Y ) );
if( mbedtls_mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed at %d\n", i );
ret = 1;
goto cleanup;
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
cleanup:
if( ret != 0 && verbose != 0 )
mbedtls_printf( "Unexpected error, return code = %08X\n", ret );
mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &X );
mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &U ); mbedtls_mpi_free( &V );
if( verbose != 0 )
mbedtls_printf( "\n" );
return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_BIGNUM_C */

View File

@ -37,15 +37,6 @@
#include <string.h>
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */
#if !defined(MBEDTLS_CAMELLIA_ALT)
#include "arc4_alt.h"
@ -688,382 +679,4 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
#endif /* MBEDTLS_CIPHER_MODE_CTR */
#endif /* !MBEDTLS_CAMELLIA_ALT */
#if defined(MBEDTLS_SELF_TEST)
/*
* Camellia test vectors from:
*
* http://info.isl.ntt.co.jp/crypt/eng/camellia/technology.html:
* http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/intermediate.txt
* http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/t_camellia.txt
* (For each bitlength: Key 0, Nr 39)
*/
#define CAMELLIA_TESTS_ECB 2
static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] =
{
{
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
},
{
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
},
{
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
},
};
static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] =
{
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
{ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] =
{
{
{ 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 },
{ 0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE,
0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31 }
},
{
{ 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 },
{ 0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9,
0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64 }
},
{
{ 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 },
{ 0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C,
0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35 }
}
};
#if defined(MBEDTLS_CIPHER_MODE_CBC)
#define CAMELLIA_TESTS_CBC 3
static const unsigned char camellia_test_cbc_key[3][32] =
{
{ 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
,
{ 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }
,
{ 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
};
static const unsigned char camellia_test_cbc_iv[16] =
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }
;
static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] =
{
{ 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A },
{ 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 },
{ 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF }
};
static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] =
{
{
{ 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB },
{ 0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78,
0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87 },
{ 0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B,
0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54 }
},
{
{ 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93 },
{ 0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42,
0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5 },
{ 0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8,
0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49 }
},
{
{ 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA },
{ 0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40,
0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50 },
{ 0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA,
0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 }
}
};
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CTR)
/*
* Camellia-CTR test vectors from:
*
* http://www.faqs.org/rfcs/rfc5528.html
*/
static const unsigned char camellia_test_ctr_key[3][16] =
{
{ 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
{ 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
{ 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
};
static const unsigned char camellia_test_ctr_nonce_counter[3][16] =
{
{ 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
{ 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
{ 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
};
static const unsigned char camellia_test_ctr_pt[3][48] =
{
{ 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23 }
};
static const unsigned char camellia_test_ctr_ct[3][48] =
{
{ 0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A,
0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F },
{ 0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4,
0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44,
0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7,
0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48 },
{ 0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88,
0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73,
0x9C, 0xE6, 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1,
0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD,
0xDF, 0x50, 0x86, 0x96 }
};
static const int camellia_test_ctr_len[3] =
{ 16, 32, 36 };
#endif /* MBEDTLS_CIPHER_MODE_CTR */
/*
* Checkup routine
*/
int mbedtls_camellia_self_test( int verbose )
{
int i, j, u, v;
unsigned char key[32];
unsigned char buf[64];
unsigned char src[16];
unsigned char dst[16];
#if defined(MBEDTLS_CIPHER_MODE_CBC)
unsigned char iv[16];
#endif
#if defined(MBEDTLS_CIPHER_MODE_CTR)
size_t offset, len;
unsigned char nonce_counter[16];
unsigned char stream_block[16];
#endif
mbedtls_camellia_context ctx;
memset( key, 0, 32 );
for( j = 0; j < 6; j++ ) {
u = j >> 1;
v = j & 1;
if( verbose != 0 )
mbedtls_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
(v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u );
if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 );
memcpy( src, camellia_test_ecb_cipher[u][i], 16 );
memcpy( dst, camellia_test_ecb_plain[i], 16 );
} else { /* MBEDTLS_CAMELLIA_ENCRYPT */
mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 );
memcpy( src, camellia_test_ecb_plain[i], 16 );
memcpy( dst, camellia_test_ecb_cipher[u][i], 16 );
}
mbedtls_camellia_crypt_ecb( &ctx, v, src, buf );
if( memcmp( buf, dst, 16 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
/*
* CBC mode
*/
for( j = 0; j < 6; j++ )
{
u = j >> 1;
v = j & 1;
if( verbose != 0 )
mbedtls_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" );
memcpy( src, camellia_test_cbc_iv, 16 );
memcpy( dst, camellia_test_cbc_iv, 16 );
memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u );
if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 );
} else {
mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 );
}
for( i = 0; i < CAMELLIA_TESTS_CBC; i++ ) {
if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
memcpy( iv , src, 16 );
memcpy( src, camellia_test_cbc_cipher[u][i], 16 );
memcpy( dst, camellia_test_cbc_plain[i], 16 );
} else { /* MBEDTLS_CAMELLIA_ENCRYPT */
memcpy( iv , dst, 16 );
memcpy( src, camellia_test_cbc_plain[i], 16 );
memcpy( dst, camellia_test_cbc_cipher[u][i], 16 );
}
mbedtls_camellia_crypt_cbc( &ctx, v, 16, iv, src, buf );
if( memcmp( buf, dst, 16 ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
#endif /* MBEDTLS_CIPHER_MODE_CBC */
if( verbose != 0 )
mbedtls_printf( "\n" );
#if defined(MBEDTLS_CIPHER_MODE_CTR)
/*
* CTR mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " CAMELLIA-CTR-128 (%s): ",
( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" );
memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 );
memcpy( key, camellia_test_ctr_key[u], 16 );
offset = 0;
mbedtls_camellia_setkey_enc( &ctx, key, 128 );
if( v == MBEDTLS_CAMELLIA_DECRYPT )
{
len = camellia_test_ctr_len[u];
memcpy( buf, camellia_test_ctr_ct[u], len );
mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
buf, buf );
if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
}
else
{
len = camellia_test_ctr_len[u];
memcpy( buf, camellia_test_ctr_pt[u], len );
mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
buf, buf );
if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#endif /* MBEDTLS_CIPHER_MODE_CTR */
return( 0 );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_CAMELLIA_C */

122
deps/mbedtls/ccm.c vendored
View File

@ -40,15 +40,6 @@
#include <string.h>
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
#include "arc4_alt.h"
#define CCM_ENCRYPT 0
@ -345,117 +336,4 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
return( 0 );
}
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
/*
* Examples 1 to 3 from SP800-38C Appendix C
*/
#define NB_TESTS 3
/*
* The data is the same for all tests, only the used length changes
*/
static const unsigned char ccm_key[] = {
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static const unsigned char iv[] = {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b
};
static const unsigned char ad[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13
};
static const unsigned char msg[] = {
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
};
static const size_t iv_len [NB_TESTS] = { 7, 8, 12 };
static const size_t add_len[NB_TESTS] = { 8, 16, 20 };
static const size_t msg_len[NB_TESTS] = { 4, 16, 24 };
static const size_t tag_len[NB_TESTS] = { 4, 6, 8 };
static const unsigned char res[NB_TESTS][32] = {
{ 0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d },
{ 0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62,
0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d,
0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd },
{ 0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a,
0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b,
0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5,
0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 }
};
int mbedtls_ccm_self_test( int verbose )
{
mbedtls_ccm_context ctx;
unsigned char out[32];
size_t i;
int ret;
mbedtls_ccm_init( &ctx );
if( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, ccm_key, 8 * sizeof ccm_key ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( " CCM: setup failed" );
return( 1 );
}
for( i = 0; i < NB_TESTS; i++ )
{
if( verbose != 0 )
mbedtls_printf( " CCM-AES #%u: ", (unsigned int) i + 1 );
ret = mbedtls_ccm_encrypt_and_tag( &ctx, msg_len[i],
iv, iv_len[i], ad, add_len[i],
msg, out,
out + msg_len[i], tag_len[i] );
if( ret != 0 ||
memcmp( out, res[i], msg_len[i] + tag_len[i] ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
ret = mbedtls_ccm_auth_decrypt( &ctx, msg_len[i],
iv, iv_len[i], ad, add_len[i],
res[i], out,
res[i] + msg_len[i], tag_len[i] );
if( ret != 0 ||
memcmp( out, msg, msg_len[i] ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
mbedtls_ccm_free( &ctx );
if( verbose != 0 )
mbedtls_printf( "\n" );
return( 0 );
}
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
#endif /* MBEDTLS_CCM_C */

42
deps/mbedtls/cipher.c vendored
View File

@ -45,17 +45,6 @@
#include "mbedtls/ccm.h"
#endif
#if defined(MBEDTLS_CMAC_C)
#include "mbedtls/cmac.h"
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER)
#define MBEDTLS_CIPHER_MODE_STREAM
#endif
@ -135,14 +124,6 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx )
if( ctx == NULL )
return;
#if defined(MBEDTLS_CMAC_C)
if( ctx->cmac_ctx )
{
mbedtls_zeroize( ctx->cmac_ctx, sizeof( mbedtls_cmac_context_t ) );
mbedtls_free( ctx->cmac_ctx );
}
#endif
if( ctx->cipher_ctx )
ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx );
@ -846,17 +827,20 @@ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
{
*olen = ilen;
return( mbedtls_gcm_crypt_and_tag( ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, ilen,
iv, iv_len, ad, ad_len, input, output,
tag_len, tag ) );
return( mbedtls_gcm_crypt_and_tag(
(mbedtls_gcm_context*)ctx->cipher_ctx,
MBEDTLS_GCM_ENCRYPT, ilen,
iv, iv_len, ad, ad_len, input, output,
tag_len, tag ) );
}
#endif /* MBEDTLS_GCM_C */
#if defined(MBEDTLS_CCM_C)
if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode )
{
*olen = ilen;
return( mbedtls_ccm_encrypt_and_tag( ctx->cipher_ctx, ilen,
iv, iv_len, ad, ad_len, input, output,
return( mbedtls_ccm_encrypt_and_tag(
(mbedtls_ccm_context*)ctx->cipher_ctx, ilen,
iv, iv_len, ad, ad_len, input, output,
tag, tag_len ) );
}
#endif /* MBEDTLS_CCM_C */
@ -880,9 +864,10 @@ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
int ret;
*olen = ilen;
ret = mbedtls_gcm_auth_decrypt( ctx->cipher_ctx, ilen,
iv, iv_len, ad, ad_len,
tag, tag_len, input, output );
ret = mbedtls_gcm_auth_decrypt(
(mbedtls_gcm_context*)ctx->cipher_ctx, ilen,
iv, iv_len, ad, ad_len,
tag, tag_len, input, output );
if( ret == MBEDTLS_ERR_GCM_AUTH_FAILED )
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
@ -896,7 +881,8 @@ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
int ret;
*olen = ilen;
ret = mbedtls_ccm_auth_decrypt( ctx->cipher_ctx, ilen,
ret = mbedtls_ccm_auth_decrypt(
(mbedtls_ccm_context*)ctx->cipher_ctx, ilen,
iv, iv_len, ad, ad_len,
input, output, tag, tag_len );

View File

@ -61,23 +61,14 @@
#include "mbedtls/ccm.h"
#endif
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
#include <string.h>
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
#include <string.h>
#if defined(MBEDTLS_GCM_C)
/* shared by all GCM ciphers */
static void *gcm_ctx_alloc( void )
{
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
void *ctx = calloc( 1, sizeof( mbedtls_gcm_context ) );
if( ctx != NULL )
mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
@ -88,7 +79,7 @@ static void *gcm_ctx_alloc( void )
static void gcm_ctx_free( void *ctx )
{
mbedtls_gcm_free((mbedtls_gcm_context*)ctx);
mbedtls_free(ctx);
free(ctx);
}
#endif /* MBEDTLS_GCM_C */
@ -96,7 +87,7 @@ static void gcm_ctx_free( void *ctx )
/* shared by all CCM ciphers */
static void *ccm_ctx_alloc( void )
{
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
void *ctx = calloc( 1, sizeof( mbedtls_ccm_context ) );
if( ctx != NULL )
mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
@ -107,7 +98,7 @@ static void *ccm_ctx_alloc( void )
static void ccm_ctx_free( void *ctx )
{
mbedtls_ccm_free((mbedtls_ccm_context*)ctx);
mbedtls_free( ctx );
free( ctx );
}
#endif /* MBEDTLS_CCM_C */
@ -162,7 +153,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * aes_ctx_alloc( void )
{
mbedtls_aes_context *aes = (mbedtls_aes_context*)mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
mbedtls_aes_context *aes = (mbedtls_aes_context*)calloc( 1, sizeof( mbedtls_aes_context ) );
if( aes == NULL )
return( NULL );
@ -175,7 +166,7 @@ static void * aes_ctx_alloc( void )
static void aes_ctx_free( void *ctx )
{
mbedtls_aes_free( (mbedtls_aes_context *) ctx );
mbedtls_free( ctx );
free( ctx );
}
static const mbedtls_cipher_base_t aes_info = {
@ -519,7 +510,7 @@ static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * camellia_ctx_alloc( void )
{
mbedtls_camellia_context *ctx = (mbedtls_camellia_context*)
mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
calloc( 1, sizeof( mbedtls_camellia_context ) );
if( ctx == NULL )
return( NULL );
@ -532,7 +523,7 @@ static void * camellia_ctx_alloc( void )
static void camellia_ctx_free( void *ctx )
{
mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
mbedtls_free( ctx );
free( ctx );
}
static const mbedtls_cipher_base_t camellia_info = {
@ -907,7 +898,7 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
static void * des_ctx_alloc( void )
{
mbedtls_des_context *des = (mbedtls_des_context*)
mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
calloc( 1, sizeof( mbedtls_des_context ) );
if( des == NULL )
return( NULL );
@ -920,12 +911,12 @@ static void * des_ctx_alloc( void )
static void des_ctx_free( void *ctx )
{
mbedtls_des_free( (mbedtls_des_context *) ctx );
mbedtls_free( ctx );
free( ctx );
}
static void * des3_ctx_alloc( void )
{
mbedtls_des3_context *des3 = (mbedtls_des3_context*)mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
mbedtls_des3_context *des3 = (mbedtls_des3_context*)calloc( 1, sizeof( mbedtls_des3_context ) );
if( des3 == NULL )
return( NULL );
@ -938,7 +929,7 @@ static void * des3_ctx_alloc( void )
static void des3_ctx_free( void *ctx )
{
mbedtls_des3_free( (mbedtls_des3_context *) ctx );
mbedtls_free( ctx );
free( ctx );
}
static const mbedtls_cipher_base_t des_info = {
@ -1123,7 +1114,7 @@ static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
static void * blowfish_ctx_alloc( void )
{
mbedtls_blowfish_context *ctx = (mbedtls_blowfish_context*)mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
mbedtls_blowfish_context *ctx = (mbedtls_blowfish_context*)calloc( 1, sizeof( mbedtls_blowfish_context ) );
if( ctx == NULL )
return( NULL );
@ -1136,7 +1127,7 @@ static void * blowfish_ctx_alloc( void )
static void blowfish_ctx_free( void *ctx )
{
mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
mbedtls_free( ctx );
free( ctx );
}
static const mbedtls_cipher_base_t blowfish_info = {
@ -1232,7 +1223,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
static void * arc4_ctx_alloc( void )
{
mbedtls_arc4_context *ctx = (mbedtls_arc4_context*)mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
mbedtls_arc4_context *ctx = (mbedtls_arc4_context*)calloc( 1, sizeof( mbedtls_arc4_context ) );
if( ctx == NULL )
return( NULL );
@ -1245,7 +1236,7 @@ static void * arc4_ctx_alloc( void )
static void arc4_ctx_free( void *ctx )
{
mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
mbedtls_free( ctx );
free( ctx );
}
static const mbedtls_cipher_base_t arc4_base_info = {

1071
deps/mbedtls/cmac.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -40,15 +40,6 @@
#include <stdio.h>
#endif
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */
#include "arc4_alt.h"
/*
@ -472,120 +463,4 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
}
#endif /* MBEDTLS_FS_IO */
#if defined(MBEDTLS_SELF_TEST)
static const unsigned char entropy_source_pr[96] =
{ 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16,
0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02,
0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b,
0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb,
0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9,
0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95,
0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63,
0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3,
0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31,
0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4,
0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56,
0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 };
static const unsigned char entropy_source_nopr[64] =
{ 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14,
0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe,
0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d,
0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20,
0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9,
0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46,
0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e,
0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e };
static const unsigned char nonce_pers_pr[16] =
{ 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2,
0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c };
static const unsigned char nonce_pers_nopr[16] =
{ 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5,
0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f };
static const unsigned char ctr_result_pr[16] =
{ 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f,
0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 };
static const unsigned char ctr_result_nopr[16] =
{ 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88,
0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f };
static size_t test_offset;
static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf,
size_t len )
{
const unsigned char *p = data;
memcpy( buf, p + test_offset, len );
test_offset += len;
return( 0 );
}
#define CHK( c ) if( (c) != 0 ) \
{ \
if( verbose != 0 ) \
mbedtls_printf( "failed\n" ); \
return( 1 ); \
}
/*
* Checkup routine
*/
int mbedtls_ctr_drbg_self_test( int verbose )
{
mbedtls_ctr_drbg_context ctx;
unsigned char buf[16];
mbedtls_ctr_drbg_init( &ctx );
/*
* Based on a NIST CTR_DRBG test vector (PR = True)
*/
if( verbose != 0 )
mbedtls_printf( " CTR_DRBG (PR = TRUE) : " );
test_offset = 0;
CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
(void *) entropy_source_pr, nonce_pers_pr, 16, 32 ) );
mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
CHK( memcmp( buf, ctr_result_pr, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
mbedtls_ctr_drbg_free( &ctx );
if( verbose != 0 )
mbedtls_printf( "passed\n" );
/*
* Based on a NIST CTR_DRBG test vector (PR = FALSE)
*/
if( verbose != 0 )
mbedtls_printf( " CTR_DRBG (PR = FALSE): " );
mbedtls_ctr_drbg_init( &ctx );
test_offset = 0;
CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
(void *) entropy_source_nopr, nonce_pers_nopr, 16, 32 ) );
CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
CHK( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) );
CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
CHK( memcmp( buf, ctr_result_nopr, 16 ) );
mbedtls_ctr_drbg_free( &ctx );
if( verbose != 0 )
mbedtls_printf( "passed\n" );
if( verbose != 0 )
mbedtls_printf( "\n" );
return( 0 );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_CTR_DRBG_C */

42
deps/mbedtls/debug.c vendored
View File

@ -27,15 +27,7 @@
#if defined(MBEDTLS_DEBUG_C)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#define mbedtls_time_t time_t
#define mbedtls_snprintf snprintf
#endif
#include "mbedtls/debug.h"
@ -66,7 +58,7 @@ static void debug_send_line( const mbedtls_ssl_context *ssl, int level,
*/
#if defined(MBEDTLS_THREADING_C)
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
#else
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
@ -133,7 +125,7 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
if( ret == MBEDTLS_ERR_SSL_WANT_READ )
return;
mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
text, ret, -ret );
debug_send_line( ssl, level, file, line, str );
@ -150,7 +142,7 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
return;
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
text, (unsigned int) len );
debug_send_line( ssl, level, file, line, str );
@ -166,19 +158,19 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
{
if( i > 0 )
{
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
debug_send_line( ssl, level, file, line, str );
idx = 0;
memset( txt, 0, sizeof( txt ) );
}
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
idx += snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
(unsigned int) i );
}
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x",
idx += snprintf( str + idx, sizeof( str ) - idx, " %02x",
(unsigned int) buf[i] );
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
}
@ -186,9 +178,9 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
if( len > 0 )
{
for( /* i = i */; i % 16 != 0; i++ )
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
idx += snprintf( str + idx, sizeof( str ) - idx, " " );
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
debug_send_line( ssl, level, file, line, str );
}
}
@ -203,10 +195,10 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
return;
mbedtls_snprintf( str, sizeof( str ), "%s(X)", text );
snprintf( str, sizeof( str ), "%s(X)", text );
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X );
mbedtls_snprintf( str, sizeof( str ), "%s(Y)", text );
snprintf( str, sizeof( str ), "%s(Y)", text );
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->Y );
}
#endif /* MBEDTLS_ECP_C */
@ -231,7 +223,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
if( ( ( X->p[n] >> j ) & 1 ) != 0 )
break;
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
debug_send_line( ssl, level, file, line, str );
@ -253,13 +245,13 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
{
if( j > 0 )
{
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
snprintf( str + idx, sizeof( str ) - idx, "\n" );
debug_send_line( ssl, level, file, line, str );
idx = 0;
}
}
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
idx += snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
j++;
@ -268,9 +260,9 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
}
if( zeros == 1 )
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
idx += snprintf( str + idx, sizeof( str ) - idx, " 00" );
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
snprintf( str + idx, sizeof( str ) - idx, "\n" );
debug_send_line( ssl, level, file, line, str );
}
#endif /* MBEDTLS_BIGNUM_C */
@ -298,7 +290,7 @@ static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
if( items[i].type == MBEDTLS_PK_DEBUG_NONE )
return;
mbedtls_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
name[sizeof( name ) - 1] = '\0';
if( items[i].type == MBEDTLS_PK_DEBUG_MPI )
@ -353,7 +345,7 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
{
char buf[1024];
mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
debug_send_line( ssl, level, file, line, str );
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );

256
deps/mbedtls/des.c vendored
View File

@ -37,15 +37,6 @@
#include <string.h>
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */
#if !defined(MBEDTLS_DES_ALT)
#include "arc4_alt.h"
@ -808,251 +799,4 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
#endif /* !MBEDTLS_DES_ALT */
#if defined(MBEDTLS_SELF_TEST)
/*
* DES and 3DES test vectors from:
*
* http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledes-vectors.zip
*/
static const unsigned char des3_test_keys[24] =
{
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
};
static const unsigned char des3_test_buf[8] =
{
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
};
static const unsigned char des3_test_ecb_dec[3][8] =
{
{ 0xCD, 0xD6, 0x4F, 0x2F, 0x94, 0x27, 0xC1, 0x5D },
{ 0x69, 0x96, 0xC8, 0xFA, 0x47, 0xA2, 0xAB, 0xEB },
{ 0x83, 0x25, 0x39, 0x76, 0x44, 0x09, 0x1A, 0x0A }
};
static const unsigned char des3_test_ecb_enc[3][8] =
{
{ 0x6A, 0x2A, 0x19, 0xF4, 0x1E, 0xCA, 0x85, 0x4B },
{ 0x03, 0xE6, 0x9F, 0x5B, 0xFA, 0x58, 0xEB, 0x42 },
{ 0xDD, 0x17, 0xE8, 0xB8, 0xB4, 0x37, 0xD2, 0x32 }
};
#if defined(MBEDTLS_CIPHER_MODE_CBC)
static const unsigned char des3_test_iv[8] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
};
static const unsigned char des3_test_cbc_dec[3][8] =
{
{ 0x12, 0x9F, 0x40, 0xB9, 0xD2, 0x00, 0x56, 0xB3 },
{ 0x47, 0x0E, 0xFC, 0x9A, 0x6B, 0x8E, 0xE3, 0x93 },
{ 0xC5, 0xCE, 0xCF, 0x63, 0xEC, 0xEC, 0x51, 0x4C }
};
static const unsigned char des3_test_cbc_enc[3][8] =
{
{ 0x54, 0xF1, 0x5A, 0xF6, 0xEB, 0xE3, 0xA4, 0xB4 },
{ 0x35, 0x76, 0x11, 0x56, 0x5F, 0xA1, 0x8E, 0x4D },
{ 0xCB, 0x19, 0x1F, 0x85, 0xD1, 0xED, 0x84, 0x39 }
};
#endif /* MBEDTLS_CIPHER_MODE_CBC */
/*
* Checkup routine
*/
int mbedtls_des_self_test( int verbose )
{
int i, j, u, v, ret = 0;
mbedtls_des_context ctx;
mbedtls_des3_context ctx3;
unsigned char buf[8];
#if defined(MBEDTLS_CIPHER_MODE_CBC)
unsigned char prv[8];
unsigned char iv[8];
#endif
mbedtls_des_init( &ctx );
mbedtls_des3_init( &ctx3 );
/*
* ECB mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " DES%c-ECB-%3d (%s): ",
( u == 0 ) ? ' ' : '3', 56 + u * 56,
( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
memcpy( buf, des3_test_buf, 8 );
switch( i )
{
case 0:
mbedtls_des_setkey_dec( &ctx, des3_test_keys );
break;
case 1:
mbedtls_des_setkey_enc( &ctx, des3_test_keys );
break;
case 2:
mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
break;
case 3:
mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
break;
case 4:
mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
break;
case 5:
mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
break;
default:
return( 1 );
}
for( j = 0; j < 10000; j++ )
{
if( u == 0 )
mbedtls_des_crypt_ecb( &ctx, buf, buf );
else
mbedtls_des3_crypt_ecb( &ctx3, buf, buf );
}
if( ( v == MBEDTLS_DES_DECRYPT &&
memcmp( buf, des3_test_ecb_dec[u], 8 ) != 0 ) ||
( v != MBEDTLS_DES_DECRYPT &&
memcmp( buf, des3_test_ecb_enc[u], 8 ) != 0 ) )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
if( verbose != 0 )
mbedtls_printf( "\n" );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
/*
* CBC mode
*/
for( i = 0; i < 6; i++ )
{
u = i >> 1;
v = i & 1;
if( verbose != 0 )
mbedtls_printf( " DES%c-CBC-%3d (%s): ",
( u == 0 ) ? ' ' : '3', 56 + u * 56,
( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
memcpy( iv, des3_test_iv, 8 );
memcpy( prv, des3_test_iv, 8 );
memcpy( buf, des3_test_buf, 8 );
switch( i )
{
case 0:
mbedtls_des_setkey_dec( &ctx, des3_test_keys );
break;
case 1:
mbedtls_des_setkey_enc( &ctx, des3_test_keys );
break;
case 2:
mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
break;
case 3:
mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
break;
case 4:
mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
break;
case 5:
mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
break;
default:
return( 1 );
}
if( v == MBEDTLS_DES_DECRYPT )
{
for( j = 0; j < 10000; j++ )
{
if( u == 0 )
mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
else
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
}
}
else
{
for( j = 0; j < 10000; j++ )
{
unsigned char tmp[8];
if( u == 0 )
mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
else
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
memcpy( tmp, prv, 8 );
memcpy( prv, buf, 8 );
memcpy( buf, tmp, 8 );
}
memcpy( buf, prv, 8 );
}
if( ( v == MBEDTLS_DES_DECRYPT &&
memcmp( buf, des3_test_cbc_dec[u], 8 ) != 0 ) ||
( v != MBEDTLS_DES_DECRYPT &&
memcmp( buf, des3_test_cbc_enc[u], 8 ) != 0 ) )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
}
#endif /* MBEDTLS_CIPHER_MODE_CBC */
if( verbose != 0 )
mbedtls_printf( "\n" );
exit:
mbedtls_des_free( &ctx );
mbedtls_des3_free( &ctx3 );
return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_DES_C */

59
deps/mbedtls/dhm.c vendored
View File

@ -47,15 +47,8 @@
#include "mbedtls/asn1.h"
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#include <stdio.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
#include "arc4_alt.h"
@ -530,7 +523,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
*n = (size_t) size;
if( *n + 1 == 0 ||
( *buf = (unsigned char*)mbedtls_calloc( 1, *n + 1 ) ) == NULL )
( *buf = (unsigned char*)calloc( 1, *n + 1 ) ) == NULL )
{
fclose( f );
return( MBEDTLS_ERR_DHM_ALLOC_FAILED );
@ -539,7 +532,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
if( fread( *buf, 1, *n, f ) != *n )
{
fclose( f );
mbedtls_free( *buf );
free( *buf );
return( MBEDTLS_ERR_DHM_FILE_IO_ERROR );
}
@ -568,57 +561,11 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path )
ret = mbedtls_dhm_parse_dhm( dhm, buf, n );
mbedtls_zeroize( buf, n );
mbedtls_free( buf );
free( buf );
return( ret );
}
#endif /* MBEDTLS_FS_IO */
#endif /* MBEDTLS_ASN1_PARSE_C */
#if defined(MBEDTLS_SELF_TEST)
static const char mbedtls_test_dhm_params[] =
"-----BEGIN DH PARAMETERS-----\r\n"
"MIGHAoGBAJ419DBEOgmQTzo5qXl5fQcN9TN455wkOL7052HzxxRVMyhYmwQcgJvh\r\n"
"1sa18fyfR9OiVEMYglOpkqVoGLN7qd5aQNNi5W7/C+VBdHTBJcGZJyyP5B3qcz32\r\n"
"9mLJKudlVudV0Qxk5qUJaPZ/xupz0NyoVpviuiBOI1gNi8ovSXWzAgEC\r\n"
"-----END DH PARAMETERS-----\r\n";
static const size_t mbedtls_test_dhm_params_len = sizeof( mbedtls_test_dhm_params );
/*
* Checkup routine
*/
int mbedtls_dhm_self_test( int verbose )
{
int ret;
mbedtls_dhm_context dhm;
mbedtls_dhm_init( &dhm );
if( verbose != 0 )
mbedtls_printf( " DHM parameter load: " );
if( ( ret = mbedtls_dhm_parse_dhm( &dhm,
(const unsigned char *) mbedtls_test_dhm_params,
mbedtls_test_dhm_params_len ) ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
ret = 1;
goto exit;
}
if( verbose != 0 )
mbedtls_printf( "passed\n\n" );
exit:
mbedtls_dhm_free( &dhm );
return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_DHM_C */

Some files were not shown because too many files have changed in this diff Show More