mirror of
https://github.com/troglobit/libite.git
synced 2026-11-06 15:50:57 +00:00
Add atonum() - Convert string to natural number, returns -1 on error.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
4005dd5e2c
commit
41c9caff17
2 files changed
+19
No files matched your search
@@ -13,6 +13,11 @@ traversing lists while deleting/freeing nodes.
|
|||||||
Helper Macros
|
Helper Macros
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
- `atonum(str)`
|
||||||
|
|
||||||
|
Convert string to natural number, works for 32-bit non-negative
|
||||||
|
integers. Returns -1 on error.
|
||||||
|
|
||||||
- `blkdev(dev)`
|
- `blkdev(dev)`
|
||||||
|
|
||||||
Create block device
|
Create block device
|
||||||
|
|||||||
@@ -101,6 +101,20 @@ static inline int fisslashdir(char *dir)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert string to natural number (0-2147483647), returns -1 on error. */
|
||||||
|
static inline int atonum(const char *str)
|
||||||
|
{
|
||||||
|
int val = -1;
|
||||||
|
char *errstr;
|
||||||
|
|
||||||
|
if (str) {
|
||||||
|
val = strtonum(str, 0, INT32_MAX, &errstr);
|
||||||
|
if (errstr)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
/* Validate string, non NULL and not zero length */
|
/* Validate string, non NULL and not zero length */
|
||||||
static inline int string_valid (const char *s)
|
static inline int string_valid (const char *s)
|
||||||
|
|||||||
Reference in new issue
Block a user