diff options
author | Martin Wilck <mwilck@arcor.de> | 2013-06-27 21:39:27 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-07-02 09:43:51 +1000 |
commit | b76dc299752f01d03ac4013f4e68cf9ee439c879 (patch) | |
tree | 4459d9c3803ba32e95111812618c989ab75aba38 /Detail.c | |
parent | eae6b0366b4ea89c406a5ce22fef4b6670bd85f4 (diff) | |
download | mdadm-b76dc299752f01d03ac4013f4e68cf9ee439c879.tar.gz |
Detail: Factor out add_device()
Makes the code a little more readable.
Signed-off-by: Martin Wilck <mwilck@arcor.de>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'Detail.c')
-rw-r--r-- | Detail.c | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -32,6 +32,22 @@ static int cmpstringp(const void *p1, const void *p2) return strcmp(* (char * const *) p1, * (char * const *) p2); } +static int add_device(const char *dev, char ***p_devices, + int *p_max_devices, int n_devices) +{ + if (n_devices + 1 >= *p_max_devices) { + *p_max_devices += 16; + *p_devices = xrealloc(*p_devices, *p_max_devices * + sizeof(**p_devices)); + if (!*p_devices) { + *p_max_devices = 0; + return 0; + } + }; + (*p_devices)[n_devices] = xstrdup(dev); + return n_devices + 1; +} + int Detail(char *dev, struct context *c) { /* @@ -660,17 +676,11 @@ This is pretty boring rv |= 1; dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer); if (dv != NULL) { - if (c->brief) { - if (n_devices + 1 >= max_devices) { - max_devices += 16; - devices = xrealloc(devices, max_devices - *sizeof(*devices)); - if (!devices) - goto out; - }; - devices[n_devices] = xstrdup(dv); - n_devices++; - } else + if (c->brief) + n_devices = add_device(dv, &devices, + &max_devices, + n_devices); + else printf(" %s", dv); } if (!c->brief) printf("\n"); |