1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Extracts a Node from a Chain |
---|
5 | * |
---|
6 | * @ingroup Score |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2008. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifdef HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/score/threadimpl.h> |
---|
23 | |
---|
24 | #include <ctype.h> |
---|
25 | |
---|
26 | size_t _Objects_Name_to_string( |
---|
27 | Objects_Name name, |
---|
28 | bool is_string, |
---|
29 | char *buffer, |
---|
30 | size_t buffer_size |
---|
31 | ) |
---|
32 | { |
---|
33 | char lname[ 5 ]; |
---|
34 | const char *s; |
---|
35 | char *d; |
---|
36 | size_t i; |
---|
37 | |
---|
38 | #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) |
---|
39 | if ( is_string ) { |
---|
40 | s = name.name_p; |
---|
41 | } else |
---|
42 | #endif |
---|
43 | { |
---|
44 | lname[ 0 ] = (name.name_u32 >> 24) & 0xff; |
---|
45 | lname[ 1 ] = (name.name_u32 >> 16) & 0xff; |
---|
46 | lname[ 2 ] = (name.name_u32 >> 8) & 0xff; |
---|
47 | lname[ 3 ] = (name.name_u32 >> 0) & 0xff; |
---|
48 | lname[ 4 ] = '\0'; |
---|
49 | s = lname; |
---|
50 | } |
---|
51 | |
---|
52 | d = buffer; |
---|
53 | i = 1; |
---|
54 | |
---|
55 | if ( s != NULL ) { |
---|
56 | while ( *s != '\0' ) { |
---|
57 | if ( i < buffer_size ) { |
---|
58 | *d = isprint((unsigned char) *s) ? *s : '*'; |
---|
59 | ++d; |
---|
60 | } |
---|
61 | |
---|
62 | ++s; |
---|
63 | ++i; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | if ( buffer_size > 0 ) { |
---|
68 | *d = '\0'; |
---|
69 | } |
---|
70 | |
---|
71 | return i - 1; |
---|
72 | } |
---|
73 | |
---|
74 | /* |
---|
75 | * This method objects the name of an object and returns its name |
---|
76 | * in the form of a C string. It attempts to be careful about |
---|
77 | * overflowing the user's string and about returning unprintable characters. |
---|
78 | */ |
---|
79 | |
---|
80 | char *_Objects_Get_name_as_string( |
---|
81 | Objects_Id id, |
---|
82 | size_t length, |
---|
83 | char *name |
---|
84 | ) |
---|
85 | { |
---|
86 | Objects_Information *information; |
---|
87 | Objects_Control *the_object; |
---|
88 | ISR_lock_Context lock_context; |
---|
89 | Objects_Id tmpId; |
---|
90 | |
---|
91 | if ( length == 0 ) |
---|
92 | return NULL; |
---|
93 | |
---|
94 | if ( name == NULL ) |
---|
95 | return NULL; |
---|
96 | |
---|
97 | tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Get_executing()->Object.id : id; |
---|
98 | |
---|
99 | information = _Objects_Get_information_id( tmpId ); |
---|
100 | if ( !information ) |
---|
101 | return NULL; |
---|
102 | |
---|
103 | the_object = _Objects_Get( tmpId, &lock_context, information ); |
---|
104 | if ( the_object == NULL ) { |
---|
105 | return NULL; |
---|
106 | } |
---|
107 | |
---|
108 | _Objects_Name_to_string( |
---|
109 | the_object->name, |
---|
110 | #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) |
---|
111 | information->is_string, |
---|
112 | #else |
---|
113 | false, |
---|
114 | #endif |
---|
115 | name, |
---|
116 | length |
---|
117 | ); |
---|
118 | |
---|
119 | _ISR_lock_ISR_enable( &lock_context ); |
---|
120 | return name; |
---|
121 | } |
---|