Skip to content

Commit

Permalink
- added missing strerror_s() Linux/OSX adapter (#273)
Browse files Browse the repository at this point in the history
- minor tweaks (facebookarchive#130, #269)
  • Loading branch information
Luke1410 committed Sep 2, 2019
1 parent 7b24c06 commit 9430ab7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Source/include/slikenet/linux_adapter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, SLikeSoft UG (haftungsbeschränkt)
* Copyright (c) 2016-2019, SLikeSoft UG (haftungsbeschränkt)
*
* This source code is licensed under the MIT-style license found in the
* license.txt file in the root directory of this source tree.
Expand All @@ -24,6 +24,7 @@ errno_t mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr, size_t sizeInWords, con
int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
errno_t strcat_s(char *strDestination, size_t numberOfElements, const char *strSource);
errno_t strcpy_s(char* strDestination, size_t numberOfElements, const char *strSource);
errno_t strerror_s(char* buffer, size_t numberOfElements, int errnum);
errno_t strncat_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count);
errno_t strncpy_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count);
int vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format, va_list argptr);
Expand Down Expand Up @@ -56,6 +57,11 @@ template<size_t BufferSize> errno_t strcpy_s(char (&strDestination)[BufferSize],
return strcpy_s(strDestination, BufferSize, strSource);
}

template<size_t BufferSize> errno_t strerror_s(char(&buffer)[BufferSize], int errnum)
{
return strerror_s(buffer, BufferSize, errnum);
}

template<size_t BufferSize> errno_t strncat_s(char(&strDest)[BufferSize], const char *strSource, size_t count)
{
return strncat_s(strDest, BufferSize, strSource, count);
Expand Down
12 changes: 9 additions & 3 deletions Source/include/slikenet/osx_adapter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, SLikeSoft UG (haftungsbeschränkt)
* Copyright (c) 2016-2019, SLikeSoft UG (haftungsbeschränkt)
*
* This source code is licensed under the MIT-style license found in the
* license.txt file in the root directory of this source tree.
Expand All @@ -24,6 +24,7 @@ errno_t mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr, size_t sizeInWords, con
int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
errno_t strcat_s(char *strDestination, size_t numberOfElements, const char *strSource);
errno_t strcpy_s(char* strDestination, size_t numberOfElements, const char *strSource);
errno_t strerror_s(char* buffer, size_t numberOfElements, int errnum);
errno_t strncat_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count);
errno_t strncpy_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count);
int vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format, va_list argptr);
Expand Down Expand Up @@ -56,12 +57,17 @@ template<size_t BufferSize> errno_t strcpy_s(char (&strDestination)[BufferSize],
return strcpy_s(strDestination, BufferSize, strSource);
}

template<size_t BufferSize> errno_t strncat_s(char(&strDest)[BufferSize], const char *strSource, size_t count)
template<size_t BufferSize> errno_t strerror_s(char(&buffer)[BufferSize], int errnum)
{
return strerror_s(buffer, BufferSize, errnum);
}

template<size_t BufferSize> errno_t strncat_s(char (&strDest)[BufferSize], const char *strSource, size_t count)
{
return strncat_s(strDest, BufferSize, strSource, count);
}

template<size_t BufferSize> errno_t strncpy_s(char(&strDest)[BufferSize], const char *strSource, size_t count)
template<size_t BufferSize> errno_t strncpy_s(char (&strDest)[BufferSize], const char *strSource, size_t count)
{
return strncpy_s(strDest, BufferSize, strSource, count);
}
Expand Down
15 changes: 13 additions & 2 deletions Source/src/linux_adapter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017, SLikeSoft UG (haftungsbeschränkt)
* Copyright (c) 2016-2019, SLikeSoft UG (haftungsbeschränkt)
*
* This source code is licensed under the MIT-style license found in the
* license.txt file in the root directory of this source tree.
Expand All @@ -15,7 +15,7 @@
#include <cerrno> // for errno
#include <cstdio> // for FILE, fopen, vsnprintf
#include <cstdlib> // for mbstowcs
#include <cstring> // for strcat, strcpy, strncat, strncpy
#include <cstring> // for strcat, strcpy, strerror, strncat, strncpy
#include <cstdarg> // for va_start, va_end, va_list
#include <ctime> // for localtime, time_t
#include <cwchar> // for wcscat, wcscpy, wcslen
Expand Down Expand Up @@ -171,6 +171,17 @@ errno_t strcpy_s(char* strDestination, size_t numberOfElements, const char *strS
return 0;
}

errno_t strerror_s(char* buffer, size_t numberOfElements, int errnum)
{
// check valid parameters
if ((buffer == nullptr) || (numberOfElements == 0)) {
return 22; // error: EINVAL
}

const char *errorMessage = strerror(errnum);
return strcpy_s(buffer, numberOfElements, errorMessage);
}

errno_t strncat_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count)
{
// check valid parameters
Expand Down
15 changes: 13 additions & 2 deletions Source/src/osx_adapter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017, SLikeSoft UG (haftungsbeschränkt)
* Copyright (c) 2016-2019, SLikeSoft UG (haftungsbeschränkt)
*
* This source code is licensed under the MIT-style license found in the
* license.txt file in the root directory of this source tree.
Expand All @@ -15,7 +15,7 @@
#include <cerrno> // for errno
#include <cstdio> // for FILE, fopen, vsnprintf
#include <cstdlib> // for mbstowcs
#include <cstring> // for strcat, strcpy, strncat, strncpy
#include <cstring> // for strcat, strcpy, strerror, strncat, strncpy
#include <cstdarg> // for va_start, va_end, va_list
#include <ctime> // for localtime, time_t
#include <cwchar> // for wcscat, wcscpy, wcslen
Expand Down Expand Up @@ -171,6 +171,17 @@ errno_t strcpy_s(char* strDestination, size_t numberOfElements, const char *strS
return 0;
}

errno_t strerror_s(char* buffer, size_t numberOfElements, int errnum)
{
// check valid parameters
if ((buffer == nullptr) || (numberOfElements == 0)) {
return 22; // error: EINVAL
}

const char *errorMessage = strerror(errnum);
return strcpy_s(buffer, numberOfElements, errorMessage);
}

errno_t strncat_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count)
{
// check valid parameters
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Core:
Building:
General:
* fixed compile errors when enabling IPv6 on Linux/OSX (#220)
* fixed compile error when enabling OPENSSL on Linux/OSX (#273)
CrashReporter:
* fixed compile error when compiling in RAKNET_COMPATIBILITY mode (#223)
Lobby2:
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ Lib/prebuild/VS_xxxx/SLikeNet_DLL_[configuration]_[core|ext]_[platform].dll
to the directory where the C# executable will be built to and rename it to
SLikeNet.dll.
On Linux you are required to build a shared library yourself since SLikeNet
isn't shipped with prebuilds for Linux. Simply follow the steps under 3.7.3.2
doesn't ship with prebuilds for Linux. Simply follow the steps under 3.7.3.2
which will take care about building such library and put it into an
appropriate directory.

Expand Down

0 comments on commit 9430ab7

Please sign in to comment.