Skip to content

Commit

Permalink
sort: change function names to be more descriptive/accurate
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Oct 24, 2018
1 parent 72feae0 commit 8405704
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion context.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static void reorder_channels(struct iio_device *dev)

/* Reorder channels by index */
qsort(dev->channels, dev->nb_channels, sizeof(struct iio_channel *),
qsort_iio_channel);
iio_channel_compare);

for (i = 0; i < dev->nb_channels; i++)
dev->channels[i]->number = i;
Expand Down
8 changes: 4 additions & 4 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ static int add_buffer_attributes(struct iio_device *dev, const char *devpath)
return ret;

qsort(dev->buffer_attrs, dev->nb_buffer_attrs, sizeof(char *),
qsort_iio_buffer_attr);
iio_buffer_attr_compare);
}

return 0;
Expand Down Expand Up @@ -1769,15 +1769,15 @@ static int create_device(void *d, const char *path)
goto err_free_scan_elements;

qsort(chn->attrs, chn->nb_attrs, sizeof(struct iio_channel_attr),
qsort_iio_channel_attr);
iio_channel_attr_compare);
}

ret = detect_and_move_global_attrs(dev);
if (ret < 0)
goto err_free_device;

qsort(dev->attrs, dev->nb_attrs, sizeof(char *),
qsort_iio_device_attr);
iio_device_attr_compare);

dev->words = (dev->nb_channels + 31) / 32;
if (dev->words) {
Expand Down Expand Up @@ -2003,7 +2003,7 @@ struct iio_context * local_create_context(void)
goto err_context_destroy;

qsort(ctx->devices, ctx->nb_devices, sizeof(struct iio_device *),
qsort_iio_device);
iio_device_compare);

foreach_in_dir(ctx, "/sys/kernel/debug/iio", true, add_debug);

Expand Down
20 changes: 13 additions & 7 deletions sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@
#include "iio-private.h"
#include <string.h>

/* These are a few functions to do sorting for various
/* These are a few functions to do sorting via qsort for various
* iio structures. For more info, see the qsort(3) man page.
* If the structures are updated, the sort functions may
*
* The qsort comparison function must return an integer less than, equal to,
* or greater than zero if the first argument is considered to be
* respectively less than, equal to, or greater than the second. If two
* members compare as equal, their order in the sort order is undefined.
*
* If the structures are updated, the compare functions may
* need to be updated.
*
* The actual arguments to these function are "pointers to
* pointers to char", but strcmp(3) arguments are "pointers
* to char", hence the cast plus dereference
*/

int qsort_iio_channel(const void *p1, const void *p2)
int iio_channel_compare(const void *p1, const void *p2)
{
const struct iio_channel *tmp1 = *(struct iio_channel **)p1;
const struct iio_channel *tmp2 = *(struct iio_channel **)p2;
Expand All @@ -53,31 +59,31 @@ int qsort_iio_channel(const void *p1, const void *p2)
return strcmp(tmp1->id, tmp2->id);
}

int qsort_iio_channel_attr(const void *p1, const void *p2)
int iio_channel_attr_compare(const void *p1, const void *p2)
{
const struct iio_channel_attr *tmp1 = (struct iio_channel_attr *)p1;
const struct iio_channel_attr *tmp2 = (struct iio_channel_attr *)p2;
/* qsort channel attributes by name */
return strcmp(tmp1->name, tmp2->name);
}

int qsort_iio_device(const void *p1, const void *p2)
int iio_device_compare(const void *p1, const void *p2)
{
const struct iio_device *tmp1 = *(struct iio_device **)p1;
const struct iio_device *tmp2 = *(struct iio_device **)p2;
/* qsort devices by ID */
return strcmp(tmp1->id, tmp2->id);
}

int qsort_iio_device_attr(const void *p1, const void *p2)
int iio_device_attr_compare(const void *p1, const void *p2)
{
const char *tmp1 = *(const char **)p1;
const char *tmp2 = *(const char **)p2;
/* qsort device attributes by name */
return strcmp(tmp1, tmp2);
}

int qsort_iio_buffer_attr(const void *p1, const void *p2)
int iio_buffer_attr_compare(const void *p1, const void *p2)
{
const char *tmp1 = *(const char **)p1;
const char *tmp2 = *(const char **)p2;
Expand Down
10 changes: 5 additions & 5 deletions sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef __IIO_QSORT_H__
#define __IIO_QSORT_H__

int qsort_iio_channel(const void *p1, const void *p2);
int qsort_iio_channel_attr(const void *p1, const void *p2);
int qsort_iio_device(const void *p1, const void *p2);
int qsort_iio_device_attr(const void *p1, const void *p2);
int qsort_iio_buffer_attr(const void *p1, const void *p2);
int iio_channel_compare(const void *p1, const void *p2);
int iio_channel_attr_compare(const void *p1, const void *p2);
int iio_device_compare(const void *p1, const void *p2);
int iio_device_attr_compare(const void *p1, const void *p2);
int iio_buffer_attr_compare(const void *p1, const void *p2);

#endif /* __IIO_QSORT_H__ */

0 comments on commit 8405704

Please sign in to comment.