SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osx_adapter.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, SLikeSoft UG (haftungsbeschränkt)
3 *
4 * This source code is licensed under the MIT-style license found in the
5 * license.txt file in the root directory of this source tree.
6 *
7 *
8 * This file declares adapters for all MS-specific functions used throughout SLikeNet.
9 */
10 #pragma once
11
12 #ifdef __APPLE__
13 #define _TRUNCATE ((size_t)-1)
14 typedef int errno_t;
15
16 #include <cstdarg> // for va_start, va_end, va_list
17 #include <cstdio> // for FILE
18 #include <ctime> // for time_t
19
20 // MS specific security enhanced functions
21 errno_t fopen_s(FILE **pfile, const char *filename, const char *mode);
22 errno_t localtime_s(struct tm* _tm, const time_t *time);
23 errno_t mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr, size_t sizeInWords, const char *mbstr, size_t count);
24 int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
25 errno_t strcat_s(char *strDestination, size_t numberOfElements, const char *strSource);
26 errno_t strcpy_s(char* strDestination, size_t numberOfElements, const char *strSource);
27 errno_t strerror_s(char* buffer, size_t numberOfElements, int errnum);
28 errno_t strncat_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count);
29 errno_t strncpy_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count);
30 int vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format, va_list argptr);
31 errno_t wcscat_s(wchar_t *strDestination, size_t numberOfElements, const wchar_t *strSource);
32 errno_t wcscpy_s(wchar_t* strDestination, size_t numberOfElements, const wchar_t *strSource);
33
34 // corresponding template overloads
35 template<size_t BufferSize> errno_t mbstowcs_s(size_t *pReturnValue, wchar_t(&wcstr)[BufferSize], const char *mbstr, size_t count)
36 {
37 return mbstowcs_s(pReturnValue, wcstr, BufferSize, mbstr, count);
38 }
39
40 template<size_t BufferSize> int sprintf_s(char (&buffer)[BufferSize], const char* format, ...)
41 {
42 va_list arglist;
43 va_start(arglist, format);
44 int numCharsWritten = vsnprintf_s(buffer, BufferSize, BufferSize - 1, format, arglist);
45 va_end(arglist);
46
47 return numCharsWritten;
48 }
49
50 template<size_t BufferSize> errno_t strcat_s(char (&strDestination)[BufferSize], const char* strSource)
51 {
52 return strcat_s(strDestination, BufferSize, strSource);
53 }
54
55 template<size_t BufferSize> errno_t strcpy_s(char (&strDestination)[BufferSize], const char* strSource)
56 {
57 return strcpy_s(strDestination, BufferSize, strSource);
58 }
59
60 template<size_t BufferSize> errno_t strerror_s(char(&buffer)[BufferSize], int errnum)
61 {
62 return strerror_s(buffer, BufferSize, errnum);
63 }
64
65 template<size_t BufferSize> errno_t strncat_s(char(&strDest)[BufferSize], const char *strSource, size_t count)
66 {
67 return strncat_s(strDest, BufferSize, strSource, count);
68 }
69
70 template<size_t BufferSize> errno_t strncpy_s(char(&strDest)[BufferSize], const char *strSource, size_t count)
71 {
72 return strncpy_s(strDest, BufferSize, strSource, count);
73 }
74
75 template<size_t BufferSize> int vsnprintf_s(char (&buffer)[BufferSize], size_t count, const char *format, va_list argptr)
76 {
77 return vsnprintf_s(buffer, BufferSize, count, format, argptr);
78 }
79
80 #endif