Skip to content

Commit e3c3184

Browse files
committed
Sort PCM D-Bus paths from the oldest to the newest
1 parent 07a4be7 commit e3c3184

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bluealsactl/cmd-list-pcms.c

+12
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111
#include <getopt.h>
1212
#include <stdio.h>
1313
#include <stdlib.h>
14+
#include <string.h>
1415

1516
#include <dbus/dbus.h>
1617

1718
#include "bluealsactl.h"
1819
#include "shared/dbus-client-pcm.h"
1920

21+
static int ba_pcm_cmp(const void *a, const void *b) {
22+
const struct ba_pcm *pcm_a = a;
23+
const struct ba_pcm *pcm_b = b;
24+
if (pcm_a->sequence == pcm_b->sequence)
25+
return strcmp(pcm_a->pcm_path, pcm_b->pcm_path);
26+
return pcm_a->sequence - pcm_b->sequence;
27+
}
28+
2029
static void usage(const char *command) {
2130
printf("List all BlueALSA PCM paths.\n\n");
2231
bactl_print_usage("%s [OPTION]...", command);
@@ -64,6 +73,9 @@ static int cmd_list_pcms_func(int argc, char *argv[]) {
6473
return EXIT_FAILURE;
6574
}
6675

76+
/* Sort PCMs from the oldest to the newest (most recently added). */
77+
qsort(pcms, pcms_count, sizeof(*pcms), ba_pcm_cmp);
78+
6779
for (size_t i = 0; i < pcms_count; i++) {
6880
printf("%s\n", pcms[i].pcm_path);
6981
if (config.verbose) {

0 commit comments

Comments
 (0)