|
| 1 | +/* |
| 2 | + libc_replacements.c - replaces libc functions with functions |
| 3 | + from Espressif SDK |
| 4 | +
|
| 5 | + Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. |
| 6 | + This file is part of the esp8266 core for Arduino environment. |
| 7 | + |
| 8 | + This library is free software; you can redistribute it and/or |
| 9 | + modify it under the terms of the GNU Lesser General Public |
| 10 | + License as published by the Free Software Foundation; either |
| 11 | + version 2.1 of the License, or (at your option) any later version. |
| 12 | +
|
| 13 | + This library is distributed in the hope that it will be useful, |
| 14 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + Lesser General Public License for more details. |
| 17 | +
|
| 18 | + You should have received a copy of the GNU Lesser General Public |
| 19 | + License along with this library; if not, write to the Free Software |
| 20 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | +*/ |
| 22 | + |
| 23 | +#include <stddef.h> |
| 24 | +#include <stdarg.h> |
| 25 | + |
| 26 | +#include "ets_sys.h" |
| 27 | +#include "os_type.h" |
| 28 | +#include "osapi.h" |
| 29 | +#include "mem.h" |
| 30 | +#include "user_interface.h" |
| 31 | + |
| 32 | + |
| 33 | +void* malloc(size_t size) { |
| 34 | + return os_malloc(size); |
| 35 | +} |
| 36 | + |
| 37 | +void free(void* ptr) { |
| 38 | + os_free(ptr); |
| 39 | +} |
| 40 | + |
| 41 | +void* realloc(void* ptr, size_t size) { |
| 42 | + return os_realloc(ptr, size); |
| 43 | +} |
| 44 | + |
| 45 | +int printf(const char* format, ...) { |
| 46 | + va_list arglist; |
| 47 | + va_start(arglist, format); |
| 48 | + ets_vprintf(format, arglist); |
| 49 | + va_end(arglist); |
| 50 | +} |
| 51 | + |
| 52 | +int sprintf(char* buffer, const char* format, ...) { |
| 53 | + va_list arglist; |
| 54 | + va_start(arglist, format); |
| 55 | + ets_vsprintf(buffer, format, arglist); |
| 56 | + va_end(arglist); |
| 57 | +} |
| 58 | + |
| 59 | +int snprintf(char* buffer, size_t size, const char* format, ...) { |
| 60 | + va_list arglist; |
| 61 | + va_start(arglist, format); |
| 62 | + ets_vsnprintf(buffer, size, format, arglist); |
| 63 | + va_end(arglist); |
| 64 | +} |
| 65 | + |
| 66 | +int memcmp(const void *s1, const void *s2, size_t n) { |
| 67 | + return ets_memcmp(s1, s2, n); |
| 68 | +} |
| 69 | + |
| 70 | +void* memcpy(void *dest, const void *src, size_t n) { |
| 71 | + return ets_memcpy(dest, src, n); |
| 72 | +} |
| 73 | + |
| 74 | +void* memset(void *s, int c, size_t n) { |
| 75 | + return ets_memset(s, c, n); |
| 76 | +} |
| 77 | + |
| 78 | +int strcmp(const char *s1, const char *s2) { |
| 79 | + return ets_strcmp(s1, s2); |
| 80 | +} |
| 81 | + |
| 82 | +char* strcpy(char *dest, const char *src) { |
| 83 | + return ets_strcpy(dest, src); |
| 84 | +} |
| 85 | + |
| 86 | +size_t strlen(const char *s) { |
| 87 | + return ets_strlen(s); |
| 88 | +} |
| 89 | + |
| 90 | +int strncmp(const char *s1, const char *s2, size_t len) { |
| 91 | + return ets_strncmp(s1, s2, len); |
| 92 | +} |
| 93 | + |
| 94 | +char *strncpy(char *dest, const char *src, size_t n) { |
| 95 | + return ets_strncpy(dest, src, n); |
| 96 | +} |
| 97 | + |
| 98 | +char *ets_strstr(const char *haystack, const char *needle) { |
| 99 | + return strstr(haystack, needle); |
| 100 | +} |
| 101 | + |
0 commit comments