ssh
src/port.c@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.c |
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 | #ifdef HAVE_CONFIG_H |
sPymbed | 0:c4152c628df5 | 31 | #include <config.h> |
sPymbed | 0:c4152c628df5 | 32 | #endif |
sPymbed | 0:c4152c628df5 | 33 | |
sPymbed | 0:c4152c628df5 | 34 | #include <stdio.h> |
sPymbed | 0:c4152c628df5 | 35 | #include <wolfssh/port.h> |
sPymbed | 0:c4152c628df5 | 36 | |
sPymbed | 0:c4152c628df5 | 37 | |
sPymbed | 0:c4152c628df5 | 38 | int wfopen(WFILE** f, const char* filename, const char* mode) |
sPymbed | 0:c4152c628df5 | 39 | { |
sPymbed | 0:c4152c628df5 | 40 | #ifdef USE_WINDOWS_API |
sPymbed | 0:c4152c628df5 | 41 | return fopen_s(f, filename, mode) != 0; |
sPymbed | 0:c4152c628df5 | 42 | #else |
sPymbed | 0:c4152c628df5 | 43 | if (f != NULL) { |
sPymbed | 0:c4152c628df5 | 44 | *f = fopen(filename, mode); |
sPymbed | 0:c4152c628df5 | 45 | return *f == NULL; |
sPymbed | 0:c4152c628df5 | 46 | } |
sPymbed | 0:c4152c628df5 | 47 | return 1; |
sPymbed | 0:c4152c628df5 | 48 | #endif |
sPymbed | 0:c4152c628df5 | 49 | } |
sPymbed | 0:c4152c628df5 | 50 | |
sPymbed | 0:c4152c628df5 | 51 | |
sPymbed | 0:c4152c628df5 | 52 | #ifndef WSTRING_USER |
sPymbed | 0:c4152c628df5 | 53 | |
sPymbed | 0:c4152c628df5 | 54 | char* wstrnstr(const char* s1, const char* s2, unsigned int n) |
sPymbed | 0:c4152c628df5 | 55 | { |
sPymbed | 0:c4152c628df5 | 56 | unsigned int s2_len = (unsigned int)WSTRLEN(s2); |
sPymbed | 0:c4152c628df5 | 57 | |
sPymbed | 0:c4152c628df5 | 58 | if (s2_len == 0) |
sPymbed | 0:c4152c628df5 | 59 | return (char*)s1; |
sPymbed | 0:c4152c628df5 | 60 | |
sPymbed | 0:c4152c628df5 | 61 | while (n >= s2_len && s1[0]) { |
sPymbed | 0:c4152c628df5 | 62 | if (s1[0] == s2[0]) |
sPymbed | 0:c4152c628df5 | 63 | if (WMEMCMP(s1, s2, s2_len) == 0) |
sPymbed | 0:c4152c628df5 | 64 | return (char*)s1; |
sPymbed | 0:c4152c628df5 | 65 | s1++; |
sPymbed | 0:c4152c628df5 | 66 | n--; |
sPymbed | 0:c4152c628df5 | 67 | } |
sPymbed | 0:c4152c628df5 | 68 | |
sPymbed | 0:c4152c628df5 | 69 | return NULL; |
sPymbed | 0:c4152c628df5 | 70 | } |
sPymbed | 0:c4152c628df5 | 71 | |
sPymbed | 0:c4152c628df5 | 72 | #endif /* WSTRING_USER */ |