aboutsummaryrefslogtreecommitdiffstats
path: root/path.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2011-05-09 15:59:28 +0200
committerDavid 'Digit' Turner <digit@android.com>2011-06-01 17:08:17 +0200
commit088edf82b3d34409ed9d9fd09ec1f7e9b933304f (patch)
treeb5515cf92d243d3453062a5bc975a494142442d3 /path.c
parent795bb19daea966401df15bbf23c57b98848eec23 (diff)
downloadexternal_qemu-088edf82b3d34409ed9d9fd09ec1f7e9b933304f.zip
external_qemu-088edf82b3d34409ed9d9fd09ec1f7e9b933304f.tar.gz
external_qemu-088edf82b3d34409ed9d9fd09ec1f7e9b933304f.tar.bz2
os-posix.c + os-win32.c and dependencies
+ Generate qemu-options.def instead of qemu-options.h Change-Id: I043e6b0c1c58e5cc2e96d05465f39b42f9054b5a
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 4fbc210..f0d703f 100644
--- a/path.c
+++ b/path.c
@@ -41,7 +41,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,
@@ -59,6 +60,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;
@@ -68,7 +78,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);
@@ -76,16 +86,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;
}