summaryrefslogtreecommitdiff
path: root/Detail.c
diff options
context:
space:
mode:
authorMartin Wilck <mwilck@arcor.de>2013-06-27 21:39:27 +0200
committerNeilBrown <neilb@suse.de>2013-07-02 09:43:51 +1000
commitb76dc299752f01d03ac4013f4e68cf9ee439c879 (patch)
tree4459d9c3803ba32e95111812618c989ab75aba38 /Detail.c
parenteae6b0366b4ea89c406a5ce22fef4b6670bd85f4 (diff)
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.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/Detail.c b/Detail.c
index 05e645c1..83395f64 100644
--- a/Detail.c
+++ b/Detail.c
@@ -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");