source: rtems/cpukit/libmisc/stringto/stringtounsignedchar.c

Last change on this file was cfe8f7a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/20 at 14:14:06

doxygen: Switch @brief and @ingroup

This order change fixes the Latex documentation build via Doxygen.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup libmisc_conv_help Conversion Helpers
5 *
6 * @brief Convert String to Unsigned Character (with validation)
7 */
8
9/*
10 *  COPYRIGHT (c) 2009.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <errno.h>
25#include <stdlib.h>
26#include <limits.h>
27
28#include <rtems/stringto.h>
29
30/*
31 *  Instantiate an error checking wrapper for strtoul (unsigned char)
32 */
33
34rtems_status_code rtems_string_to_unsigned_char (
35  const char *s,
36  unsigned char *n,
37  char **endptr,
38  int base
39)
40{
41  unsigned long result;
42  char *end;
43
44  if ( !n )
45    return RTEMS_INVALID_ADDRESS;
46
47  errno = 0;
48  *n = 0;
49
50  result = strtoul( s, &end, base );
51
52  if ( endptr )
53    *endptr = end;
54
55  if ( end == s )
56    return RTEMS_NOT_DEFINED;
57
58  if ( ( errno == ERANGE ) &&
59    (( result == 0 ) || ( result == ULONG_MAX )))
60      return RTEMS_INVALID_NUMBER;
61
62#if (UCHAR_MAX < ULONG_MAX)
63  if ( result > UCHAR_MAX ) {
64    errno = ERANGE;
65    return RTEMS_INVALID_NUMBER;
66  }
67#endif
68
69  *n = result;
70
71  return RTEMS_SUCCESSFUL;
72}
Note: See TracBrowser for help on using the repository browser.