mirror of
https://github.com/troglobit/libite.git
synced 2026-11-17 19:30:17 +00:00
Update code docs for string functions and macros as well
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
0a98f5bbd1
commit
970fa47ecf
12 files changed
+245
-63
No files matched your search
+42
-6
@@ -17,24 +17,60 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file strtonum.c
|
||||
* @author Ted Unangst
|
||||
* @author Todd Miller
|
||||
* @date 2004
|
||||
* @copyright ISC License
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef strtonum
|
||||
#define INVALID 1
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
#define INVALID 1 /**< internal */
|
||||
#define TOOSMALL 2 /**< internal */
|
||||
#define TOOLARGE 3 /**< internal */
|
||||
|
||||
#ifndef LLONG_MAX
|
||||
# define LLONG_MAX 0x7fffffffffffffffLL
|
||||
# define LLONG_MAX 0x7fffffffffffffffLL /**< internal */
|
||||
#endif
|
||||
|
||||
#ifndef LLONG_MIN
|
||||
# define LLONG_MIN (-0x7fffffffffffffffLL - 1)
|
||||
# define LLONG_MIN (-0x7fffffffffffffffLL - 1) /**< internal */
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Reliably convert string value to an integer
|
||||
* @param numstr String to convert to a number
|
||||
* @param minval Lower bound to check number against
|
||||
* @param maxval Upper bound to check number against
|
||||
* @param errstrp Pointer to error string
|
||||
*
|
||||
* This function converts the string in @p numstr to a long long value.
|
||||
* The function was designed to facilitate safe, robust programming and
|
||||
* overcome the shortcomings of the atoi(3) and strtol(3) family of
|
||||
* interfaces.
|
||||
*
|
||||
* The string may begin with an arbitrary amount of whitespace (as
|
||||
* determined by isspace(3)) followed by a single optional ‘+’ or ‘-’
|
||||
* sign.
|
||||
*
|
||||
* The remainder of the string is converted to a long long value
|
||||
* according to base 10.
|
||||
*
|
||||
* The value obtained is then checked against the provided @p minval and
|
||||
* @p maxval bounds. If @p errstrp is non-NULL, strtonum() stores an
|
||||
* error string in @p *errstrp indicating the failure.
|
||||
*
|
||||
* @returns The result of the conversion, unless the value would exceed
|
||||
* the provided bounds or is invalid. On error, 0 is returned, @a errno
|
||||
* is set, and @p errstrp points to an error message. @p *errstr* is set
|
||||
* to @c NULL on success; this fact can be used to differentiate a
|
||||
* successful return of 0 from an error.
|
||||
*/
|
||||
long long
|
||||
strtonum(const char *numstr, long long minval, long long maxval,
|
||||
const char **errstrp)
|
||||
|
||||
Reference in new issue
Block a user