summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/objectnametoidstring.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-18 07:25:23 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-18 15:36:58 +0100
commitc904df573396d95957dc79b242b3a76911063089 (patch)
treebe6406676689018e8af8a929b6a4ef5284f94c70 /cpukit/score/src/objectnametoidstring.c
parentsptests/sptls02: Use GNU++11 (diff)
downloadrtems-c904df573396d95957dc79b242b3a76911063089.tar.bz2
score: Add _Objects_Get_by_name()
Replace _Objects_Name_to_id_string() with _Objects_Get_by_name() since all users of this function are interested in the object itself and not the identifier. Use the object allocator lock to protect the search. Update #2555.
Diffstat (limited to 'cpukit/score/src/objectnametoidstring.c')
-rw-r--r--cpukit/score/src/objectnametoidstring.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/cpukit/score/src/objectnametoidstring.c b/cpukit/score/src/objectnametoidstring.c
index 00c84f04d3..bd4b4a9ead 100644
--- a/cpukit/score/src/objectnametoidstring.c
+++ b/cpukit/score/src/objectnametoidstring.c
@@ -23,40 +23,53 @@
#include <string.h>
#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-Objects_Name_or_id_lookup_errors _Objects_Name_to_id_string(
- Objects_Information *information,
- const char *name,
- Objects_Id *id
+Objects_Control *_Objects_Get_by_name(
+ const Objects_Information *information,
+ const char *name,
+ size_t *name_length_p,
+ Objects_Get_by_name_error *error
)
{
- Objects_Control *the_object;
- uint32_t index;
+ size_t name_length;
+ size_t max_name_length;
+ uint32_t index;
- /* ASSERT: information->is_string == true */
+ _Assert( information->is_string );
+ _Assert( _Objects_Allocator_is_owner() );
- if ( !id )
- return OBJECTS_INVALID_ADDRESS;
+ if ( name == NULL ) {
+ *error = OBJECTS_GET_BY_NAME_INVALID_NAME;
+ return NULL;
+ }
+
+ name_length = strnlen( name, information->name_length + 1 );
+ max_name_length = information->name_length;
+ if ( name_length > max_name_length ) {
+ *error = OBJECTS_GET_BY_NAME_NAME_TOO_LONG;
+ return NULL;
+ }
+
+ if ( name_length_p != NULL ) {
+ *name_length_p = name_length;
+ }
- if ( !name )
- return OBJECTS_INVALID_NAME;
+ for ( index = 1; index <= information->maximum; index++ ) {
+ Objects_Control *the_object;
- if ( information->maximum != 0 ) {
+ the_object = information->local_table[ index ];
- for ( index = 1; index <= information->maximum; index++ ) {
- the_object = information->local_table[ index ];
- if ( !the_object )
- continue;
+ if ( the_object == NULL )
+ continue;
- if ( !the_object->name.name_p )
- continue;
+ if ( the_object->name.name_p == NULL )
+ continue;
- if (!strncmp( name, the_object->name.name_p, information->name_length)) {
- *id = the_object->id;
- return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;
- }
+ if ( strncmp( name, the_object->name.name_p, max_name_length ) == 0 ) {
+ return the_object;
}
}
- return OBJECTS_INVALID_NAME;
+ *error = OBJECTS_GET_BY_NAME_NO_OBJECT;
+ return NULL;
}
#endif