1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Set Objects Name |
---|
5 | * @ingroup ScoreObject |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
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 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/objectimpl.h> |
---|
22 | #include <rtems/score/wkspace.h> |
---|
23 | |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | bool _Objects_Set_name( |
---|
27 | Objects_Information *information, |
---|
28 | Objects_Control *the_object, |
---|
29 | const char *name |
---|
30 | ) |
---|
31 | { |
---|
32 | size_t length; |
---|
33 | const char *s; |
---|
34 | |
---|
35 | s = name; |
---|
36 | length = strnlen( name, information->name_length ); |
---|
37 | |
---|
38 | #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) |
---|
39 | if ( information->is_string ) { |
---|
40 | char *d; |
---|
41 | |
---|
42 | d = _Workspace_Allocate( length + 1 ); |
---|
43 | if ( !d ) |
---|
44 | return false; |
---|
45 | |
---|
46 | _Workspace_Free( (void *)the_object->name.name_p ); |
---|
47 | the_object->name.name_p = NULL; |
---|
48 | |
---|
49 | strncpy( d, name, length ); |
---|
50 | d[length] = '\0'; |
---|
51 | the_object->name.name_p = d; |
---|
52 | } else |
---|
53 | #endif |
---|
54 | { |
---|
55 | the_object->name.name_u32 = _Objects_Build_name( |
---|
56 | ((length) ? s[ 0 ] : ' '), |
---|
57 | ((length > 1) ? s[ 1 ] : ' '), |
---|
58 | ((length > 2) ? s[ 2 ] : ' '), |
---|
59 | ((length > 3) ? s[ 3 ] : ' ') |
---|
60 | ); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | return true; |
---|
65 | } |
---|