source: rtems/cpukit/score/src/objectsetname.c @ 6fd4d06f

4.104.115
Last change on this file since 6fd4d06f was 6fd4d06f, checked in by Joel Sherrill <joel.sherrill@…>, on 09/28/09 at 23:00:20

2009-09-28 Joel Sherrill <joel.sherrill@…>

  • score/src/objectidtoname.c: Remove error which cannot be reached since API that calls this checks the error first.
  • score/src/objectsetname.c: Adjust handling of length.
  • Property mode set to 100644
File size: 1.5 KB
Line 
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 <rtems/score/wkspace.h>
20#include <stdlib.h>
21#include <ctype.h>
22#include <inttypes.h>
23#include <string.h>
24
25
26/*
27 *  This method sets the name of an object based upon a C string.
28 */
29
30bool _Objects_Set_name(
31  Objects_Information *information,
32  Objects_Control     *the_object,
33  const char          *name
34)
35{
36  size_t                 length;
37  const char            *s;
38
39  s      = name;
40  length = strnlen( name, information->name_length );
41
42#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
43  if ( information->is_string ) {
44    char *d;
45
46    d = _Workspace_Allocate( length + 1 );
47    if ( !d )
48      return false;
49
50    if ( the_object->name.name_p ) {
51      _Workspace_Free( (void *)the_object->name.name_p );
52      the_object->name.name_p = NULL;
53    }
54
55    strncpy( d, name, length );
56    the_object->name.name_p = d;
57  } else
58#endif
59  {
60    the_object->name.name_u32 =  _Objects_Build_name(
61      ((0 <= length) ? s[ 0 ] : ' '),
62      ((1 <  length) ? s[ 1 ] : ' '),
63      ((2 <  length) ? s[ 2 ] : ' '),
64      ((3 <  length) ? s[ 3 ] : ' ')
65    );
66
67  }
68
69  return true;
70}
Note: See TracBrowser for help on using the repository browser.