source: rtems/cpukit/score/src/objectgetnameasstring.c @ 8b9bc54

4.115
Last change on this file since 8b9bc54 was 8b9bc54, checked in by Josh Oguin <josh.oguin@…>, on 11/19/14 at 20:49:46

objectgetnameasstring.c: Reformat _Objects_Get() switch to follow pattern

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Extracts a Node from a Chain
5 *
6 * @ingroup Score
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/threadimpl.h>
23
24#include <ctype.h>
25
26/*
27 *  This method objects the name of an object and returns its name
28 *  in the form of a C string.  It attempts to be careful about
29 *  overflowing the user's string and about returning unprintable characters.
30 */
31
32char *_Objects_Get_name_as_string(
33  Objects_Id        id,
34  size_t            length,
35  char             *name
36)
37{
38  Objects_Information   *information;
39  const char            *s;
40  char                  *d;
41  uint32_t               i;
42  char                   lname[5];
43  Objects_Control       *the_object;
44  Objects_Locations      location;
45  Objects_Id             tmpId;
46
47  if ( length == 0 )
48    return NULL;
49
50  if ( name == NULL )
51    return NULL;
52
53  tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Get_executing()->Object.id : id;
54
55  information = _Objects_Get_information_id( tmpId );
56  if ( !information )
57    return NULL;
58
59  the_object = _Objects_Get( information, tmpId, &location );
60  switch ( location ) {
61
62    case OBJECTS_LOCAL:
63
64      #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
65        if ( information->is_string ) {
66          s = the_object->name.name_p;
67        } else
68      #endif
69      {
70        uint32_t  u32_name = (uint32_t) the_object->name.name_u32;
71
72        lname[ 0 ] = (u32_name >> 24) & 0xff;
73        lname[ 1 ] = (u32_name >> 16) & 0xff;
74        lname[ 2 ] = (u32_name >>  8) & 0xff;
75        lname[ 3 ] = (u32_name >>  0) & 0xff;
76        lname[ 4 ] = '\0';
77        s = lname;
78      }
79
80      d = name;
81      if ( s ) {
82        for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
83          *d = (isprint((unsigned char)*s)) ? *s : '*';
84        }
85      }
86      *d = '\0';
87
88      _Objects_Put( the_object );
89      return name;
90
91#if defined(RTEMS_MULTIPROCESSING)
92    case OBJECTS_REMOTE:
93      /* not supported */
94#endif
95    case OBJECTS_ERROR:
96      return NULL;
97
98  }
99  return NULL;                  /* unreachable path */
100}
Note: See TracBrowser for help on using the repository browser.