Skip to content

Commit 121806d

Browse files
committed
Add strlcpy implementation (esp8266#465)
1 parent e53da68 commit 121806d

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ size_t ICACHE_FLASH_ATTR strnlen(const char *s, size_t len) {
9494
return (size_t)(cp - s);
9595
}
9696

97-
char* strstr(const char *haystack, const char *needle) {
98-
return ets_strstr(haystack, needle);
99-
}
100-
10197
char* ICACHE_FLASH_ATTR strchr(const char * str, int character) {
10298
while(1) {
10399
if(*str == 0x00) {
@@ -443,3 +439,56 @@ int* ICACHE_FLASH_ATTR __errno(void) {
443439
return &errno_var;
444440
}
445441

442+
443+
/*
444+
* begin newlib/string/strlcpy.c
445+
*
446+
* Copyright (c) 1998 Todd C. Miller <[email protected]>
447+
* All rights reserved.
448+
*
449+
* Redistribution and use in source and binary forms, with or without
450+
* modification, are permitted provided that the following conditions
451+
* are met:
452+
* 1. Redistributions of source code must retain the above copyright
453+
* notice, this list of conditions and the following disclaimer.
454+
* 2. Redistributions in binary form must reproduce the above copyright
455+
* notice, this list of conditions and the following disclaimer in the
456+
* documentation and/or other materials provided with the distribution.
457+
* 3. The name of the author may not be used to endorse or promote products
458+
* derived from this software without specific prior written permission.
459+
*
460+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
461+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
462+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
463+
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
464+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
465+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
466+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
467+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
468+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
469+
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
470+
*/
471+
472+
size_t ICACHE_FLASH_ATTR strlcpy(char* dst, const char* src, size_t size) {
473+
const char *s = src;
474+
size_t n = size;
475+
476+
if (n != 0 && --n != 0) {
477+
do {
478+
if ((*dst++ = *s++) == 0)
479+
break;
480+
} while (--n != 0);
481+
}
482+
483+
if (n == 0) {
484+
if (size != 0)
485+
*dst = 0;
486+
while (*s++);
487+
}
488+
489+
return(s - src - 1);
490+
}
491+
/*
492+
* end of newlib/string/strlcpy.c
493+
*/
494+

0 commit comments

Comments
 (0)