summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-01-12 08:28:57 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-01-13 07:19:21 +0100
commitb8bcebea186e2d02334a014d5e792a0dde8007fc (patch)
tree57c5d9e00fdb03008c96f812c2a76386a569a6eb
parentconfigure: Add RTEMS_TOOL_CHAIN_ERROR (diff)
downloadrtems-b8bcebea186e2d02334a014d5e792a0dde8007fc.tar.bz2
score: Add and use _Objects_Name_to_string()
Update #2858.
-rw-r--r--cpukit/score/include/rtems/score/objectimpl.h21
-rw-r--r--cpukit/score/src/objectgetnameasstring.c85
2 files changed, 79 insertions, 27 deletions
diff --git a/cpukit/score/include/rtems/score/objectimpl.h b/cpukit/score/include/rtems/score/objectimpl.h
index a00aa2276e..1ec688a793 100644
--- a/cpukit/score/include/rtems/score/objectimpl.h
+++ b/cpukit/score/include/rtems/score/objectimpl.h
@@ -655,6 +655,27 @@ char *_Objects_Get_name_as_string(
);
/**
+ * @brief Converts the specified object name to a text representation.
+ *
+ * Non-printable characters according to isprint() are converted to '*'.
+ *
+ * @param[in] name The object name.
+ * @param[in] is_string Indicates if the object name is a string or a four
+ * character array (32-bit unsigned integer).
+ * @param[in] buffer The string buffer for the text representation.
+ * @param[in] buffer_size The buffer size in characters.
+ *
+ * @retval The length of the text representation. May be greater than or equal
+ * to the buffer size if truncation occurred.
+ */
+size_t _Objects_Name_to_string(
+ Objects_Name name,
+ bool is_string,
+ char *buffer,
+ size_t buffer_size
+);
+
+/**
* @brief Set objects name.
*
* This method sets the object name to either a copy of a string
diff --git a/cpukit/score/src/objectgetnameasstring.c b/cpukit/score/src/objectgetnameasstring.c
index ca6e1f43ab..7a6177a124 100644
--- a/cpukit/score/src/objectgetnameasstring.c
+++ b/cpukit/score/src/objectgetnameasstring.c
@@ -23,6 +23,54 @@
#include <ctype.h>
+size_t _Objects_Name_to_string(
+ Objects_Name name,
+ bool is_string,
+ char *buffer,
+ size_t buffer_size
+)
+{
+ char lname[ 5 ];
+ const char *s;
+ char *d;
+ size_t i;
+
+#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ if ( is_string ) {
+ s = name.name_p;
+ } else
+#endif
+ {
+ lname[ 0 ] = (name.name_u32 >> 24) & 0xff;
+ lname[ 1 ] = (name.name_u32 >> 16) & 0xff;
+ lname[ 2 ] = (name.name_u32 >> 8) & 0xff;
+ lname[ 3 ] = (name.name_u32 >> 0) & 0xff;
+ lname[ 4 ] = '\0';
+ s = lname;
+ }
+
+ d = buffer;
+ i = 1;
+
+ if ( s != NULL ) {
+ while ( *s != '\0' ) {
+ if ( i < buffer_size ) {
+ *d = isprint((unsigned char) *s) ? *s : '*';
+ ++d;
+ }
+
+ ++s;
+ ++i;
+ }
+ }
+
+ if ( buffer_size > 0 ) {
+ *d = '\0';
+ }
+
+ return i - 1;
+}
+
/*
* This method objects the name of an object and returns its name
* in the form of a C string. It attempts to be careful about
@@ -36,10 +84,6 @@ char *_Objects_Get_name_as_string(
)
{
Objects_Information *information;
- const char *s;
- char *d;
- uint32_t i;
- char lname[5];
Objects_Control *the_object;
ISR_lock_Context lock_context;
Objects_Id tmpId;
@@ -61,29 +105,16 @@ char *_Objects_Get_name_as_string(
return NULL;
}
- #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
- if ( information->is_string ) {
- s = the_object->name.name_p;
- } else
- #endif
- {
- uint32_t u32_name = (uint32_t) the_object->name.name_u32;
-
- lname[ 0 ] = (u32_name >> 24) & 0xff;
- lname[ 1 ] = (u32_name >> 16) & 0xff;
- lname[ 2 ] = (u32_name >> 8) & 0xff;
- lname[ 3 ] = (u32_name >> 0) & 0xff;
- lname[ 4 ] = '\0';
- s = lname;
- }
-
- d = name;
- if ( s ) {
- for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
- *d = (isprint((unsigned char)*s)) ? *s : '*';
- }
- }
- *d = '\0';
+ _Objects_Name_to_string(
+ the_object->name,
+#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ information->is_string,
+#else
+ false,
+#endif
+ name,
+ length
+ );
_ISR_lock_ISR_enable( &lock_context );
return name;