source: rtems/cpukit/score/src/objectgetnameasstring.c @ ce19f1fa

4.104.114.95
Last change on this file since ce19f1fa was ce19f1fa, checked in by Joel Sherrill <joel.sherrill@…>, on 01/23/08 at 22:57:43

2008-01-23 Joel Sherrill <joel.sherrill@…>

  • itron/include/rtems/itron/object.h, itron/src/cre_tsk.c, libblock/src/show_bdbuf.c, libmisc/capture/capture-cli.c, libmisc/capture/capture.c, libmisc/monitor/mon-manager.c, libmisc/stackchk/check.c, posix/src/condinit.c, posix/src/keycreate.c, posix/src/mqueuecreatesupp.c, posix/src/mqueuedeletesupp.c, posix/src/mqueuenametoid.c, posix/src/mqueueopen.c, posix/src/mqueueunlink.c, posix/src/mutexinit.c, posix/src/pbarrierinit.c, posix/src/prwlockinit.c, posix/src/pspininit.c, posix/src/pthreadcreate.c, posix/src/pthreadexit.c, posix/src/semaphorecreatesupp.c, posix/src/semaphorenametoid.c, posix/src/timercreate.c, rtems/src/barrierident.c, rtems/src/dpmemident.c, rtems/src/msgqident.c, rtems/src/partident.c, rtems/src/ratemonident.c, rtems/src/regionident.c, rtems/src/semident.c, rtems/src/taskident.c, rtems/src/timerident.c, sapi/src/extensionident.c, score/Makefile.am, score/include/rtems/score/object.h, score/inline/rtems/score/object.inl, score/src/apimutexallocate.c, score/src/objectextendinformation.c, score/src/objectgetnameasstring.c, score/src/objectmp.c, score/src/objectnametoid.c: Convert the Objects_Name type from a simple type to a union of an unsigned 32 bit integer and a pointer. This should help eliminate weird casts between u32 and pointers in various places. The APIs now have to explicitly call _u32 or _string versions of helper routines. This should also simplify things and eliminate the need for ugly casts in some cases.
  • score/src/objectclearname.c, score/src/objectcomparenameraw.c, score/src/objectcomparenamestring.c, score/src/objectcopynameraw.c, score/src/objectcopynamestring.c: Removed.
  • Property mode set to 100644
File size: 2.1 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  const 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#if defined(RTEMS_MULTIPROCESSING)
59    case OBJECTS_REMOTE:
60      /* not supported */
61#endif
62    case OBJECTS_ERROR:
63      return NULL;
64
65    case OBJECTS_LOCAL:
66
67      if ( information->is_string ) {
68        s = the_object->name.name_p;
69      } else {
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      for ( i=0, d=name ; i<(length-1) && *s ; i++, s++, d++ ) {
81        *d = (!isprint(*s)) ?  '*' : *s;
82      }
83      *d = '\0';
84
85      _Thread_Enable_dispatch();
86      return name;
87  }
88  return NULL;                  /* unreachable path */
89}
Note: See TracBrowser for help on using the repository browser.