Replace mh_xmalloc() with mh_xcalloc()
[mmh] / sbr / crawl_folders.c
index 0185bd8..2e1a094 100644 (file)
@@ -9,11 +9,13 @@
 #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;    /*
-                   ** 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 */
@@ -29,7 +31,7 @@ struct crawl_context {
 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) {
@@ -140,10 +142,10 @@ crawl_folders_body(struct crawl_context *crawl, char *dir,
 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->folders = mh_xmalloc(crawl->max * sizeof(*crawl->folders));
+       crawl->folders = mh_xcalloc(crawl->max, sizeof(*crawl->folders));
 
        crawl_folders_body(crawl, dir, callback, baton);