1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <rtems/system.h> |
---|
15 | #include <rtems/score/object.h> |
---|
16 | #include <rtems/score/thread.h> |
---|
17 | #include <rtems/score/wkspace.h> |
---|
18 | #include <stdlib.h> |
---|
19 | #include <ctype.h> |
---|
20 | #include <inttypes.h> |
---|
21 | #include <string.h> |
---|
22 | |
---|
23 | |
---|
24 | /* |
---|
25 | * This method sets the name of an object based upon a C string. |
---|
26 | */ |
---|
27 | |
---|
28 | bool _Objects_Set_name( |
---|
29 | Objects_Information *information, |
---|
30 | Objects_Control *the_object, |
---|
31 | const char *name |
---|
32 | ) |
---|
33 | { |
---|
34 | size_t length; |
---|
35 | const char *s; |
---|
36 | |
---|
37 | s = name; |
---|
38 | length = strnlen( name, information->name_length ); |
---|
39 | |
---|
40 | #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) |
---|
41 | if ( information->is_string ) { |
---|
42 | char *d; |
---|
43 | |
---|
44 | d = _Workspace_Allocate( length + 1 ); |
---|
45 | if ( !d ) |
---|
46 | return false; |
---|
47 | |
---|
48 | _Workspace_Free( (void *)the_object->name.name_p ); |
---|
49 | the_object->name.name_p = NULL; |
---|
50 | |
---|
51 | strncpy( d, name, length ); |
---|
52 | d[length] = '\0'; |
---|
53 | the_object->name.name_p = d; |
---|
54 | } else |
---|
55 | #endif |
---|
56 | { |
---|
57 | the_object->name.name_u32 = _Objects_Build_name( |
---|
58 | ((0 <= length) ? s[ 0 ] : ' '), |
---|
59 | ((1 < length) ? s[ 1 ] : ' '), |
---|
60 | ((2 < length) ? s[ 2 ] : ' '), |
---|
61 | ((3 < length) ? s[ 3 ] : ' ') |
---|
62 | ); |
---|
63 | |
---|
64 | } |
---|
65 | |
---|
66 | return true; |
---|
67 | } |
---|