X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fis.c;h=4a834f49c11d08010aee7700cef2cf88bfba232d;hp=a16596be3169ad8df648e47c1403a3b3f8d0b166;hb=43eed091129212dd29996838cf1d76af0f8fc135;hpb=3a99114360636806078bbf614c241e89661bcc7f diff --git a/daemon/is.c b/daemon/is.c index a16596b..4a834f4 100644 --- a/daemon/is.c +++ b/daemon/is.c @@ -41,30 +41,73 @@ do_exists (const char *path) return r == 0; } +static int get_mode (const char *path, mode_t *mode); + int do_is_file (const char *path) { - int r; - struct stat buf; + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISREG (mode); +} - CHROOT_IN; - r = lstat (path, &buf); - CHROOT_OUT; +int +do_is_dir (const char *path) +{ + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISDIR (mode); +} - if (r == -1) { - if (errno != ENOENT && errno != ENOTDIR) { - reply_with_perror ("stat: %s", path); - return -1; - } - else - return 0; /* Not a file. */ - } +int +do_is_chardev (const char *path) +{ + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISCHR (mode); +} - return S_ISREG (buf.st_mode); +int +do_is_blockdev (const char *path) +{ + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISBLK (mode); } int -do_is_dir (const char *path) +do_is_fifo (const char *path) +{ + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISFIFO (mode); +} + +int +do_is_symlink (const char *path) +{ + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISLNK (mode); +} + +int +do_is_socket (const char *path) +{ + mode_t mode; + int r = get_mode (path, &mode); + if (r <= 0) return r; + return S_ISSOCK (mode); +} + +static int +get_mode (const char *path, mode_t *mode) { int r; struct stat buf; @@ -79,8 +122,9 @@ do_is_dir (const char *path) return -1; } else - return 0; /* Not a directory. */ + return 0; /* Doesn't exist, means return false. */ } - return S_ISDIR (buf.st_mode); + *mode = buf.st_mode; + return 1; }