aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-08 06:55:10 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:47 -0700
commit0b4c78339608179841838798517485208cee08a2 (patch)
tree721c0adc45b7a53af2fe5ec60dfb4b6dcc76b682
parentb0dd57ac8f35755b5d367365d1a80d3a5b9527e8 (diff)
downloadmpd-0b4c78339608179841838798517485208cee08a2.tar.gz
mpd-0b4c78339608179841838798517485208cee08a2.tar.xz
mpd-0b4c78339608179841838798517485208cee08a2.zip
dirvec: moved code to dirvec.c
Having all functions as static (non-inline) functions generates GCC warnings, and duplicates binary code across several object files. Most of dirvec's methods are too complex for becoming inline functions. Move them all to dirvec.c and publish the prototypes in dirvec.h.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/dirvec.c69
-rw-r--r--src/dirvec.h67
3 files changed, 75 insertions, 62 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index bfefd5eec..89577360c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -113,6 +113,7 @@ mpd_SOURCES = \
dbUtils.c \
decode.c \
directory.c \
+ dirvec.c \
inputPlugin.c \
inputStream.c \
inputStream_file.c \
diff --git a/src/dirvec.c b/src/dirvec.c
new file mode 100644
index 000000000..f84aa37fc
--- /dev/null
+++ b/src/dirvec.c
@@ -0,0 +1,69 @@
+#include "dirvec.h"
+#include "os_compat.h"
+#include "utils.h"
+
+static size_t dv_size(struct dirvec *dv)
+{
+ return dv->nr * sizeof(Directory *);
+}
+
+/* Only used for sorting/searching a dirvec, not general purpose compares */
+static int dirvec_cmp(const void *d1, const void *d2)
+{
+ const Directory *a = ((const Directory * const *)d1)[0];
+ const Directory *b = ((const Directory * const *)d2)[0];
+ return strcmp(a->path, b->path);
+}
+
+void dirvec_sort(struct dirvec *dv)
+{
+ qsort(dv->base, dv->nr, sizeof(Directory *), dirvec_cmp);
+}
+
+Directory *dirvec_find(struct dirvec *dv, const char *path)
+{
+ int i;
+
+ for (i = dv->nr; --i >= 0; )
+ if (!strcmp(dv->base[i]->path, path))
+ return dv->base[i];
+ return NULL;
+}
+
+int dirvec_delete(struct dirvec *dv, Directory *del)
+{
+ int i;
+
+ for (i = dv->nr; --i >= 0; ) {
+ if (dv->base[i] != del)
+ continue;
+ /* we _don't_ call freeDirectory() here */
+ if (!--dv->nr) {
+ free(dv->base);
+ dv->base = NULL;
+ } else {
+ memmove(&dv->base[i], &dv->base[i + 1],
+ (dv->nr - i + 1) * sizeof(Directory *));
+ dv->base = xrealloc(dv->base, dv_size(dv));
+ }
+ return i;
+ }
+
+ return -1; /* not found */
+}
+
+void dirvec_add(struct dirvec *dv, Directory *add)
+{
+ ++dv->nr;
+ dv->base = xrealloc(dv->base, dv_size(dv));
+ dv->base[dv->nr - 1] = add;
+}
+
+void dirvec_destroy(struct dirvec *dv)
+{
+ if (dv->base) {
+ free(dv->base);
+ dv->base = NULL;
+ }
+ dv->nr = 0;
+}
diff --git a/src/dirvec.h b/src/dirvec.h
index 8b2f634e2..94abd681f 100644
--- a/src/dirvec.h
+++ b/src/dirvec.h
@@ -2,72 +2,15 @@
#define DIRVEC_H
#include "directory.h"
-#include "os_compat.h"
-#include "utils.h"
-static size_t dv_size(struct dirvec *dv)
-{
- return dv->nr * sizeof(Directory *);
-}
+void dirvec_sort(struct dirvec *dv);
-/* Only used for sorting/searching a dirvec, not general purpose compares */
-static int dirvec_cmp(const void *d1, const void *d2)
-{
- const Directory *a = ((const Directory * const *)d1)[0];
- const Directory *b = ((const Directory * const *)d2)[0];
- return strcmp(a->path, b->path);
-}
+Directory *dirvec_find(struct dirvec *dv, const char *path);
-static void dirvec_sort(struct dirvec *dv)
-{
- qsort(dv->base, dv->nr, sizeof(Directory *), dirvec_cmp);
-}
+int dirvec_delete(struct dirvec *dv, Directory *del);
-static Directory *dirvec_find(struct dirvec *dv, const char *path)
-{
- int i;
+void dirvec_add(struct dirvec *dv, Directory *add);
- for (i = dv->nr; --i >= 0; )
- if (!strcmp(dv->base[i]->path, path))
- return dv->base[i];
- return NULL;
-}
+void dirvec_destroy(struct dirvec *dv);
-static int dirvec_delete(struct dirvec *dv, Directory *del)
-{
- int i;
-
- for (i = dv->nr; --i >= 0; ) {
- if (dv->base[i] != del)
- continue;
- /* we _don't_ call freeDirectory() here */
- if (!--dv->nr) {
- free(dv->base);
- dv->base = NULL;
- } else {
- memmove(&dv->base[i], &dv->base[i + 1],
- (dv->nr - i + 1) * sizeof(Directory *));
- dv->base = xrealloc(dv->base, dv_size(dv));
- }
- return i;
- }
-
- return -1; /* not found */
-}
-
-static void dirvec_add(struct dirvec *dv, Directory *add)
-{
- ++dv->nr;
- dv->base = xrealloc(dv->base, dv_size(dv));
- dv->base[dv->nr - 1] = add;
-}
-
-static void dirvec_destroy(struct dirvec *dv)
-{
- if (dv->base) {
- free(dv->base);
- dv->base = NULL;
- }
- dv->nr = 0;
-}
#endif /* DIRVEC_H */