From e991d81eee81208b61d860b9f9c39f53a2d361a8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Oct 2011 21:04:07 +1100 Subject: [PATCH] desktop: removed the need for libbsd this should help the cygwin build that MikeO is working on --- libraries/Desktop/Desktop.mk | 2 +- libraries/Desktop/support/Arduino.cpp | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/Desktop/Desktop.mk b/libraries/Desktop/Desktop.mk index 137e16157d..1fd49f6d05 100644 --- a/libraries/Desktop/Desktop.mk +++ b/libraries/Desktop/Desktop.mk @@ -116,7 +116,7 @@ CFLAGS = -g $(DEFINES) $(OPTFLAGS) $(DEPFLAGS) $(COPTS) ASFLAGS = -g $(DEFINES) $(DEPFLAGS) $(ASOPTS) LDFLAGS = -g $(OPTFLAGS) -Wl,--gc-sections -Wl,-Map -Wl,$(SKETCHMAP) -LIBS = -lm -lbsd +LIBS = -lm SRCSUFFIXES = *.cpp *.c diff --git a/libraries/Desktop/support/Arduino.cpp b/libraries/Desktop/support/Arduino.cpp index 7a6c7dc4bd..676f3e84f7 100644 --- a/libraries/Desktop/support/Arduino.cpp +++ b/libraries/Desktop/support/Arduino.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "avr/pgmspace.h" #include #include @@ -43,9 +42,23 @@ void delay(long unsigned msec) usleep(msec*1000); } -size_t strlcat_P(char *dst, PGM_P src, size_t size) +size_t strlcat_P(char *d, PGM_P s, size_t bufsize) { - return strlcat(dst, src, size); + size_t len1 = strlen(d); + size_t len2 = strlen(s); + size_t ret = len1 + len2; + + if (len1+len2 >= bufsize) { + if (bufsize < (len1+1)) { + return ret; + } + len2 = bufsize - (len1+1); + } + if (len2 > 0) { + memcpy(d+len1, s, len2); + d[len1+len2] = 0; + } + return ret; } size_t strnlen_P(PGM_P str, size_t size)