mirror of
https://github.com/linux-msm/qbootctl.git
synced 2026-02-25 13:13:44 -08:00
Use scope-based memory management for malloc, free, open, close, etc.
If we are using C++, we might as well use scope-based memory management for these things, cleaner and less error prone. Also removed unnecessary gotos.
This commit is contained in:
committed by
Caleb Connolly
parent
843aa92266
commit
9d7600df51
22
qbootctl.cpp
22
qbootctl.cpp
@@ -41,17 +41,23 @@ bool isslotnum(const char* str)
|
||||
return strspn(str, "01") == strlen(str);
|
||||
}
|
||||
|
||||
static void unexpectedSlot(const char *arg)
|
||||
{
|
||||
fprintf(stderr, "Expected slot not '%s'\n", arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned parseSlot(const char* arg)
|
||||
{
|
||||
char *end;
|
||||
int slot;
|
||||
if (!isslot(arg)) {
|
||||
goto fail;
|
||||
}
|
||||
if (!isslot(arg))
|
||||
unexpectedSlot(arg);
|
||||
|
||||
if (isslotnum(arg)) {
|
||||
slot = (int)strtol(arg, &end, 10);
|
||||
if (end == arg)
|
||||
goto fail;
|
||||
unexpectedSlot(arg);
|
||||
} else {
|
||||
switch (arg[0]) {
|
||||
case 'a':
|
||||
@@ -63,17 +69,11 @@ unsigned parseSlot(const char* arg)
|
||||
slot = 1;
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
unexpectedSlot(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return (unsigned)slot;
|
||||
|
||||
fail:
|
||||
fprintf(stderr,
|
||||
"Expected slot not '%s'\n",
|
||||
arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int usage()
|
||||
|
||||
Reference in New Issue
Block a user