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

4.115
Last change on this file since d7c3883 was bab5c5fa, checked in by Joel Sherrill <joel.sherrill@…>, on 03/12/10 at 16:26:16

2010-03-12 Joel Sherrill <joel.sherrill@…>

  • ftpd/ftpd.c, httpd/asp.c, httpd/ejparse.c, httpd/emfdb.c, httpd/misc.c, httpd/um.c, httpd/webs.c, httpd/websuemf.c, libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_format.c, libfs/src/dosfs/msdos_misc.c, libfs/src/nfsclient/src/nfs.c, libmisc/capture/capture-cli.c, libmisc/monitor/mon-network.c, libmisc/shell/hexdump-odsyntax.c, libmisc/shell/main_ifconfig.c, libmisc/shell/shell.c, libmisc/shell/shell_makeargs.c, libmisc/uuid/parse.c, libnetworking/libc/gethostbydns.c, libnetworking/libc/gethostbyht.c, libnetworking/libc/gethostnamadr.c, libnetworking/libc/getnetnamadr.c, libnetworking/libc/inet_addr.c, libnetworking/libc/inet_network.c, libnetworking/libc/res_debug.c, libnetworking/libc/res_init.c, libnetworking/libc/res_query.c, libnetworking/rtems/rtems_mii_ioctl.c, score/src/objectgetnameasstring.c: Readdress use of ctype methods per recommendation from D.J. Delorie on the newlib mailing list. We should pass an unsigned char into these methods.
  • Property mode set to 100644
File size: 2.3 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 <stdlib.h>
20#include <ctype.h>
21#include <inttypes.h>
22
23/*
24 *  This method objects the name of an object and returns its name
25 *  in the form of a C string.  It attempts to be careful about
26 *  overflowing the user's string and about returning unprintable characters.
27 */
28
29char *_Objects_Get_name_as_string(
30  Objects_Id        id,
31  size_t            length,
32  char             *name
33)
34{
35  Objects_Information   *information;
36  const char            *s;
37  char                  *d;
38  uint32_t               i;
39  char                   lname[5];
40  Objects_Control       *the_object;
41  Objects_Locations      location;
42  Objects_Id             tmpId;
43
44  if ( length == 0 )
45    return NULL;
46
47  if ( name == NULL )
48    return NULL;
49
50  tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id;
51
52  information = _Objects_Get_information_id( tmpId );
53  if ( !information )
54    return NULL;
55
56  the_object = _Objects_Get( information, tmpId, &location );
57  switch ( location ) {
58
59#if defined(RTEMS_MULTIPROCESSING)
60    case OBJECTS_REMOTE:
61      /* not supported */
62#endif
63    case OBJECTS_ERROR:
64      return NULL;
65
66    case OBJECTS_LOCAL:
67
68      #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
69        if ( information->is_string ) {
70          s = the_object->name.name_p;
71        } else
72      #endif
73      {
74        uint32_t  u32_name = (uint32_t) the_object->name.name_u32;
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      d = name;
85      if ( s ) {
86        for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
87          *d = (isprint((unsigned char)*s)) ? *s : '*';
88        }
89      }
90      *d = '\0';
91
92      _Thread_Enable_dispatch();
93      return name;
94  }
95  return NULL;                  /* unreachable path */
96}
Note: See TracBrowser for help on using the repository browser.