diff options
Diffstat (limited to 'cpukit/score/src/objectnametoidstring.c')
-rw-r--r-- | cpukit/score/src/objectnametoidstring.c | 59 |
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 |