added more stuff
This commit is contained in:
parent
41621b2af3
commit
b35dec2fdc
8 changed files with 274 additions and 97 deletions
|
@ -52,26 +52,30 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Resources/Version.rc.in ${CMAKE_CURRE
|
||||||
|
|
||||||
# Explicitly list source files
|
# Explicitly list source files
|
||||||
set(COMMON_SOURCES
|
set(COMMON_SOURCES
|
||||||
"src/dllmain.c"
|
src/dllmain.c
|
||||||
"src/HarmonyLinkLib.c"
|
src/HarmonyLinkLib.c
|
||||||
"src/Version.c"
|
src/Version.c
|
||||||
|
src/Utilities.c
|
||||||
|
|
||||||
"src/Structs/Battery.c"
|
src/Structs/Battery.c
|
||||||
"src/Structs/CPUInfo.c"
|
src/Structs/CPUInfo.c
|
||||||
|
src/Structs/StringArray.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# Explicitly list include files
|
# Explicitly list include files
|
||||||
set(COMMON_INCLUDES
|
set(COMMON_INCLUDES
|
||||||
"include/Core.h"
|
include/Core.h
|
||||||
"include/HarmonyLinkLib.h"
|
include/HarmonyLinkLib.h
|
||||||
"include/Version.h"
|
include/Version.h
|
||||||
|
include/Utilities.h
|
||||||
|
|
||||||
"include/Enums/Device.h"
|
include/Enums/Device.h
|
||||||
"include/Enums/Platform.h"
|
include/Enums/Platform.h
|
||||||
"include/Enums/SteamDeck.h"
|
include/Enums/SteamDeck.h
|
||||||
|
|
||||||
"include/Structs/Battery.h"
|
include/Structs/Battery.h
|
||||||
"include/Structs/CPUInfo.h"
|
include/Structs/CPUInfo.h
|
||||||
|
include/Structs/StringArray.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(WINDOWS_SOURCES
|
set(WINDOWS_SOURCES
|
||||||
|
|
|
@ -25,5 +25,7 @@ typedef struct
|
||||||
unsigned char battery_percent;
|
unsigned char battery_percent;
|
||||||
} FBattery;
|
} FBattery;
|
||||||
|
|
||||||
|
HARMONYLINKLIB_API FBattery* FBattery_Init(const FBattery* self);
|
||||||
|
|
||||||
HARMONYLINKLIB_API void FBattery_print(const FBattery* self);
|
HARMONYLINKLIB_API void FBattery_print(const FBattery* self);
|
||||||
|
|
||||||
|
|
|
@ -20,43 +20,27 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
|
#include "Structs/StringArray.h"
|
||||||
typedef struct {
|
|
||||||
char** data; // Array of strings (flags)
|
|
||||||
size_t FlagsCount; // Number of flags
|
|
||||||
} FlagsInfo;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* VendorID;
|
char* VendorID;
|
||||||
char* Model_Name;
|
char* Model_Name;
|
||||||
unsigned int Physical_Cores;
|
unsigned int Physical_Cores;
|
||||||
unsigned int Logical_Cores;
|
unsigned int Logical_Cores;
|
||||||
FlagsInfo flagsInfo;
|
StringArray flagsInfo;
|
||||||
} FCPUInfo;
|
} FCPUInfo;
|
||||||
|
|
||||||
// Initialize FlagsInfo
|
|
||||||
void FlagsInfo_Init(FlagsInfo* flagsInfo, size_t count);
|
|
||||||
|
|
||||||
// Initialize FCPUInfo
|
// Initialize FCPUInfo
|
||||||
void FCPUInfo_Init(FCPUInfo* cpuInfo, const char* vendorID, const char* modelName, unsigned int physicalCores, unsigned int logicalCores, size_t flagsCount);
|
FCPUInfo* FCPUInfo_Init(const char* vendorID, const char* modelName, unsigned int physicalCores, unsigned int logicalCores, size_t flagsCount);
|
||||||
|
|
||||||
// Print FlagsInfo
|
// Print FlagsInfo
|
||||||
HARMONYLINKLIB_API void HL_FlagsInfo_Print(const FlagsInfo* flagsInfo);
|
HARMONYLINKLIB_API void HL_FlagsInfo_Print(const FCPUInfo* cpuInfo);
|
||||||
|
|
||||||
// Print FCPUInfo
|
// Print FCPUInfo
|
||||||
HARMONYLINKLIB_API void HL_FCPUInfo_Print(const FCPUInfo* cpuInfo);
|
HARMONYLINKLIB_API void HL_FCPUInfo_Print(const FCPUInfo* cpuInfo);
|
||||||
|
|
||||||
// Free FlagsInfo
|
|
||||||
HARMONYLINKLIB_API void HL_FlagsInfo_Free(FlagsInfo* flagsInfo);
|
|
||||||
|
|
||||||
// Free FCPUInfo
|
// Free FCPUInfo
|
||||||
HARMONYLINKLIB_API void FCPUInfo_Free(FCPUInfo* cpuInfo);
|
HARMONYLINKLIB_API void HL_FCPUInfo_Free(FCPUInfo* cpuInfo);
|
||||||
|
|
||||||
// Check if a flag exists in FlagsInfo
|
// Check if a flag exists in FlagsInfo
|
||||||
HARMONYLINKLIB_API bool HL_FlagsInfo_Contains(const FlagsInfo* flagsInfo, const char* flag);
|
HARMONYLINKLIB_API bool HL_FlagsInfo_Contains(const FCPUInfo* cpuInfo, const char* flag);
|
||||||
|
|
||||||
// Add a flag to FlagsInfo
|
|
||||||
void FlagsInfo_AddFlag(FlagsInfo* flagsInfo, size_t index, const char* flag);
|
|
||||||
|
|
||||||
// Remove a flag from FlagsInfo by value
|
|
||||||
void FlagsInfo_Remove(FlagsInfo* flagsInfo, const char* flag);
|
|
||||||
|
|
51
HarmonyLinkLib/include/Structs/StringArray.h
Normal file
51
HarmonyLinkLib/include/Structs/StringArray.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (c) 2024 Jordon Brooks
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// include/Structs/StringArray.h
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "Core.h"
|
||||||
|
|
||||||
|
#define DEFAULT_INITIAL_FLAGS_SIZE 4
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char** data; // Array of strings (flags)
|
||||||
|
size_t FlagsCount; // Number of flags
|
||||||
|
size_t AllocatedSize; // Number of allocated slots
|
||||||
|
} StringArray;
|
||||||
|
|
||||||
|
// Initialize FlagsInfo
|
||||||
|
void StringArray_Init(StringArray* flagsInfo, size_t overrideInitialSize);
|
||||||
|
|
||||||
|
// Print FlagsInfo
|
||||||
|
HARMONYLINKLIB_API void HL_StringArray_Print(const StringArray* flagsInfo);
|
||||||
|
|
||||||
|
// Free FlagsInfo
|
||||||
|
HARMONYLINKLIB_API void HL_StringArray_Free(StringArray* flagsInfo);
|
||||||
|
|
||||||
|
// Check if a flag exists in FlagsInfo
|
||||||
|
HARMONYLINKLIB_API bool HL_StringArray_Contains(const StringArray* flagsInfo, const char* flag);
|
||||||
|
|
||||||
|
// Add a flag to FlagsInfo
|
||||||
|
void StringArray_AddFlag(StringArray* flagsInfo, const char* flag);
|
||||||
|
|
||||||
|
// Remove a flag from FlagsInfo by value
|
||||||
|
void StringArray_Remove(StringArray* flagsInfo, const char* flag);
|
||||||
|
|
||||||
|
// Resize FlagsInfo array
|
||||||
|
void StringArray_Resize(StringArray* flagsInfo, size_t newSize);
|
18
HarmonyLinkLib/include/Utilities.h
Normal file
18
HarmonyLinkLib/include/Utilities.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright (c) 2024 Jordon Brooks
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
// Utility function to convert char* to wchar_t*
|
||||||
|
wchar_t* convertToWideChar(const char* str);
|
|
@ -13,92 +13,66 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "Structs/CPUInfo.h"
|
#include "Structs/CPUInfo.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void FlagsInfo_Init(FlagsInfo *flagsInfo, size_t count) {
|
FCPUInfo* FCPUInfo_Init(const char *vendorID, const char *modelName, unsigned int physicalCores,
|
||||||
flagsInfo->FlagsCount = count;
|
unsigned int logicalCores, size_t flagsCount) {
|
||||||
flagsInfo->data = (char**)malloc(count * sizeof(char*));
|
FCPUInfo *cpuInfo = (FCPUInfo*)malloc(sizeof(FCPUInfo));
|
||||||
for (size_t i = 0; i < count; ++i) {
|
|
||||||
flagsInfo->data[i] = NULL;
|
if (cpuInfo == NULL) {
|
||||||
}
|
fprintf(stderr, "Memory allocation failed for FCPUInfo.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FCPUInfo_Init(FCPUInfo *cpuInfo, const char *vendorID, const char *modelName, unsigned int physicalCores,
|
cpuInfo->VendorID = _strdup(vendorID);
|
||||||
unsigned int logicalCores, size_t flagsCount) {
|
cpuInfo->Model_Name = _strdup(modelName);
|
||||||
cpuInfo->VendorID = strdup(vendorID);
|
|
||||||
cpuInfo->Model_Name = strdup(modelName);
|
|
||||||
cpuInfo->Physical_Cores = physicalCores;
|
cpuInfo->Physical_Cores = physicalCores;
|
||||||
cpuInfo->Logical_Cores = logicalCores;
|
cpuInfo->Logical_Cores = logicalCores;
|
||||||
FlagsInfo_Init(&cpuInfo->flagsInfo, flagsCount);
|
StringArray_Init(&cpuInfo->flagsInfo, flagsCount);
|
||||||
|
|
||||||
|
return cpuInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlagsInfo_AddFlag(FlagsInfo *flagsInfo, size_t index, const char *flag) {
|
void HL_FlagsInfo_Print(const FCPUInfo* cpuInfo) {
|
||||||
if (index < flagsInfo->FlagsCount) {
|
if (!cpuInfo)
|
||||||
flagsInfo->data[index] = strdup(flag);
|
{
|
||||||
}
|
fprintf(stderr, "cpuInfo is nullptr!\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HL_FlagsInfo_Print(const FlagsInfo *flagsInfo) {
|
HL_StringArray_Print(&cpuInfo->flagsInfo);
|
||||||
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
|
||||||
if (flagsInfo->data[i] != NULL) {
|
|
||||||
wprintf(L" %s\n", flagsInfo->data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HL_FCPUInfo_Print(const FCPUInfo *cpuInfo) {
|
void HL_FCPUInfo_Print(const FCPUInfo *cpuInfo) {
|
||||||
wprintf(L"VendorID: %s\n", cpuInfo->VendorID);
|
wchar_t* wVendorID = convertToWideChar(cpuInfo->VendorID);
|
||||||
wprintf(L"Model Name: %s\n", cpuInfo->Model_Name);
|
wchar_t* wModelName = convertToWideChar(cpuInfo->Model_Name);
|
||||||
|
|
||||||
|
wprintf(L"VendorID: %ls\n", wVendorID);
|
||||||
|
wprintf(L"Model Name: %ls\n", wModelName);
|
||||||
wprintf(L"Physical Cores: %u\n", cpuInfo->Physical_Cores);
|
wprintf(L"Physical Cores: %u\n", cpuInfo->Physical_Cores);
|
||||||
wprintf(L"Logical Cores: %u\n", cpuInfo->Logical_Cores);
|
wprintf(L"Logical Cores: %u\n", cpuInfo->Logical_Cores);
|
||||||
wprintf(L"Flags:\n");
|
wprintf(L"Flags:\n");
|
||||||
HL_FlagsInfo_Print(&cpuInfo->flagsInfo);
|
HL_StringArray_Print(&cpuInfo->flagsInfo);
|
||||||
|
|
||||||
|
free(wVendorID);
|
||||||
|
free(wModelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HL_FlagsInfo_Free(FlagsInfo *flagsInfo) {
|
bool HL_FlagsInfo_Contains(const FCPUInfo* cpuInfo, const char* flag) {
|
||||||
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
if (!cpuInfo)
|
||||||
free(flagsInfo->data[i]);
|
{
|
||||||
}
|
fprintf(stderr, "cpuInfo is nullptr!\n");
|
||||||
free(flagsInfo->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlagsInfo_Remove(FlagsInfo *flagsInfo, const char *flag) {
|
|
||||||
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
|
||||||
if (flagsInfo->data[i] && strcmp(flagsInfo->data[i], flag) == 0) {
|
|
||||||
free(flagsInfo->data[i]);
|
|
||||||
for (size_t j = i; j < flagsInfo->FlagsCount - 1; ++j) {
|
|
||||||
flagsInfo->data[j] = flagsInfo->data[j + 1];
|
|
||||||
}
|
|
||||||
flagsInfo->data[flagsInfo->FlagsCount - 1] = NULL;
|
|
||||||
flagsInfo->FlagsCount--;
|
|
||||||
|
|
||||||
// Use a temporary pointer to ensure realloc success
|
|
||||||
char** temp = realloc(flagsInfo->data, flagsInfo->FlagsCount * sizeof(char*));
|
|
||||||
if (temp != NULL) {
|
|
||||||
flagsInfo->data = temp;
|
|
||||||
} else if (flagsInfo->FlagsCount > 0) {
|
|
||||||
// realloc failed and we're not deallocating to zero, handle error
|
|
||||||
fprintf(stderr, "Realloc failed. Memory not reallocated.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HL_FlagsInfo_Contains(const FlagsInfo *flagsInfo, const char *flag) {
|
|
||||||
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
|
||||||
if (flagsInfo->data[i] && strcmp(flagsInfo->data[i], flag) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return HL_StringArray_Contains(&cpuInfo->flagsInfo, flag);
|
||||||
|
}
|
||||||
|
|
||||||
void HL_FCPUInfo_Free(FCPUInfo *cpuInfo) {
|
void HL_FCPUInfo_Free(FCPUInfo *cpuInfo) {
|
||||||
free(cpuInfo->VendorID);
|
free(cpuInfo->VendorID);
|
||||||
free(cpuInfo->Model_Name);
|
free(cpuInfo->Model_Name);
|
||||||
HL_FlagsInfo_Free(&cpuInfo->flagsInfo);
|
HL_StringArray_Free(&cpuInfo->flagsInfo);
|
||||||
}
|
}
|
||||||
|
|
117
HarmonyLinkLib/src/Structs/StringArray.c
Normal file
117
HarmonyLinkLib/src/Structs/StringArray.c
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
// Copyright (c) 2024 Jordon Brooks
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "Structs/StringArray.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Initialize FlagsInfo with optional initial size
|
||||||
|
void StringArray_Init(StringArray *flagsInfo, size_t overrideInitialSize) {
|
||||||
|
size_t initialSize = DEFAULT_INITIAL_FLAGS_SIZE;
|
||||||
|
|
||||||
|
if (overrideInitialSize > 0) {
|
||||||
|
initialSize = overrideInitialSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
flagsInfo->FlagsCount = 0;
|
||||||
|
flagsInfo->AllocatedSize = initialSize;
|
||||||
|
flagsInfo->data = (char**)malloc(initialSize * sizeof(char*));
|
||||||
|
for (size_t i = 0; i < initialSize; ++i) {
|
||||||
|
flagsInfo->data[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringArray_AddFlag(StringArray *flagsInfo, const char *flag) {
|
||||||
|
// Check if we need to resize the array
|
||||||
|
if (flagsInfo->FlagsCount >= flagsInfo->AllocatedSize) {
|
||||||
|
StringArray_Resize(flagsInfo, flagsInfo->AllocatedSize * 2);
|
||||||
|
}
|
||||||
|
flagsInfo->data[flagsInfo->FlagsCount] = _strdup(flag);
|
||||||
|
flagsInfo->FlagsCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HL_StringArray_Print(const StringArray *flagsInfo) {
|
||||||
|
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
||||||
|
if (flagsInfo->data[i] != NULL) {
|
||||||
|
wchar_t* wstr = convertToWideChar(flagsInfo->data[i]);
|
||||||
|
wprintf(L" %ls\n", wstr);
|
||||||
|
free(wstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HL_StringArray_Free(StringArray *flagsInfo) {
|
||||||
|
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
||||||
|
free(flagsInfo->data[i]);
|
||||||
|
}
|
||||||
|
free(flagsInfo->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringArray_Remove(StringArray *flagsInfo, const char *flag) {
|
||||||
|
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
||||||
|
if (flagsInfo->data[i] && strcmp(flagsInfo->data[i], flag) == 0) {
|
||||||
|
free(flagsInfo->data[i]);
|
||||||
|
for (size_t j = i; j < flagsInfo->FlagsCount - 1; ++j) {
|
||||||
|
flagsInfo->data[j] = flagsInfo->data[j + 1];
|
||||||
|
}
|
||||||
|
flagsInfo->data[flagsInfo->FlagsCount - 1] = NULL;
|
||||||
|
flagsInfo->FlagsCount--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HL_StringArray_Contains(const StringArray *flagsInfo, const char *flag) {
|
||||||
|
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
||||||
|
if (flagsInfo->data[i] && strcmp(flagsInfo->data[i], flag) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resize FlagsInfo array
|
||||||
|
void StringArray_Resize(StringArray* flagsInfo, size_t newSize) {
|
||||||
|
// Count the number of non-null pointers
|
||||||
|
size_t nonNullCount = 0;
|
||||||
|
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
|
||||||
|
if (flagsInfo->data[i] != NULL) {
|
||||||
|
nonNullCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the new size is smaller than the number of non-null pointers
|
||||||
|
if (newSize < nonNullCount) {
|
||||||
|
fprintf(stderr, "Resize failed. New size is smaller than the number of non-null pointers.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char** temp = realloc(flagsInfo->data, newSize * sizeof(char*));
|
||||||
|
if (temp != NULL) {
|
||||||
|
flagsInfo->data = temp;
|
||||||
|
if (newSize > flagsInfo->AllocatedSize) {
|
||||||
|
// Initialize new elements to NULL
|
||||||
|
for (size_t i = flagsInfo->AllocatedSize; i < newSize; ++i) {
|
||||||
|
flagsInfo->data[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flagsInfo->AllocatedSize = newSize;
|
||||||
|
} else {
|
||||||
|
// Handle realloc failure
|
||||||
|
fprintf(stderr, "Realloc failed. Memory not reallocated.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
27
HarmonyLinkLib/src/Utilities.c
Normal file
27
HarmonyLinkLib/src/Utilities.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (c) 2024 Jordon Brooks
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "Utilities.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
wchar_t* convertToWideChar(const char* str) {
|
||||||
|
size_t len = 0;
|
||||||
|
mbstowcs_s(&len, NULL, 0, str, 0); // Get the length of the wide string (including null terminator)
|
||||||
|
wchar_t* wstr = (wchar_t*)malloc(len * sizeof(wchar_t));
|
||||||
|
if (wstr == NULL) {
|
||||||
|
return NULL; // Handle memory allocation failure
|
||||||
|
}
|
||||||
|
mbstowcs_s(&len, wstr, len, str, len - 1);
|
||||||
|
return wstr;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue