1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2008. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/score/object.h> |
---|
18 | #include <rtems/score/thread.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <ctype.h> |
---|
21 | #include <inttypes.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * This method objects the name of an object and returns its name |
---|
25 | * in the form of a C string. It attempts to be careful about |
---|
26 | * overflowing the user's string and about returning unprintable characters. |
---|
27 | */ |
---|
28 | |
---|
29 | char *_Objects_Get_name_as_string( |
---|
30 | Objects_Id id, |
---|
31 | size_t length, |
---|
32 | char *name |
---|
33 | ) |
---|
34 | { |
---|
35 | Objects_Information *information; |
---|
36 | const char *s; |
---|
37 | char *d; |
---|
38 | uint32_t i; |
---|
39 | char lname[5]; |
---|
40 | Objects_Control *the_object; |
---|
41 | Objects_Locations location; |
---|
42 | Objects_Id tmpId; |
---|
43 | |
---|
44 | if ( length == 0 ) |
---|
45 | return NULL; |
---|
46 | |
---|
47 | if ( name == NULL ) |
---|
48 | return NULL; |
---|
49 | |
---|
50 | tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id; |
---|
51 | |
---|
52 | information = _Objects_Get_information_id( tmpId ); |
---|
53 | if ( !information ) |
---|
54 | return NULL; |
---|
55 | |
---|
56 | the_object = _Objects_Get( information, tmpId, &location ); |
---|
57 | switch ( location ) { |
---|
58 | |
---|
59 | #if defined(RTEMS_MULTIPROCESSING) |
---|
60 | case OBJECTS_REMOTE: |
---|
61 | /* not supported */ |
---|
62 | #endif |
---|
63 | case OBJECTS_ERROR: |
---|
64 | return NULL; |
---|
65 | |
---|
66 | case OBJECTS_LOCAL: |
---|
67 | |
---|
68 | if ( information->is_string ) { |
---|
69 | s = the_object->name.name_p; |
---|
70 | } else { |
---|
71 | uint32_t u32_name = (uint32_t) the_object->name.name_u32; |
---|
72 | |
---|
73 | lname[ 0 ] = (u32_name >> 24) & 0xff; |
---|
74 | lname[ 1 ] = (u32_name >> 16) & 0xff; |
---|
75 | lname[ 2 ] = (u32_name >> 8) & 0xff; |
---|
76 | lname[ 3 ] = (u32_name >> 0) & 0xff; |
---|
77 | lname[ 4 ] = '\0'; |
---|
78 | s = lname; |
---|
79 | } |
---|
80 | |
---|
81 | d = name; |
---|
82 | if ( s ) { |
---|
83 | for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) { |
---|
84 | *d = (isprint(*s)) ? *s : '*'; |
---|
85 | } |
---|
86 | } |
---|
87 | *d = '\0'; |
---|
88 | |
---|
89 | _Thread_Enable_dispatch(); |
---|
90 | return name; |
---|
91 | } |
---|
92 | return NULL; /* unreachable path */ |
---|
93 | } |
---|