summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2011-12-12 15:17:33 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2011-12-12 15:17:33 +0000
commit141b31107a64a23ef2e369cc7cc2ed91c1e78cc3 (patch)
tree78337f049e79a9886d7257668864b8aeeb7d9351
parentebd6c936de9004b8eb0d4d954dccd757821a2b29 (diff)
2011-12-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
* score/src/wkstringduplicate.c: New file. * score/Makefile.am: Reflect change above. * score/include/rtems/score/wkspace.h: Declare _Workspace_String_duplicate().
-rw-r--r--cpukit/ChangeLog7
-rw-r--r--cpukit/score/Makefile.am2
-rw-r--r--cpukit/score/include/rtems/score/wkspace.h17
-rw-r--r--cpukit/score/src/wkstringduplicate.c39
4 files changed, 64 insertions, 1 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 9f9b120cb2..63c179edb6 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,10 @@
+2011-12-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/wkstringduplicate.c: New file.
+ * score/Makefile.am: Reflect change above.
+ * score/include/rtems/score/wkspace.h: Declare
+ _Workspace_String_duplicate().
+
2011-12-10 Ralf Corsépius <ralf.corsepius@rtems.org>
* posix/src/fork.c: Include <unistd.h> for "fork" prototype.
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index d5e938570e..13c31826b9 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -329,7 +329,7 @@ libscore_a_SOURCES += src/userextaddset.c \
libscore_a_SOURCES += src/apiext.c src/chain.c src/chainappend.c \
src/chainextract.c src/chainget.c src/chaininsert.c \
src/chainappendempty.c src/chainprependempty.c src/chaingetempty.c \
- src/interr.c src/isr.c src/wkspace.c
+ src/interr.c src/isr.c src/wkspace.c src/wkstringduplicate.c
EXTRA_DIST = src/Unlimited.txt
diff --git a/cpukit/score/include/rtems/score/wkspace.h b/cpukit/score/include/rtems/score/wkspace.h
index 89b7c6dfc5..0fc96df6c2 100644
--- a/cpukit/score/include/rtems/score/wkspace.h
+++ b/cpukit/score/include/rtems/score/wkspace.h
@@ -99,6 +99,23 @@ void *_Workspace_Allocate_or_fatal_error(
size_t size
);
+/**
+ * @brief Duplicates the @a string with memory from the Workspace.
+ *
+ * If the @a string length exceeds @a maxlen, then the additional characters
+ * will be discarded.
+ *
+ * @param[in] string Pointer to zero terminated string.
+ * @param[in] maxlen Maximum length of the duplicated string.
+ *
+ * @return NULL Not enough memory.
+ * @return other Duplicated string.
+ */
+char *_Workspace_String_duplicate(
+ const char *string,
+ size_t maxlen
+);
+
#ifndef __RTEMS_APPLICATION__
#include <rtems/score/wkspace.inl>
#endif
diff --git a/cpukit/score/src/wkstringduplicate.c b/cpukit/score/src/wkstringduplicate.c
new file mode 100644
index 0000000000..55c347a7ca
--- /dev/null
+++ b/cpukit/score/src/wkstringduplicate.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/score/wkspace.h>
+
+#include <string.h>
+
+char *_Workspace_String_duplicate(
+ const char *string,
+ size_t maxlen
+)
+{
+ size_t n = strnlen(string, maxlen);
+ char *dup = _Workspace_Allocate(n + 1);
+
+ if (dup != NULL) {
+ dup [n] = '\0';
+ memcpy(dup, string, n);
+ }
+
+ return dup;
+}