#include <sys/mkdev.h>
#endif
+#include "ext2_fs.h"
+#include "ext2fs.h"
+
struct dir_list {
char *name;
struct dir_list *next;
/*
* This function adds an entry to the directory list
*/
-static void add_to_dirlist(char *name, struct dir_list **list)
+static void add_to_dirlist(const char *name, struct dir_list **list)
{
struct dir_list *dp;
goto skip_to_next;
if (dp->d_name[0] == '.' &&
((dp->d_name[1] == 0) ||
- (dp->d_name[1] == '.') && (dp->d_name[2] == 0)))
+ ((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
goto skip_to_next;
sprintf(path, "%s/%s", dirname, dp->d_name);
if (stat(path, &st) < 0)
add_to_dirlist(path, list);
if (S_ISBLK(st.st_mode) && st.st_rdev == device) {
cp = malloc(strlen(path)+1);
- if (!cp)
+ if (!cp) {
+ closedir(dir);
return ENOMEM;
+ }
strcpy(cp, path);
*ret_path = cp;
- return 0;
+ goto success;
}
skip_to_next:
dp = readdir(dir);
}
+success:
closedir(dir);
return 0;
}
new_list = 0;
}
}
-found_it:
free_dirlist(&list);
free_dirlist(&new_list);
return ret_path;