-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: move str_to_uint to a separate file
- Loading branch information
Showing
4 changed files
with
29 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <errno.h> | ||
#include <inttypes.h> | ||
|
||
#include "str_to_uint.h" | ||
|
||
int | ||
str_to_uint(const char *s, int base, uintmax_t *resultp) | ||
{ | ||
uintmax_t v; | ||
char *ep; | ||
errno = 0; | ||
v = strtoumax(s, &ep, base); | ||
if (s == ep) { | ||
return EINVAL; | ||
} | ||
if (*ep != 0) { | ||
return EINVAL; | ||
} | ||
if (errno != 0) { | ||
return errno; | ||
} | ||
*resultp = v; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <stdint.h> | ||
|
||
int str_to_uint(const char *s, int base, uintmax_t *resultp); |