~ubuntu-branches/ubuntu/raring/findutils/raring

« back to all changes in this revision

Viewing changes to gnulib/lib/xstrtol.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2005-07-04 11:37:37 UTC
  • mto: (11.1.1 lenny) (1.1.10 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050704113737-oxfumqxsqgfz5gay
Tags: upstream-4.2.22
ImportĀ upstreamĀ versionĀ 4.2.22

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* A more useful interface to strtol.
2
 
   Copyright 1995, 1996, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
 
2
 
 
3
   Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004 Free
 
4
   Software Foundation, Inc.
3
5
 
4
6
   This program is free software; you can redistribute it and/or modify
5
7
   it under the terms of the GNU General Public License as published by
13
15
 
14
16
   You should have received a copy of the GNU General Public License
15
17
   along with this program; if not, write to the Free Software Foundation,
16
 
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
18
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
19
 
18
20
#ifndef XSTRTOL_H_
19
21
# define XSTRTOL_H_ 1
20
22
 
21
 
/* Get uintmax_t.  */
 
23
# include "exitfail.h"
 
24
 
22
25
# if HAVE_INTTYPES_H
23
26
#  include <inttypes.h>
24
 
# else
25
 
#  if HAVE_STDINT_H
26
 
#   include <stdint.h>
27
 
#  endif
28
27
# endif
29
 
 
30
 
# ifndef PARAMS
31
 
#  if defined PROTOTYPES || (defined __STDC__ && __STDC__)
32
 
#   define PARAMS(Args) Args
33
 
#  else
34
 
#   define PARAMS(Args) ()
35
 
#  endif
 
28
# if HAVE_STDINT_H
 
29
#  include <stdint.h>
36
30
# endif
37
31
 
38
32
# ifndef _STRTOL_ERROR
39
33
enum strtol_error
40
34
  {
41
 
    LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
 
35
    LONGINT_OK = 0,
 
36
 
 
37
    /* These two values can be ORed together, to indicate that both
 
38
       errors occurred.  */
 
39
    LONGINT_OVERFLOW = 1,
 
40
    LONGINT_INVALID_SUFFIX_CHAR = 2,
 
41
 
 
42
    LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR
 
43
                                                 | LONGINT_OVERFLOW),
 
44
    LONGINT_INVALID = 4
42
45
  };
43
46
typedef enum strtol_error strtol_error;
44
47
# endif
45
48
 
46
49
# define _DECLARE_XSTRTOL(name, type) \
47
 
  strtol_error \
48
 
    name PARAMS ((const char *s, char **ptr, int base, \
49
 
                  type *val, const char *valid_suffixes));
 
50
  strtol_error name (const char *, char **, int, type *, const char *);
50
51
_DECLARE_XSTRTOL (xstrtol, long int)
51
52
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
52
53
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
57
58
    {                                                                   \
58
59
      switch ((Err))                                                    \
59
60
        {                                                               \
60
 
        case LONGINT_OK:                                                \
 
61
        default:                                                        \
61
62
          abort ();                                                     \
62
63
                                                                        \
63
64
        case LONGINT_INVALID:                                           \
66
67
          break;                                                        \
67
68
                                                                        \
68
69
        case LONGINT_INVALID_SUFFIX_CHAR:                               \
 
70
        case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW:            \
69
71
          error ((Exit_code), 0, "invalid character following %s in `%s'", \
70
72
                 (Argument_type_string), (Str));                        \
71
73
          break;                                                        \
79
81
  while (0)
80
82
 
81
83
# define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err)             \
82
 
  _STRTOL_ERROR (2, Str, Argument_type_string, Err)
 
84
  _STRTOL_ERROR (exit_failure, Str, Argument_type_string, Err)
83
85
 
84
86
# define STRTOL_FAIL_WARN(Str, Argument_type_string, Err)               \
85
87
  _STRTOL_ERROR (0, Str, Argument_type_string, Err)