From 3f8576a6abedfa7c16d6f13dbdbabaa695cf60bb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 3 Oct 2014 22:37:51 +0200 Subject: Remove some duplicate code --- src/libutil/util.cc | 10 ++++++++++ src/libutil/util.hh | 2 ++ 2 files changed, 12 insertions(+) (limited to 'src/libutil') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 436580651dd0..99d2b1e0adce 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -227,6 +227,16 @@ DirEntries readDirectory(const Path & path) } +unsigned char getFileType(const Path & path) +{ + struct stat st = lstat(path); + if (S_ISDIR(st.st_mode)) return DT_DIR; + if (S_ISLNK(st.st_mode)) return DT_LNK; + if (S_ISREG(st.st_mode)) return DT_REG; + return DT_UNKNOWN; +} + + string readFile(int fd) { struct stat st; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 4f9f7422c09f..b35e02dceb60 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -77,6 +77,8 @@ typedef vector DirEntries; DirEntries readDirectory(const Path & path); +unsigned char getFileType(const Path & path); + /* Read the contents of a file into a string. */ string readFile(int fd); string readFile(const Path & path, bool drain = false); -- cgit 1.4.1