1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Object ID to Name |
---|
5 | * @ingroup ScoreObject |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2010. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/objectimpl.h> |
---|
22 | |
---|
23 | #include <string.h> |
---|
24 | |
---|
25 | #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) |
---|
26 | Objects_Control *_Objects_Get_by_name( |
---|
27 | const Objects_Information *information, |
---|
28 | const char *name, |
---|
29 | size_t *name_length_p, |
---|
30 | Objects_Get_by_name_error *error |
---|
31 | ) |
---|
32 | { |
---|
33 | size_t name_length; |
---|
34 | size_t max_name_length; |
---|
35 | uint32_t index; |
---|
36 | |
---|
37 | _Assert( information->is_string ); |
---|
38 | _Assert( _Objects_Allocator_is_owner() ); |
---|
39 | |
---|
40 | if ( name == NULL ) { |
---|
41 | *error = OBJECTS_GET_BY_NAME_INVALID_NAME; |
---|
42 | return NULL; |
---|
43 | } |
---|
44 | |
---|
45 | name_length = strnlen( name, information->name_length + 1 ); |
---|
46 | max_name_length = information->name_length; |
---|
47 | if ( name_length > max_name_length ) { |
---|
48 | *error = OBJECTS_GET_BY_NAME_NAME_TOO_LONG; |
---|
49 | return NULL; |
---|
50 | } |
---|
51 | |
---|
52 | if ( name_length_p != NULL ) { |
---|
53 | *name_length_p = name_length; |
---|
54 | } |
---|
55 | |
---|
56 | for ( index = 1; index <= information->maximum; index++ ) { |
---|
57 | Objects_Control *the_object; |
---|
58 | |
---|
59 | the_object = information->local_table[ index ]; |
---|
60 | |
---|
61 | if ( the_object == NULL ) |
---|
62 | continue; |
---|
63 | |
---|
64 | if ( the_object->name.name_p == NULL ) |
---|
65 | continue; |
---|
66 | |
---|
67 | if ( strncmp( name, the_object->name.name_p, max_name_length ) == 0 ) { |
---|
68 | return the_object; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | *error = OBJECTS_GET_BY_NAME_NO_OBJECT; |
---|
73 | return NULL; |
---|
74 | } |
---|
75 | #endif |
---|