2 * Copyright (C) 2010-2014 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #define _LARGEFILE_SOURCE 1
30 static char *path_append(const char *dir, const char *path)
34 result = malloc(strlen(dir) + 1 + strlen(path) + 1);
43 static char **paths_add(char **paths, int n, char *path)
47 result = malloc((n+1) * sizeof(void *));
49 memcpy(result + 1, paths, n * sizeof(void *));
56 char **dir_list(const char *dpath, int (*filter) (const char *))
60 char **paths, *path, *name, **tmp;
69 paths = malloc(sizeof(void *));
72 while ((ent = readdir(dir)) != NULL) {
75 if (!strcmp(name, ".") || !strcmp(name, ".."))
78 path = path_append(dpath, name);
80 if (!filter || filter(path)) {
81 tmp = paths_add(paths, n, path);
96 void paths_free(char **paths)