* @param endptr [optional] reference to remainder of the string
* @param base base of the numbering scheme
* @param err error occured during conversion
+ * @flags controlling conversion feature
* @result result of the conversion as provided by strtoul
*
+ * The following flags are supported
+ * SMB_STR_STANDARD # raise error if negative or non-numeric
+ * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
+ *
* The following errors are detected
* - wrong base
* - value overflow
* - no conversion due to empty string or not representing a number
*/
unsigned long int
-strtoul_err(const char *nptr, char **endptr, int base, int *err)
+smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags)
{
unsigned long int val;
int saved_errno = errno;
return val;
}
- /* did we convert a negative "number" ? */
- needle = strchr(nptr, '-');
- if (needle != NULL && needle < tmp_endptr) {
- *err = EINVAL;
+ if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
+ /* did we convert a negative "number" ? */
+ needle = strchr(nptr, '-');
+ if (needle != NULL && needle < tmp_endptr) {
+ *err = EINVAL;
+ }
}
errno = saved_errno;
* @param endptr [optional] reference to remainder of the string
* @param base base of the numbering scheme
* @param err error occured during conversion
+ * @flags controlling conversion feature
* @result result of the conversion as provided by strtoull
*
+ * The following flags are supported
+ * SMB_STR_STANDARD # raise error if negative or non-numeric
+ * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
+ *
* The following errors are detected
* - wrong base
* - value overflow
* - no conversion due to empty string or not representing a number
*/
unsigned long long int
-strtoull_err(const char *nptr, char **endptr, int base, int *err)
+smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags)
{
unsigned long long int val;
int saved_errno = errno;
return val;
}
- /* did we convert a negative "number" ? */
- needle = strchr(nptr, '-');
- if (needle != NULL && needle < tmp_endptr) {
- *err = EINVAL;
+ if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
+ /* did we convert a negative "number" ? */
+ needle = strchr(nptr, '-');
+ if (needle != NULL && needle < tmp_endptr) {
+ *err = EINVAL;
+ }
}
errno = saved_errno;
Utility functions for Samba
Copyright (C) Andrew Tridgell 1992-1999
Copyright (C) Jelmer Vernooij 2005
+ Copyright (C) Swen Schillig 2019
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
SMB_STR_ALLOW_NEGATIVE)
unsigned long int
-strtoul_err(const char *nptr, char **endptr, int base, int *err);
+smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags);
unsigned long long int
-strtoull_err(const char *nptr, char **endptr, int base, int *err);
+smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags);
+#define strtoul_err(nptr, endptr, base, err) \
+ smb_strtoul(nptr, endptr, base, err, SMB_STR_STANDARD)
+#define strtoull_err(nptr, endptr, base, err) \
+ smb_strtoull(nptr, endptr, base, err, SMB_STR_STANDARD)
/**
* Write dump of binary data to a callback