mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Cc: Andrea GALLO <andrea.gallo@stericsson.com>
Subject: [PATCH 1/6] string: add strlcpy support
Date: Wed,  4 Aug 2010 03:43:54 +0200	[thread overview]
Message-ID: <1280886239-19133-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20100804014227.GA16337@game.jcrosoft.org>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Andrea GALLO <andrea.gallo@stericsson.com>
Cc: Gael SALLES <gael.salles@stericsson.com>
---
 include/linux/string.h |    3 +++
 include/stdio.h        |    1 +
 lib/string.c           |   26 ++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/include/linux/string.h b/include/linux/string.h
index 20b0829..62d743e 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -38,6 +38,9 @@ extern char * strcpy(char *,const char *);
 #ifndef __HAVE_ARCH_STRNCPY
 extern char * strncpy(char *,const char *, __kernel_size_t);
 #endif
+#ifndef __HAVE_ARCH_STRLCPY
+size_t strlcpy(char *, const char *, size_t);
+#endif
 #ifndef __HAVE_ARCH_STRCAT
 extern char * strcat(char *, const char *);
 #endif
diff --git a/include/stdio.h b/include/stdio.h
index d591b6a..8bc45fa 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -36,6 +36,7 @@ int	vsprintf(char *buf, const char *fmt, va_list args);
 char	*asprintf(const char *fmt, ...);
 char	*vasprintf(const char *fmt, va_list ap);
 int	vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+int	vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 
 /* stderr */
 #define eputc(c)		console_putc(CONSOLE_STDERR, c)
diff --git a/lib/string.c b/lib/string.c
index cbb13d3..77435aa 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -62,6 +62,32 @@ char * strncpy(char * dest,const char *src,size_t count)
 #endif
 EXPORT_SYMBOL(strncpy);
 
+#ifndef __HAVE_ARCH_STRLCPY
+/**
+ * strlcpy - Copy a %NUL terminated string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @size: size of destination buffer
+ *
+ * Compatible with *BSD: the result is always a valid
+ * NUL-terminated string that fits in the buffer (unless,
+ * of course, the buffer size is zero). It does not pad
+ * out the result like strncpy() does.
+ */
+size_t strlcpy(char *dest, const char *src, size_t size)
+{
+	size_t ret = strlen(src);
+
+	if (size) {
+		size_t len = (ret >= size) ? size - 1 : ret;
+		memcpy(dest, src, len);
+		dest[len] = '\0';
+	}
+	return ret;
+}
+EXPORT_SYMBOL(strlcpy);
+#endif
+
 #ifndef __HAVE_ARCH_STRCAT
 /**
  * strcat - Append one %NUL-terminated string to another
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2010-08-04  1:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-04  1:42 [PATCH 0/6] common arm clkdev Jean-Christophe PLAGNIOL-VILLARD
2010-08-04  1:43 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2010-08-04  1:43   ` [PATCH 2/6] arm: add common clkdev Jean-Christophe PLAGNIOL-VILLARD
2010-08-04  1:43     ` [PATCH 3/6] amba: add pl011 Jean-Christophe PLAGNIOL-VILLARD
2010-08-04  1:43       ` [PATCH 4/6] arm: add Nomadik 8815 SoC support Jean-Christophe PLAGNIOL-VILLARD
2010-08-04  1:43         ` [PATCH 5/6] nand: driver for Nomadik 8815 SoC Jean-Christophe PLAGNIOL-VILLARD
2010-08-04  1:43           ` [PATCH 6/6] arm: add nhk8815 board support Jean-Christophe PLAGNIOL-VILLARD
2010-08-04  6:46       ` [PATCH 3/6] amba: add pl011 Sascha Hauer
2010-08-04 13:51         ` Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1280886239-19133-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=andrea.gallo@stericsson.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox