ssh
wolfssh/port.h@0:c4152c628df5, 2019-11-25 (annotated)
- Committer:
- sPymbed
- Date:
- Mon Nov 25 14:24:05 2019 +0000
- Revision:
- 0:c4152c628df5
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sPymbed | 0:c4152c628df5 | 1 | /* port.h |
sPymbed | 0:c4152c628df5 | 2 | * |
sPymbed | 0:c4152c628df5 | 3 | * Copyright (C) 2014-2016 wolfSSL Inc. |
sPymbed | 0:c4152c628df5 | 4 | * |
sPymbed | 0:c4152c628df5 | 5 | * This file is part of wolfSSH. |
sPymbed | 0:c4152c628df5 | 6 | * |
sPymbed | 0:c4152c628df5 | 7 | * wolfSSH is free software; you can redistribute it and/or modify |
sPymbed | 0:c4152c628df5 | 8 | * it under the terms of the GNU General Public License as published by |
sPymbed | 0:c4152c628df5 | 9 | * the Free Software Foundation; either version 3 of the License, or |
sPymbed | 0:c4152c628df5 | 10 | * (at your option) any later version. |
sPymbed | 0:c4152c628df5 | 11 | * |
sPymbed | 0:c4152c628df5 | 12 | * wolfSSH is distributed in the hope that it will be useful, |
sPymbed | 0:c4152c628df5 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
sPymbed | 0:c4152c628df5 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
sPymbed | 0:c4152c628df5 | 15 | * GNU General Public License for more details. |
sPymbed | 0:c4152c628df5 | 16 | * |
sPymbed | 0:c4152c628df5 | 17 | * You should have received a copy of the GNU General Public License |
sPymbed | 0:c4152c628df5 | 18 | * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>. |
sPymbed | 0:c4152c628df5 | 19 | */ |
sPymbed | 0:c4152c628df5 | 20 | |
sPymbed | 0:c4152c628df5 | 21 | |
sPymbed | 0:c4152c628df5 | 22 | /* |
sPymbed | 0:c4152c628df5 | 23 | * The port module wraps standard C library functions with macros to |
sPymbed | 0:c4152c628df5 | 24 | * cover portablility issues when building in environments that rename |
sPymbed | 0:c4152c628df5 | 25 | * those functions. This module also provides local versions of some |
sPymbed | 0:c4152c628df5 | 26 | * standard C library functions that are missing on some platforms. |
sPymbed | 0:c4152c628df5 | 27 | */ |
sPymbed | 0:c4152c628df5 | 28 | |
sPymbed | 0:c4152c628df5 | 29 | |
sPymbed | 0:c4152c628df5 | 30 | #pragma once |
sPymbed | 0:c4152c628df5 | 31 | |
sPymbed | 0:c4152c628df5 | 32 | #include <wolfssh/settings.h> |
sPymbed | 0:c4152c628df5 | 33 | #include <stdio.h> |
sPymbed | 0:c4152c628df5 | 34 | |
sPymbed | 0:c4152c628df5 | 35 | #ifdef __cplusplus |
sPymbed | 0:c4152c628df5 | 36 | extern "C" { |
sPymbed | 0:c4152c628df5 | 37 | #endif |
sPymbed | 0:c4152c628df5 | 38 | |
sPymbed | 0:c4152c628df5 | 39 | |
sPymbed | 0:c4152c628df5 | 40 | /* setup memory handling */ |
sPymbed | 0:c4152c628df5 | 41 | #ifndef WMALLOC_USER |
sPymbed | 0:c4152c628df5 | 42 | #include <wolfssh/memory.h> |
sPymbed | 0:c4152c628df5 | 43 | |
sPymbed | 0:c4152c628df5 | 44 | #define WMALLOC(s, h, t) ((void)h, (void)t, wolfSSH_Malloc((s))) |
sPymbed | 0:c4152c628df5 | 45 | #define WFREE(p, h, t) {void* xp = (p); if ((xp)) wolfSSH_Free((xp));} |
sPymbed | 0:c4152c628df5 | 46 | #define WREALLOC(p, n, h, t) wolfSSH_Realloc((p), (n)) |
sPymbed | 0:c4152c628df5 | 47 | #endif /* WMALLOC_USER */ |
sPymbed | 0:c4152c628df5 | 48 | |
sPymbed | 0:c4152c628df5 | 49 | |
sPymbed | 0:c4152c628df5 | 50 | /* setup string handling */ |
sPymbed | 0:c4152c628df5 | 51 | #ifndef WSTRING_USER |
sPymbed | 0:c4152c628df5 | 52 | #include <string.h> |
sPymbed | 0:c4152c628df5 | 53 | |
sPymbed | 0:c4152c628df5 | 54 | #define WFILE FILE |
sPymbed | 0:c4152c628df5 | 55 | |
sPymbed | 0:c4152c628df5 | 56 | WOLFSSH_API char* wstrnstr(const char*, const char*, unsigned int); |
sPymbed | 0:c4152c628df5 | 57 | WOLFSSH_API int wfopen(WFILE**, const char*, const char*); |
sPymbed | 0:c4152c628df5 | 58 | |
sPymbed | 0:c4152c628df5 | 59 | #define WMEMCPY(d,s,l) memcpy((d),(s),(l)) |
sPymbed | 0:c4152c628df5 | 60 | #define WMEMSET(b,c,l) memset((b),(c),(l)) |
sPymbed | 0:c4152c628df5 | 61 | #define WMEMCMP(s1,s2,n) memcmp((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 62 | #define WMEMMOVE(d,s,l) memmove((d),(s),(l)) |
sPymbed | 0:c4152c628df5 | 63 | |
sPymbed | 0:c4152c628df5 | 64 | #define WSTRLEN(s1) strlen((s1)) |
sPymbed | 0:c4152c628df5 | 65 | #define WSTRSTR(s1,s2) strstr((s1),(s2)) |
sPymbed | 0:c4152c628df5 | 66 | #define WSTRNSTR(s1,s2,n) wstrnstr((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 67 | #define WSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 68 | #define WSTRNCAT(s1,s2,n) strncat((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 69 | #define WSTRSPN(s1,s2) strspn((s1),(s2)) |
sPymbed | 0:c4152c628df5 | 70 | #define WSTRCSPN(s1,s2) strcspn((s1),(s2)) |
sPymbed | 0:c4152c628df5 | 71 | #define WFOPEN(f,fn,m) wfopen((f),(fn),(m)) |
sPymbed | 0:c4152c628df5 | 72 | #define WFCLOSE(f) fclose(f) |
sPymbed | 0:c4152c628df5 | 73 | |
sPymbed | 0:c4152c628df5 | 74 | #ifndef USE_WINDOWS_API |
sPymbed | 0:c4152c628df5 | 75 | #include <stdio.h> |
sPymbed | 0:c4152c628df5 | 76 | #define WSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 77 | #define WSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 78 | #define WSNPRINTF(s,n,f,...) snprintf((s),(n),(f),##__VA_ARGS__) |
sPymbed | 0:c4152c628df5 | 79 | #define WVSNPRINTF(s,n,f,...) vsnprintf((s),(n),(f),##__VA_ARGS__) |
sPymbed | 0:c4152c628df5 | 80 | #define WLOCALTIME(c,r) (localtime_r((c),(r))!=NULL) |
sPymbed | 0:c4152c628df5 | 81 | #else |
sPymbed | 0:c4152c628df5 | 82 | #define WSTRNCPY(s1,s2,n) strncpy_s((s1),(n),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 83 | #define WSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n)) |
sPymbed | 0:c4152c628df5 | 84 | #define WSNPRINTF(s,n,f,...) _snprintf_s((s),(n),(n),(f),##__VA_ARGS__) |
sPymbed | 0:c4152c628df5 | 85 | #define WVSNPRINTF(s,n,f,...) vsnprintf_s((s),(n),(n),(f),##__VA_ARGS__) |
sPymbed | 0:c4152c628df5 | 86 | #define WLOCALTIME(c,r) (localtime_s((r),(c))==0) |
sPymbed | 0:c4152c628df5 | 87 | #endif |
sPymbed | 0:c4152c628df5 | 88 | #endif /* WSTRING_USER */ |
sPymbed | 0:c4152c628df5 | 89 | |
sPymbed | 0:c4152c628df5 | 90 | |
sPymbed | 0:c4152c628df5 | 91 | /* setup compiler inlining */ |
sPymbed | 0:c4152c628df5 | 92 | #ifndef INLINE |
sPymbed | 0:c4152c628df5 | 93 | #ifndef NO_INLINE |
sPymbed | 0:c4152c628df5 | 94 | #ifdef _MSC_VER |
sPymbed | 0:c4152c628df5 | 95 | #define INLINE __inline |
sPymbed | 0:c4152c628df5 | 96 | #elif defined(__GNUC__) |
sPymbed | 0:c4152c628df5 | 97 | #define INLINE inline |
sPymbed | 0:c4152c628df5 | 98 | #elif defined(__IAR_SYSTEMS_ICC__) |
sPymbed | 0:c4152c628df5 | 99 | #define INLINE inline |
sPymbed | 0:c4152c628df5 | 100 | #elif defined(THREADX) |
sPymbed | 0:c4152c628df5 | 101 | #define INLINE _Inline |
sPymbed | 0:c4152c628df5 | 102 | #else |
sPymbed | 0:c4152c628df5 | 103 | #define INLINE |
sPymbed | 0:c4152c628df5 | 104 | #endif |
sPymbed | 0:c4152c628df5 | 105 | #else |
sPymbed | 0:c4152c628df5 | 106 | #define INLINE |
sPymbed | 0:c4152c628df5 | 107 | #endif |
sPymbed | 0:c4152c628df5 | 108 | #endif /* INLINE */ |
sPymbed | 0:c4152c628df5 | 109 | |
sPymbed | 0:c4152c628df5 | 110 | |
sPymbed | 0:c4152c628df5 | 111 | /* GCC 7 has new switch() fall-through detection */ |
sPymbed | 0:c4152c628df5 | 112 | #if defined(__GNUC__) |
sPymbed | 0:c4152c628df5 | 113 | #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1))) |
sPymbed | 0:c4152c628df5 | 114 | #define FALL_THROUGH __attribute__ ((fallthrough)); |
sPymbed | 0:c4152c628df5 | 115 | #endif |
sPymbed | 0:c4152c628df5 | 116 | #endif |
sPymbed | 0:c4152c628df5 | 117 | #ifndef FALL_THROUGH |
sPymbed | 0:c4152c628df5 | 118 | #define FALL_THROUGH |
sPymbed | 0:c4152c628df5 | 119 | #endif |
sPymbed | 0:c4152c628df5 | 120 | |
sPymbed | 0:c4152c628df5 | 121 | |
sPymbed | 0:c4152c628df5 | 122 | #ifdef __cplusplus |
sPymbed | 0:c4152c628df5 | 123 | } |
sPymbed | 0:c4152c628df5 | 124 | #endif |
sPymbed | 0:c4152c628df5 | 125 |