source: rtems/cpukit/score/src/objectgetnameasstring.c @ 717adfb3

4.104.114.84.95
Last change on this file since 717adfb3 was 717adfb3, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/16/07 at 06:51:53

2007-05-16 Ralf Corsépius <ralf.corsepius@…>

  • score/src/objectgetnameasstring.c: Remove bogus ifdef RTEMS_POSIX_API.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2007.
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 <stdlib.h>
20#include <stdio.h>
21#include <ctype.h>
22#include <inttypes.h>
23
24
25/*
26 *  This method objects the name of an object and returns its name
27 *  in the form of a C string.  It attempts to be careful about
28 *  overflowing the user's string and about returning unprintable characters.
29 */
30
31char *_Objects_Get_name_as_string(
32  Objects_Id        id,
33  size_t            length,
34  char             *name
35)
36{
37  Objects_Information *information;
38  char                  *s;
39  char                  *d;
40  uint32_t               i;
41  char                   lname[5];
42  Objects_Control       *the_object;
43  Objects_Locations      location;
44
45  if ( length == 0 )
46    return NULL;
47
48  if ( name == NULL )
49    return NULL;
50
51  information = _Objects_Get_information( id );
52  if ( !information )
53    return NULL;
54
55  the_object = _Objects_Get( information, id, &location );
56  switch ( location ) {
57
58    case OBJECTS_REMOTE:
59      /* not supported */
60    case OBJECTS_ERROR:
61      return NULL;
62
63    case OBJECTS_LOCAL:
64
65      /*
66       *  Neither the Classic nor ITRON APIs use string names.
67       */
68#ifdef RTEMS_POSIX_API
69        if ( information->is_string ) {
70          s = the_object->name;
71        } else
72#endif
73      {
74        uint32_t  u32_name = (uint32_t) the_object->name;
75
76        lname[ 0 ] = (u32_name >> 24) & 0xff;
77        lname[ 1 ] = (u32_name >> 16) & 0xff;
78        lname[ 2 ] = (u32_name >>  8) & 0xff;
79        lname[ 3 ] = (u32_name >>  0) & 0xff;
80        lname[ 4 ] = '\0';
81        s = lname;
82      }
83
84      for ( i=0, d=name ; i<(length-1) && *s ; i++, s++, d++ ) {
85        *d = (!isprint(*s)) ?  '*' : *s;
86      }
87      *d = '\0';
88
89      _Thread_Enable_dispatch();
90      return name;
91  }
92  return NULL;                  /* unreachable path */
93}
Note: See TracBrowser for help on using the repository browser.