mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
commandhelper: Simplify envsort
This saves two invocations of each `strndup` and `free`. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
9f9b133e0c
commit
d274092131
@ -37,24 +37,19 @@ extern char **environ;
|
|||||||
|
|
||||||
static int envsort(const void *a, const void *b)
|
static int envsort(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const char *const*astrptr = a;
|
const char *astr = *(const char**)a;
|
||||||
const char *const*bstrptr = b;
|
const char *bstr = *(const char**)b;
|
||||||
const char *astr = *astrptr;
|
|
||||||
const char *bstr = *bstrptr;
|
|
||||||
char *aeq = strchr(astr, '=');
|
|
||||||
char *beq = strchr(bstr, '=');
|
|
||||||
char *akey;
|
|
||||||
char *bkey;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!(akey = strndup(astr, aeq - astr)))
|
while (true) {
|
||||||
abort();
|
char achar = (*astr == '=') ? '\0' : *astr;
|
||||||
if (!(bkey = strndup(bstr, beq - bstr)))
|
char bchar = (*bstr == '=') ? '\0' : *bstr;
|
||||||
abort();
|
|
||||||
ret = strcmp(akey, bkey);
|
if ((achar == '\0') || (achar != bchar))
|
||||||
free(akey);
|
return achar - bchar;
|
||||||
free(bkey);
|
|
||||||
return ret;
|
astr++;
|
||||||
|
bstr++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user