@@ -214,6 +214,22 @@ char *substring(const char *src, int first, int len) {
return s;
}
+#if defined(__linux__)
+size_t
+strlcpy(char *dst, const char * src, size_t size)
+{
+
+ size_t len = strlen(src);
+ if (len < size) {
+ memcpy(dst, src, len + 1);
+ } else if (len) {
+ memcpy(dst, src, len - 1);
+ /* Add C string terminator */
+ dst[len - 1] = '\0';
+ }
+ return len;
+}
+#endif
int openfileoutput(const char *filename)
{
@@ -169,6 +169,11 @@ int copy_write(void *out, const void *buf, unsigned int len);
#if defined(__FreeBSD__)
int copy_write_padded(void *out, const void *buf, unsigned int len);
#endif
+#if defined(__linux__)
+/* strlcpy was originally developped in FreeBSD, not present in glibc */
+size_t
+strlcpy(char *dst, const char * src, size_t size);
+#endif
int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs,
unsigned long long seek,
int skip_file, int compressed, uint32_t *checksum,
strncpy() is often considered not safe becuase it can leave the a null terminated string in the destination. Add strlcpy() from FreeBSD (function will be built for linux only). Signed-off-by: Stefano Babic <sbabic@denx.de> --- core/util.c | 16 ++++++++++++++++ include/util.h | 5 +++++ 2 files changed, 21 insertions(+)