Skip to content

Commit

Permalink
Add a parse_uint()
Browse files Browse the repository at this point in the history
I like how the unsigned conversion functions still accept signed inputs.
Sure, -42 is *totally* within the range of an unsigned int.
  • Loading branch information
Freaky committed Apr 21, 2020
1 parent 91214f3 commit 5e83cb3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion checkrestart.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ parse_int(const char *str, int *value)
return (*str != '\0' && *end == '\0');
}

static bool
parse_uint(const char *str, unsigned int *value)
{
char *end;

*value = strtoumax(str, &end, 10);
return (*str != '\0' && *end == '\0');
}

static int
gettermwidth(void)
{
Expand Down Expand Up @@ -257,7 +266,7 @@ main(int argc, char *argv[])
break;
case 'u':
uflag = true;
if (!parse_int(optarg, (int *)&filter_uid) && !user_getuid(optarg, &filter_uid)) {
if (!parse_uint(optarg, &filter_uid) && !user_getuid(optarg, &filter_uid)) {
xo_errx(EX_NOUSER, "user \"%s\" not found", optarg);
}
break;
Expand Down

0 comments on commit 5e83cb3

Please sign in to comment.