diff --git a/include/sdutils/sdutils.h b/include/sdutils/sdutils.h
index a0d7510..0f1c380 100644
--- a/include/sdutils/sdutils.h
+++ b/include/sdutils/sdutils.h
@@ -19,7 +19,7 @@ enum SDUtilsStatus {
};
typedef uint32_t SDUtilsVersion;
-#define SDUTILS_MODULE_VERSION 0x00000001
+#define SD_UTILS_MODULE_VERSION_ERROR 0xFFFFFFFF
enum SDUtilsAttachStatus {
SDUTILS_ATTACH_MOUNTED = 1,
@@ -45,11 +45,17 @@ SDUtilsStatus SDUtils_InitLibrary();
SDUtilsStatus SDUtils_DeInitLibrary();
/**
- * Returns the API Version of the WUHBUtils Module.
- * @return The WUHBUtilsVersion of the Module
+ * Retrieves the API Version of the loaded SDUtils.
+ *
+ * @param outVersion pointer to the variable where the version will be stored.
+ *
+ * @return SDUTILS_RESULT_SUCCESS: The API version has been store in the version ptr.
+ * SDUTILS_RESULT_MODULE_NOT_FOUND: The module could not be found. Make sure the module is loaded.
+ * SDUTILS_RESULT_MODULE_MISSING_EXPORT: The module is missing an expected export.
+ * SDUTILS_RESULT_INVALID_ARGUMENT: Invalid version pointer.
+ * SDUTILS_RESULT_UNKNOWN_ERROR: Retrieving the module version failed.
*/
-SDUtilsVersion SDUtils_GetVersion();
-
+SDUtilsStatus SDUtils_GetVersion(SDUtilsVersion *outVersion);
/**
* Registers a callback which will be called whenever a sd card will be inserted or ejected.
diff --git a/source/utils.cpp b/source/utils.cpp
index 4b896ef..fa08db0 100644
--- a/source/utils.cpp
+++ b/source/utils.cpp
@@ -5,7 +5,7 @@
static OSDynLoad_Module sModuleHandle = nullptr;
-static SDUtilsVersion (*sSDUtilsGetVersion)() = nullptr;
+static SDUtilsStatus (*sSDUtilsGetVersion)(SDUtilsVersion *) = nullptr;
static bool (*sSDUtilsAddAttachHandler)(SDAttachHandlerFn) = nullptr;
static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr;
@@ -13,6 +13,8 @@ static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr;
static bool (*sSDUtilsAddCleanUpHandlesHandler)(SDCleanUpHandlesHandlerFn) = nullptr;
static bool (*sSDUtilsRemoveCleanUpHandlesHandler)(SDCleanUpHandlesHandlerFn) = nullptr;
+static SDUtilsVersion sSDUtilsVersion = SD_UTILS_MODULE_VERSION_ERROR;
+
SDUtilsStatus SDUtils_InitLibrary() {
if (OSDynLoad_Acquire("homebrew_sdhotswap", &sModuleHandle) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: OSDynLoad_Acquire failed.\n");
@@ -23,8 +25,9 @@ SDUtilsStatus SDUtils_InitLibrary() {
OSReport("SDUtils_Init: SDUtilsGetVersion failed.\n");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
}
- auto res = SDUtils_GetVersion();
- if (res != SDUTILS_MODULE_VERSION) {
+
+ auto res = SDUtils_GetVersion(&sSDUtilsVersion);
+ if (res != SDUTILS_RESULT_SUCCESS) {
return SDUTILS_RESULT_UNSUPPORTED_VERSION;
}
@@ -56,13 +59,12 @@ SDUtilsStatus SDUtils_DeInitLibrary() {
return SDUTILS_RESULT_SUCCESS;
}
-SDUtilsVersion GetVersion();
-SDUtilsVersion SDUtils_GetVersion() {
- if (sSDUtilsGetVersion == nullptr) {
- return SDUTILS_RESULT_LIB_UNINITIALIZED;
+SDUtilsStatus GetVersion(SDUtilsVersion *);
+SDUtilsStatus SDUtils_GetVersion(SDUtilsVersion *version) {
+ if (version == nullptr) {
+ return SDUTILS_RESULT_INVALID_ARGUMENT;
}
-
- return reinterpret_cast(sSDUtilsGetVersion)();
+ return reinterpret_cast(sSDUtilsGetVersion)(version);
}
SDUtilsStatus SDUtils_IsSdCardMounted(bool *status) {