X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Freaddir.c;h=b8f5fea80f898045ce28c6685a90345e007af8ff;hb=8bc6e9d6a89672bbe1e7469774abe889354deb67;hp=cea6fdd45c08351735f011f160e1e1a3747627d2;hpb=5186251f8f681f2ebb028423bb49a748861fd11e;p=libguestfs.git diff --git a/daemon/readdir.c b/daemon/readdir.c index cea6fdd..b8f5fea 100644 --- a/daemon/readdir.c +++ b/daemon/readdir.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -28,7 +28,7 @@ #include "actions.h" guestfs_int_dirent_list * -do_readdir (char *path) +do_readdir (const char *path) { guestfs_int_dirent_list *ret; guestfs_int_dirent v; @@ -36,9 +36,6 @@ do_readdir (char *path) struct dirent *d; int i; - NEED_ROOT (NULL); - ABS_PATH (path, NULL); - ret = malloc (sizeof *ret); if (ret == NULL) { reply_with_perror ("malloc"); @@ -63,11 +60,13 @@ do_readdir (char *path) guestfs_int_dirent *p; p = realloc (ret->guestfs_int_dirent_list_val, - sizeof (guestfs_int_dirent) * (i+1)); + sizeof (guestfs_int_dirent) * (i+1)); v.name = strdup (d->d_name); if (!p || !v.name) { reply_with_perror ("allocate"); free (ret->guestfs_int_dirent_list_val); + free (p); + free (v.name); free (ret); closedir (dir); return NULL; @@ -75,6 +74,7 @@ do_readdir (char *path) ret->guestfs_int_dirent_list_val = p; v.ino = d->d_ino; +#ifdef HAVE_STRUCT_DIRENT_D_TYPE switch (d->d_type) { case DT_BLK: v.ftyp = 'b'; break; case DT_CHR: v.ftyp = 'c'; break; @@ -86,6 +86,9 @@ do_readdir (char *path) case DT_UNKNOWN: v.ftyp = 'u'; break; default: v.ftyp = '?'; break; } +#else + v.ftyp = 'u'; +#endif ret->guestfs_int_dirent_list_val[i] = v;