projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add some gcc hint defines
[mmh]
/
sbr
/
crawl_folders.c
diff --git
a/sbr/crawl_folders.c
b/sbr/crawl_folders.c
index
0693a21
..
7164616
100644
(file)
--- a/
sbr/crawl_folders.c
+++ b/
sbr/crawl_folders.c
@@
-9,11
+9,13
@@
#include <h/mh.h>
#include <h/crawl_folders.h>
#include <h/utils.h>
#include <h/mh.h>
#include <h/crawl_folders.h>
#include <h/utils.h>
+#include <dirent.h>
+#include <sys/stat.h>
struct crawl_context {
int max; /*
struct crawl_context {
int max; /*
- ** how many folders we currently can hold in the array
- ** `folders', increased by CRAWL_NUMFOLDERS at a time
+ ** number of folders we can hold in the folders array;
+ ** increased by CRAWL_NUMFOLDERS at a time
*/
int total; /* how many `folders' actually has */
char **folders; /* the array of folders */
*/
int total; /* how many `folders' actually has */
char **folders; /* the array of folders */
@@
-29,7
+31,7
@@
struct crawl_context {
static void
add_folder(char *fold, struct crawl_context *crawl)
{
static void
add_folder(char *fold, struct crawl_context *crawl)
{
- register int i, j;
+ int i, j;
/* if necessary, reallocate the space for folder names */
if (crawl->foldp >= crawl->max) {
/* if necessary, reallocate the space for folder names */
if (crawl->foldp >= crawl->max) {
@@
-66,7
+68,7
@@
add_children(char *name, struct crawl_context *crawl)
}
if (strcmp(name, ".") == 0) {
}
if (strcmp(name, ".") == 0) {
- prefix = getcpy("");
+ prefix = mh_xstrdup("");
} else {
prefix = concat(name, "/", (void *)NULL);
}
} else {
prefix = concat(name, "/", (void *)NULL);
}
@@
-84,7
+86,8
@@
add_children(char *name, struct crawl_context *crawl)
continue;
}
#endif
continue;
}
#endif
- if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
+ if (strcmp(dp->d_name, ".")==0 ||
+ strcmp(dp->d_name, "..")==0) {
continue;
}
child = concat(prefix, dp->d_name, (void *)NULL);
continue;
}
child = concat(prefix, dp->d_name, (void *)NULL);
@@
-99,12
+102,12
@@
add_children(char *name, struct crawl_context *crawl)
/* add_folder saves child in the list, don't free it */
add_folder(child, crawl);
} else {
/* add_folder saves child in the list, don't free it */
add_folder(child, crawl);
} else {
- free(child);
+ mh_free0(&child);
}
}
closedir(dd);
}
}
closedir(dd);
- free(prefix);
+ mh_free0(&prefix);
}
static void
}
static void
@@
-139,10
+142,10
@@
crawl_folders_body(struct crawl_context *crawl, char *dir,
void
crawl_folders(char *dir, crawl_callback_t *callback, void *baton)
{
void
crawl_folders(char *dir, crawl_callback_t *callback, void *baton)
{
- struct crawl_context *crawl = mh_xmalloc(sizeof(*crawl));
+ struct crawl_context *crawl = mh_xcalloc(1, sizeof(*crawl));
crawl->max = CRAWL_NUMFOLDERS;
crawl->total = crawl->start = crawl->foldp = 0;
crawl->max = CRAWL_NUMFOLDERS;
crawl->total = crawl->start = crawl->foldp = 0;
- crawl->folders = mh_xmalloc(crawl->max * sizeof(*crawl->folders));
+ crawl->folders = mh_xcalloc(crawl->max, sizeof(*crawl->folders));
crawl_folders_body(crawl, dir, callback, baton);
crawl_folders_body(crawl, dir, callback, baton);
@@
-150,6
+153,6
@@
crawl_folders(char *dir, crawl_callback_t *callback, void *baton)
** Note that we "leak" the folder names, on the assumption that the
** caller is using them.
*/
** Note that we "leak" the folder names, on the assumption that the
** caller is using them.
*/
- free(crawl->folders);
- free(crawl);
+ mh_free0(&(crawl->folders));
+ mh_free0(&crawl);
}
}