mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 18:55:40 +03:00
pstore: use typesafe_qsort
Also move "allocated" above "n", since, conceptually, it is modified earlier (and that is the definition order we normally use).
This commit is contained in:
parent
eb10767565
commit
bacafb0990
@ -98,8 +98,8 @@ typedef struct PStoreEntry {
|
|||||||
|
|
||||||
typedef struct PStoreList {
|
typedef struct PStoreList {
|
||||||
PStoreEntry *entries;
|
PStoreEntry *entries;
|
||||||
|
size_t n_allocated;
|
||||||
size_t n_entries;
|
size_t n_entries;
|
||||||
size_t n_entries_allocated;
|
|
||||||
} PStoreList;
|
} PStoreList;
|
||||||
|
|
||||||
static void pstore_entries_reset(PStoreList *list) {
|
static void pstore_entries_reset(PStoreList *list) {
|
||||||
@ -109,8 +109,7 @@ static void pstore_entries_reset(PStoreList *list) {
|
|||||||
list->n_entries = 0;
|
list->n_entries = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compare_pstore_entries(const void *_a, const void *_b) {
|
static int compare_pstore_entries(const PStoreEntry *a, const PStoreEntry *b) {
|
||||||
PStoreEntry *a = (PStoreEntry *)_a, *b = (PStoreEntry *)_b;
|
|
||||||
return strcmp(a->dirent.d_name, b->dirent.d_name);
|
return strcmp(a->dirent.d_name, b->dirent.d_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +345,7 @@ static int list_files(PStoreList *list, const char *sourcepath) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GREEDY_REALLOC(list->entries, list->n_entries_allocated, list->n_entries + 1))
|
if (!GREEDY_REALLOC(list->entries, list->n_allocated, list->n_entries + 1))
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
list->entries[list->n_entries++] = (PStoreEntry) {
|
list->entries[list->n_entries++] = (PStoreEntry) {
|
||||||
@ -391,7 +390,7 @@ static int run(int argc, char *argv[]) {
|
|||||||
|
|
||||||
/* Handle each pstore file */
|
/* Handle each pstore file */
|
||||||
/* Sort files lexigraphically ascending, generally needed by all */
|
/* Sort files lexigraphically ascending, generally needed by all */
|
||||||
qsort_safe(list.entries, list.n_entries, sizeof(PStoreEntry), compare_pstore_entries);
|
typesafe_qsort(list.entries, list.n_entries, compare_pstore_entries);
|
||||||
|
|
||||||
/* Process known file types */
|
/* Process known file types */
|
||||||
process_dmesg_files(&list);
|
process_dmesg_files(&list);
|
||||||
|
Loading…
Reference in New Issue
Block a user