#include <talloc.h>
-#include <glib.h> /* g_strdup_printf */
-
#define unused(x) x __attribute__ ((unused))
/* There's no point in continuing when we've detected that we've done
continue;
}
- next = g_strdup_printf ("%s/%s", path, entry->d_name);
+ next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
if (stat (next, st)) {
fprintf (stderr, "Error reading %s: %s\n",
ret = status;
}
- free (next);
+ talloc_free (next);
next = NULL;
}
DONE:
if (next)
- free (next);
+ talloc_free (next);
if (entry)
free (entry);
if (dir)
count_files (const char *path, int *count)
{
DIR *dir;
- struct dirent *entry, *e;
+ struct dirent *e, *entry = NULL;
int entry_length;
int err;
char *next;
if (dir == NULL) {
fprintf (stderr, "Warning: failed to open directory %s: %s\n",
path, strerror (errno));
- return;
+ goto DONE;
}
entry_length = offsetof (struct dirent, d_name) +
fprintf (stderr, "Error reading directory: %s\n",
strerror (errno));
free (entry);
- return;
+ goto DONE;
}
if (e == NULL)
continue;
}
- next = g_strdup_printf ("%s/%s", path, entry->d_name);
+ if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
+ next = NULL;
+ fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
+ path, entry->d_name);
+ continue;
+ }
stat (next, &st);
free (next);
}
- free (entry);
+ DONE:
+ if (entry)
+ free (entry);
closedir (dir);
}