summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/objectsetname.c
blob: c699570209845e90216a2554af6dac192e7d6e5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * @file
 *
 * @brief Set Objects Name
 * @ingroup ScoreObject
 */

/*
 *  COPYRIGHT (c) 1989-2014.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/score/objectimpl.h>
#include <rtems/score/wkspace.h>

#include <string.h>

bool _Objects_Set_name(
  Objects_Information *information,
  Objects_Control     *the_object,
  const char          *name
)
{
  size_t                 length;
  const char            *s;

  s      = name;
  length = strnlen( name, information->name_length );

#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
  if ( information->is_string ) {
    char *d;

    d = _Workspace_Allocate( length + 1 );
    if ( !d )
      return false;

    _Workspace_Free( (void *)the_object->name.name_p );
    the_object->name.name_p = NULL;

    strncpy( d, name, length );
    d[length] = '\0';
    the_object->name.name_p = d;
  } else
#endif
  {
    the_object->name.name_u32 =  _Objects_Build_name(
      ((length)     ? s[ 0 ] : ' '),
      ((length > 1) ? s[ 1 ] : ' '),
      ((length > 2) ? s[ 2 ] : ' '),
      ((length > 3) ? s[ 3 ] : ' ')
    );

  }

  return true;
}