From d9b136f2a3555d666839ddf50b00e714aabf3b4c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 26 Aug 2011 22:41:08 +0200 Subject: [PATCH 1/3] sysdeps: introduce _dbus_stat_is_file() To make use of the mode value of the stat struct we need an OS-indepdendent way to check whether something is a regular file. --- dbus/dbus-sysdeps-util-unix.c | 12 ++++++++++++ dbus/dbus-sysdeps-util-win.c | 13 +++++++++++++ dbus/dbus-sysdeps.h | 1 + 3 files changed, 26 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index a80f643..f51ef7f 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -609,6 +609,18 @@ _dbus_stat (const DBusString *filename, return TRUE; } +/** + * Tests whether a buffer returned by _dbus_stat() refers to a regular + * file + * + * @param statbuf the stat info to check + * @returns #TRUE if the stat refers to a file + */ +dbus_bool_t +_dbus_stat_is_file (DBusStat *statbuf) +{ + return S_ISREG(statbuf->mode); +} /** * Internals of directory iterator diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index f5646f3..7d164b7 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -424,6 +424,19 @@ _dbus_stat(const DBusString *filename, return TRUE; } +/** + * Tests whether a buffer returned by _dbus_stat() refers to a regular + * file + * + * @param statbuf the stat info to check + * @returns #TRUE if the stat refers to a file + */ +dbus_bool_t +_dbus_stat_is_file (DBusStat *statbuf) +{ + return !!(statbuf->mode & _S_IFMT) == _S_IFREG; +} + /* This file is part of the KDE project Copyright (C) 2000 Werner Almesberger diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index f66efaa..65434f2 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -394,6 +394,7 @@ typedef struct dbus_bool_t _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error); +dbus_bool_t _dbus_stat_is_file (DBusStat *statbuf); dbus_bool_t _dbus_full_duplex_pipe (int *fd1, int *fd2, dbus_bool_t blocking, -- 1.7.6