1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Add strlcpy implementation (#465)

This commit is contained in:
Ivan Grokhotkov 2015-07-07 14:39:39 +03:00
parent de70454a2a
commit 49dc457fe5

View File

@ -94,10 +94,6 @@ size_t ICACHE_FLASH_ATTR strnlen(const char *s, size_t len) {
return (size_t)(cp - s); return (size_t)(cp - s);
} }
char* strstr(const char *haystack, const char *needle) {
return ets_strstr(haystack, needle);
}
char* ICACHE_FLASH_ATTR strchr(const char * str, int character) { char* ICACHE_FLASH_ATTR strchr(const char * str, int character) {
while(1) { while(1) {
if(*str == 0x00) { if(*str == 0x00) {
@ -443,3 +439,56 @@ int* ICACHE_FLASH_ATTR __errno(void) {
return &errno_var; return &errno_var;
} }
/*
* begin newlib/string/strlcpy.c
*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
size_t ICACHE_FLASH_ATTR strlcpy(char* dst, const char* src, size_t size) {
const char *s = src;
size_t n = size;
if (n != 0 && --n != 0) {
do {
if ((*dst++ = *s++) == 0)
break;
} while (--n != 0);
}
if (n == 0) {
if (size != 0)
*dst = 0;
while (*s++);
}
return(s - src - 1);
}
/*
* end of newlib/string/strlcpy.c
*/