зеркало из https://github.com/Azure/c-pal.git
fix linux string utils (#140)
* at least have the almost same header * it did not include string_utils.h * remove <<extern>> from here and everyhwere
This commit is contained in:
Родитель
2660ec8004
Коммит
4b8dd7f491
|
@ -1,62 +1,64 @@
|
|||
// Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
|
||||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdarg>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cwchar>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*note: linux implementation is missing all the wide char functions that can be found on windows implementation because the wide char functions have a completely different functionality on linux
|
||||
regarding their return value. Basically, they (swprintf and vswprintf) will return -1 when called with NULL, 0 first two arguments*/
|
||||
|
||||
#include "macro_utils/macro_utils.h"
|
||||
|
||||
#include "umock_c/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*produces a string as if printed by printf*/
|
||||
extern char* sprintf_char_function(const char* format, ...);
|
||||
|
||||
/*produces a string as if printed by printf (will also verify arguments)*/
|
||||
#define sprintf_char(format, ...) (0?printf((format), __VA_ARGS__):0, sprintf_char_function((format), __VA_ARGS__))
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_printf,
|
||||
/*produces a string as if printed by vprintf*/
|
||||
FUNCTION(, char*, vsprintf_char, const char*, format, va_list, va)
|
||||
)
|
||||
|
||||
/*
|
||||
below macros can be used with printf. example:
|
||||
printf("PartitionId = %" GUID_FORMAT "\n", GUID_VALUES(fabricDeployedStatefulServiceReplicaQueryResultItem->PartitionId)); produces on the screen:
|
||||
PartitionId=316132b8-96a0-4bc7-aecc-a16e7c5a6bf6
|
||||
*/
|
||||
#define GUID_FORMAT "8.8" PRIx32 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%12.12" PRIx64
|
||||
#define GUID_VALUES(guid) (guid).Data1, (guid).Data2, (guid).Data3, ((guid).Data4[0]<<8) + (guid).Data4[1], ((uint64_t)((guid).Data4[2])<<40) + ((uint64_t)((guid).Data4[3])<<32) + (((uint64_t)(guid).Data4[4])<<24) + ((guid).Data4[5]<<16) + ((guid).Data4[6]<<8) + ((guid).Data4[7])
|
||||
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_convert,
|
||||
/*produces the wchar_t* string representation of source (which is assumed to be multibyte). Returns NULL on any failure.*/
|
||||
FUNCTION(, wchar_t*, mbs_to_wcs, const char*, source),
|
||||
|
||||
/*produces the multibyte char* string representation of source. Returns NULL on any failure.*/
|
||||
FUNCTION(, char*, wcs_to_mbs, const wchar_t*, source)
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
// Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
|
||||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdarg>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cwchar>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*note: linux implementation is missing all the wide char functions that can be found on windows implementation because the wide char functions have a completely different functionality on linux
|
||||
regarding their return value. Basically, they (swprintf and vswprintf) will return -1 when called with NULL, 0 first two arguments*/
|
||||
|
||||
#include "macro_utils/macro_utils.h"
|
||||
|
||||
#include "umock_c/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*produces a string as if printed by printf*/
|
||||
char* sprintf_char_function(const char* format, ...);
|
||||
|
||||
/*produces a string as if printed by printf (will also verify arguments)*/
|
||||
#define sprintf_char(format, ...) (0?printf((format), __VA_ARGS__):0, sprintf_char_function((format), __VA_ARGS__))
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_printf,
|
||||
/*produces a string as if printed by vprintf*/
|
||||
FUNCTION(, char*, vsprintf_char, const char*, format, va_list, va),
|
||||
/*produces a string as if printed by vwprintf*/
|
||||
FUNCTION(, wchar_t*, vsprintf_wchar, const wchar_t*, format, va_list, va)
|
||||
)
|
||||
|
||||
/*
|
||||
below macros can be used with printf. example:
|
||||
printf("PartitionId = %" GUID_FORMAT "\n", GUID_VALUES(fabricDeployedStatefulServiceReplicaQueryResultItem->PartitionId)); produces on the screen:
|
||||
PartitionId=316132b8-96a0-4bc7-aecc-a16e7c5a6bf6
|
||||
*/
|
||||
#define GUID_FORMAT "8.8" PRIx32 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%12.12" PRIx64
|
||||
#define GUID_VALUES(guid) (guid).Data1, (guid).Data2, (guid).Data3, ((guid).Data4[0]<<8) + (guid).Data4[1], ((uint64_t)((guid).Data4[2])<<40) + ((uint64_t)((guid).Data4[3])<<32) + (((uint64_t)(guid).Data4[4])<<24) + ((guid).Data4[5]<<16) + ((guid).Data4[6]<<8) + ((guid).Data4[7])
|
||||
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_convert,
|
||||
/*produces the wchar_t* string representation of source (which is assumed to be multibyte). Returns NULL on any failure.*/
|
||||
FUNCTION(, wchar_t*, mbs_to_wcs, const char*, source),
|
||||
|
||||
/*produces the multibyte char* string representation of source. Returns NULL on any failure.*/
|
||||
FUNCTION(, char*, wcs_to_mbs, const wchar_t*, source)
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,5 +21,5 @@ set(linux_reals_h_files
|
|||
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../src)
|
||||
add_library(linux_reals ${linux_reals_c_files} ${linux_reals_h_files})
|
||||
target_include_directories(linux_reals PUBLIC . ${CMAKE_CURRENT_LIST_DIR}/../../common/reals)
|
||||
target_include_directories(linux_reals PUBLIC . ${CMAKE_CURRENT_LIST_DIR}/../../common/reals ${CMAKE_CURRENT_LIST_DIR}/../inc)
|
||||
target_link_libraries(linux_reals pal_interfaces pal_interfaces_reals rt uuid pthread)
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
#undef errno
|
||||
#define errno mock_errno
|
||||
|
||||
extern int mock_errno;
|
||||
int mock_errno;
|
||||
|
||||
#include "../../src/sync_linux.c"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#define sysconf mocked_sysconf
|
||||
|
||||
extern long mocked_sysconf(int name);
|
||||
|
||||
#include "../../src/sysinfo_linux.c"
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#define sysconf mocked_sysconf
|
||||
|
||||
long mocked_sysconf(int name);
|
||||
|
||||
#include "../../src/sysinfo_linux.c"
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
// Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
|
||||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdarg>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cwchar>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#include "macro_utils/macro_utils.h"
|
||||
|
||||
#include "umock_c/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*produces a string as if printed by printf*/
|
||||
extern char* sprintf_char_function(const char* format, ...);
|
||||
|
||||
/*produces a string as if printed by printf (will also verify arguments)*/
|
||||
#define sprintf_char(format, ...) (0?printf((format), ## __VA_ARGS__):0, sprintf_char_function((format), ##__VA_ARGS__))
|
||||
|
||||
/*produces a string as if printed by wprintf*/
|
||||
extern wchar_t* sprintf_wchar_function(const wchar_t* format, ...);
|
||||
#define sprintf_wchar(format, ...) (0?wprintf((format), ##__VA_ARGS__):0, sprintf_wchar_function((format), ##__VA_ARGS__))
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_printf,
|
||||
/*produces a string as if printed by vprintf*/
|
||||
FUNCTION(, char*, vsprintf_char, const char*, format, va_list, va),
|
||||
/*produces a string as if printed by vwprintf*/
|
||||
FUNCTION(, wchar_t*, vsprintf_wchar, const wchar_t*, format, va_list, va)
|
||||
)
|
||||
|
||||
/*
|
||||
below macros can be used with printf. example:
|
||||
printf("PartitionId = %" GUID_FORMAT "\n", GUID_VALUES(fabricDeployedStatefulServiceReplicaQueryResultItem->PartitionId)); produces on the screen:
|
||||
PartitionId=316132b8-96a0-4bc7-aecc-a16e7c5a6bf6
|
||||
*/
|
||||
#define GUID_FORMAT "8.8" PRIx32 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%12.12" PRIx64
|
||||
#define GUID_VALUES(guid) (uint32_t)(guid).Data1, (uint16_t)(guid).Data2, (uint16_t)(guid).Data3, (uint16_t)(((guid).Data4[0]<<8) + (guid).Data4[1]), (uint64_t)((uint64_t)((guid).Data4[2])<<40) + ((uint64_t)((guid).Data4[3])<<32) + (((uint64_t)(guid).Data4[4])<<24) + ((guid).Data4[5]<<16) + ((guid).Data4[6]<<8) + ((guid).Data4[7])
|
||||
|
||||
/*takes a FILETIME, returns a nice string representation of it*/
|
||||
MOCKABLE_FUNCTION(, char*, FILETIME_toAsciiArray, const FILETIME*, fileTime);
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_convert,
|
||||
/*produces the wchar_t* string representation of source (which is assumed to be multibyte). Returns NULL on any failure.*/
|
||||
FUNCTION(, wchar_t*, mbs_to_wcs, const char*, source),
|
||||
|
||||
/*produces the multibyte char* string representation of source. Returns NULL on any failure.*/
|
||||
FUNCTION(, char*, wcs_to_mbs, const wchar_t*, source)
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
// Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
|
||||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdarg>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cwchar>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#include "macro_utils/macro_utils.h"
|
||||
|
||||
#include "umock_c/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*produces a string as if printed by printf*/
|
||||
char* sprintf_char_function(const char* format, ...);
|
||||
|
||||
/*produces a string as if printed by printf (will also verify arguments)*/
|
||||
#define sprintf_char(format, ...) (0?printf((format), ## __VA_ARGS__):0, sprintf_char_function((format), ##__VA_ARGS__))
|
||||
|
||||
/*produces a string as if printed by wprintf*/
|
||||
wchar_t* sprintf_wchar_function(const wchar_t* format, ...);
|
||||
#define sprintf_wchar(format, ...) (0?wprintf((format), ##__VA_ARGS__):0, sprintf_wchar_function((format), ##__VA_ARGS__))
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_printf,
|
||||
/*produces a string as if printed by vprintf*/
|
||||
FUNCTION(, char*, vsprintf_char, const char*, format, va_list, va),
|
||||
/*produces a string as if printed by vwprintf*/
|
||||
FUNCTION(, wchar_t*, vsprintf_wchar, const wchar_t*, format, va_list, va)
|
||||
)
|
||||
|
||||
/*
|
||||
below macros can be used with printf. example:
|
||||
printf("PartitionId = %" GUID_FORMAT "\n", GUID_VALUES(fabricDeployedStatefulServiceReplicaQueryResultItem->PartitionId)); produces on the screen:
|
||||
PartitionId=316132b8-96a0-4bc7-aecc-a16e7c5a6bf6
|
||||
*/
|
||||
#define GUID_FORMAT "8.8" PRIx32 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%4.4" PRIx16 "-%12.12" PRIx64
|
||||
#define GUID_VALUES(guid) (uint32_t)(guid).Data1, (uint16_t)(guid).Data2, (uint16_t)(guid).Data3, (uint16_t)(((guid).Data4[0]<<8) + (guid).Data4[1]), (uint64_t)((uint64_t)((guid).Data4[2])<<40) + ((uint64_t)((guid).Data4[3])<<32) + (((uint64_t)(guid).Data4[4])<<24) + ((guid).Data4[5]<<16) + ((guid).Data4[6]<<8) + ((guid).Data4[7])
|
||||
|
||||
/*takes a FILETIME, returns a nice string representation of it*/
|
||||
MOCKABLE_FUNCTION(, char*, FILETIME_toAsciiArray, const FILETIME*, fileTime);
|
||||
|
||||
MOCKABLE_INTERFACE(string_utils_convert,
|
||||
/*produces the wchar_t* string representation of source (which is assumed to be multibyte). Returns NULL on any failure.*/
|
||||
FUNCTION(, wchar_t*, mbs_to_wcs, const char*, source),
|
||||
|
||||
/*produces the multibyte char* string representation of source. Returns NULL on any failure.*/
|
||||
FUNCTION(, char*, wcs_to_mbs, const wchar_t*, source)
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#define CreateThreadpool mocked_CreateThreadpool
|
||||
#define CloseThreadpool mocked_CloseThreadpool
|
||||
#define SetThreadpoolThreadMinimum mocked_SetThreadpoolThreadMinimum
|
||||
#define SetThreadpoolThreadMaximum mocked_SetThreadpoolThreadMaximum
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#pragma warning(disable: 4273)
|
||||
|
||||
extern PTP_POOL WINAPI mocked_CreateThreadpool(LPVOID reserved);
|
||||
|
||||
#include "../../src/execution_engine_win32.c"
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#define CreateThreadpool mocked_CreateThreadpool
|
||||
#define CloseThreadpool mocked_CloseThreadpool
|
||||
#define SetThreadpoolThreadMinimum mocked_SetThreadpoolThreadMinimum
|
||||
#define SetThreadpoolThreadMaximum mocked_SetThreadpoolThreadMaximum
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#pragma warning(disable: 4273)
|
||||
|
||||
PTP_POOL WINAPI mocked_CreateThreadpool(LPVOID reserved);
|
||||
|
||||
#include "../../src/execution_engine_win32.c"
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
#define HeapReAlloc mock_HeapReAlloc
|
||||
#define HeapFree mock_HeapFree
|
||||
|
||||
extern HANDLE mock_HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
|
||||
extern BOOL mock_HeapDestroy(HANDLE hHeap);
|
||||
extern LPVOID mock_HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
|
||||
extern LPVOID mock_HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
|
||||
extern BOOL mock_HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
|
||||
HANDLE mock_HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
|
||||
BOOL mock_HeapDestroy(HANDLE hHeap);
|
||||
LPVOID mock_HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
|
||||
LPVOID mock_HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
|
||||
BOOL mock_HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
|
||||
|
||||
#include "../../src/gballoc_hl_metrics.c"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#define GetSystemInfo mocked_GetSystemInfo
|
||||
|
||||
extern void mocked_GetSystemInfo(LPSYSTEM_INFO lpSystemInfo);
|
||||
|
||||
#include "../../src/sysinfo_win32.c"
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#define GetSystemInfo mocked_GetSystemInfo
|
||||
|
||||
void mocked_GetSystemInfo(LPSYSTEM_INFO lpSystemInfo);
|
||||
|
||||
#include "../../src/sysinfo_win32.c"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
|
||||
#define QueryPerformanceFrequency mocked_QueryPerformanceFrequency
|
||||
#define QueryPerformanceCounter mocked_QueryPerformanceCounter
|
||||
|
||||
|
||||
extern BOOLEAN mocked_QueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount);
|
||||
extern BOOLEAN mocked_QueryPerformanceFrequency(LARGE_INTEGER* lpFrequency);
|
||||
|
||||
#include "../../src/timer_win32.c"
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
|
||||
#define QueryPerformanceFrequency mocked_QueryPerformanceFrequency
|
||||
#define QueryPerformanceCounter mocked_QueryPerformanceCounter
|
||||
|
||||
|
||||
BOOLEAN mocked_QueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount);
|
||||
BOOLEAN mocked_QueryPerformanceFrequency(LARGE_INTEGER* lpFrequency);
|
||||
|
||||
#include "../../src/timer_win32.c"
|
||||
|
|
Загрузка…
Ссылка в новой задаче