source: rtems/cpukit/score/src/objectsetname.c @ d7c3883

4.115
Last change on this file since d7c3883 was a0323a9f, checked in by Joel Sherrill <joel.sherrill@…>, on 02/16/11 at 00:24:49

2011-02-15 Joel Sherrill <joel.sherrilL@…>

  • libmisc/capture/capture.c, posix/src/keyfreememory.c, posix/src/pthread.c, score/include/rtems/score/wkspace.h, score/src/objectextendinformation.c, score/src/objectnamespaceremove.c, score/src/objectsetname.c, score/src/threadclose.c, score/src/threadinitialize.c, score/src/wkspace.c: Many places were checking for a NULL pointer before calling _Workspace_Free. By moving the check into _Workspace_Free, we eliminate a number of conditional paths and make it harder to return a NULL pointer.
  • Property mode set to 100644
File size: 1.4 KB
Line 
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 *  $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    _Workspace_Free( (void *)the_object->name.name_p );
51    the_object->name.name_p = NULL;
52
53    strncpy( d, name, length );
54    d[length] = '\0';
55    the_object->name.name_p = d;
56  } else
57#endif
58  {
59    the_object->name.name_u32 =  _Objects_Build_name(
60      ((0 <= length) ? s[ 0 ] : ' '),
61      ((1 <  length) ? s[ 1 ] : ' '),
62      ((2 <  length) ? s[ 2 ] : ' '),
63      ((3 <  length) ? s[ 3 ] : ' ')
64    );
65
66  }
67
68  return true;
69}
Note: See TracBrowser for help on using the repository browser.