sssd  2.2.3
About: SSSD provides a set of daemons to manage access to remote directories and authentication mechanisms such as LDAP, Kerberos or FreeIPA. It provides also an NSS and PAM interface toward the system.
  Fossies Dox: sssd-2.2.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

strtonum.c
Go to the documentation of this file.
1 /*
2  SSSD
3 
4  SSSD Utility functions
5 
6  Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include "config.h"
26 #include "util/util.h"
27 #include "util/strtonum.h"
28 
29 /* strtoint32 */
30 int32_t strtoint32(const char *nptr, char **endptr, int base)
31 {
32  long long ret = 0;
33 
34  errno = 0;
35  ret = strtoll(nptr, endptr, base);
36 
37  if (ret > INT32_MAX) {
38  errno = ERANGE;
39  return INT32_MAX;
40  }
41  else if (ret < INT32_MIN) {
42  errno = ERANGE;
43  return INT32_MIN;
44  }
45 
46  /* If errno was set by strtoll, we'll pass it back as-is */
47  return (int32_t)ret;
48 }
49 
50 
51 /* strtouint32 */
52 uint32_t strtouint32(const char *nptr, char **endptr, int base)
53 {
54  unsigned long long ret = 0;
55  errno = 0;
56  ret = strtoull(nptr, endptr, base);
57 
58  if (ret > UINT32_MAX) {
59  errno = ERANGE;
60  return UINT32_MAX;
61  }
62 
63  /* If errno was set by strtoll, we'll pass it back as-is */
64  return (uint32_t)ret;
65 }
66 
67 
68 /* strtouint16 */
69 uint16_t strtouint16(const char *nptr, char **endptr, int base)
70 {
71  unsigned long long ret = 0;
72  errno = 0;
73  ret = strtoull(nptr, endptr, base);
74 
75  if (ret > UINT16_MAX) {
76  errno = ERANGE;
77  return UINT16_MAX;
78  }
79 
80  /* If errno was set by strtoll, we'll pass it back as-is */
81  return (uint16_t)ret;
82 }
83 
strtouint16
uint16_t strtouint16(const char *nptr, char **endptr, int base)
Definition: strtonum.c:69
strtouint32
uint32_t strtouint32(const char *nptr, char **endptr, int base)
Definition: strtonum.c:52
strtonum.h
strtoint32
int32_t strtoint32(const char *nptr, char **endptr, int base)
Definition: strtonum.c:30
util.h
ret
errno_t ret
Definition: sbus_errors.c:31