source: rtems-schedsim/schedsim/shell/shared/lookup_task.c @ 6425eb9

Last change on this file since 6425eb9 was ff91f4e, checked in by Joel Sherrill <joel.sherrill@…>, on 05/22/14 at 21:17:25

lookup_task.c: Fix bug where only first four chars of name mattered

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 *  Given Name or ID String, give Id
3 *
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17
18#include <rtems.h>
19#include <rtems/stringto.h>
20
21#ifndef METHOD_NAME
22  #define METHOD_NAME lookup_task
23#endif
24#ifndef RTEMS_IDENT_NAME
25  #define RTEMS_IDENT_NAME rtems_task_ident
26  #define DOING_TASKS
27#endif
28
29int METHOD_NAME(
30  const char *string,
31  rtems_id   *id
32)
33{
34  char               name[5];
35  rtems_status_code  status;
36  unsigned long      tmp;
37
38  if ( string[0] != '0' ) {
39    #ifdef DOING_TASKS
40      if ( !strcmp( string, "SELF" ) ) {
41        *id = _Thread_Executing->Object.id;
42        return 0;
43      }
44    #endif
45    if ( strlen( string ) != 4 ) {
46      return -1;
47    }
48    memset( name, '\0', sizeof(name) );
49    strncpy( name, string, 4 );
50    status = RTEMS_IDENT_NAME(
51      rtems_build_name( name[0], name[1], name[2], name[3] ),
52      OBJECTS_SEARCH_ALL_NODES,
53      id
54    );
55    if ( status != RTEMS_SUCCESSFUL )
56      return 1;
57  } else {
58    if ( rtems_string_to_unsigned_long( string, &tmp, NULL, 0) ) {
59      fprintf( stderr, "Argument (%s) is not a number\n", string );
60      return 1;
61    }
62    *id = (rtems_id) tmp;
63  }
64
65  return 0;
66}
Note: See TracBrowser for help on using the repository browser.