summaryrefslogtreecommitdiffstats
path: root/path.c
diff options
context:
space:
mode:
authorAurelien Jarno2011-02-09 19:53:36 +0100
committerAurelien Jarno2011-02-09 19:53:36 +0100
commit1c0de9fa509c48aeeb6ef2465307d603abc9ee4e (patch)
tree69353b33fdb34e4acb5fc081d2e14bacef37cd4c /path.c
parenttarget-arm: implement vsli.64, vsri.64 (diff)
parentlinux-user: fix for loopmount ioctl (diff)
downloadqemu-1c0de9fa509c48aeeb6ef2465307d603abc9ee4e.tar.gz
qemu-1c0de9fa509c48aeeb6ef2465307d603abc9ee4e.tar.xz
qemu-1c0de9fa509c48aeeb6ef2465307d603abc9ee4e.zip
Merge branch 'linux-user-for-upstream' of git://gitorious.org/qemu-maemo/qemu
* 'linux-user-for-upstream' of git://gitorious.org/qemu-maemo/qemu: linux-user: fix for loopmount ioctl linux-user: fix build errors for mmap2-only ports user: speed up init_paths a bit linux-user: implement sched_{g,s}etaffinity linux-user/FLAT: allow targets to override FLAT processing linux-user/FLAT: fix auto-stack sizing linux-user: decode MAP_{UNINITIALIZED,EXECUTABLE} in strace linux-user: add ppoll syscall support linux-user/elfload: add FDPIC support linux-user: fix sizeof handling for getsockopt linux-user: Fix possible realloc memory leak linux-user: Add support for -version option
Diffstat (limited to 'path.c')
-rw-r--r--path.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/path.c b/path.c
index 0d2bf149e4..ef3f277f17 100644
--- a/path.c
+++ b/path.c
@@ -38,7 +38,8 @@ static int strneq(const char *s1, unsigned int n, const char *s2)
return s2[i] == 0;
}
-static struct pathelem *add_entry(struct pathelem *root, const char *name);
+static struct pathelem *add_entry(struct pathelem *root, const char *name,
+ unsigned char type);
static struct pathelem *new_entry(const char *root,
struct pathelem *parent,
@@ -56,6 +57,15 @@ static struct pathelem *new_entry(const char *root,
#define streq(a,b) (strcmp((a), (b)) == 0)
+/* Not all systems provide this feature */
+#if defined(DT_DIR) && defined(DT_UNKNOWN)
+# define dirent_type(dirent) ((dirent)->d_type)
+# define is_dir_maybe(type) ((type) == DT_DIR || (type) == DT_UNKNOWN)
+#else
+# define dirent_type(dirent) (1)
+# define is_dir_maybe(type) (type)
+#endif
+
static struct pathelem *add_dir_maybe(struct pathelem *path)
{
DIR *dir;
@@ -65,7 +75,7 @@ static struct pathelem *add_dir_maybe(struct pathelem *path)
while ((dirent = readdir(dir)) != NULL) {
if (!streq(dirent->d_name,".") && !streq(dirent->d_name,"..")){
- path = add_entry(path, dirent->d_name);
+ path = add_entry(path, dirent->d_name, dirent_type(dirent));
}
}
closedir(dir);
@@ -73,16 +83,22 @@ static struct pathelem *add_dir_maybe(struct pathelem *path)
return path;
}
-static struct pathelem *add_entry(struct pathelem *root, const char *name)
+static struct pathelem *add_entry(struct pathelem *root, const char *name,
+ unsigned char type)
{
+ struct pathelem **e;
+
root->num_entries++;
root = realloc(root, sizeof(*root)
+ sizeof(root->entries[0])*root->num_entries);
+ e = &root->entries[root->num_entries-1];
+
+ *e = new_entry(root->pathname, root, name);
+ if (is_dir_maybe(type)) {
+ *e = add_dir_maybe(*e);
+ }
- root->entries[root->num_entries-1] = new_entry(root->pathname, root, name);
- root->entries[root->num_entries-1]
- = add_dir_maybe(root->entries[root->num_entries-1]);
return root;
}