aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-03 22:37:51 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-03 22:37:51 +0200
commit3f8576a6abedfa7c16d6f13dbdbabaa695cf60bb (patch)
treee1aad65d6748f23229b06768d61c21401de2a98f /src/libutil
parentc08c802bf31ce739e0de6d1fbfe4d58b808ae9bb (diff)
Remove some duplicate code
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc10
-rw-r--r--src/libutil/util.hh2
2 files changed, 12 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 436580651..99d2b1e0a 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 4f9f7422c..b35e02dce 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -77,6 +77,8 @@ typedef vector<DirEntry> 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);