From 07d4d26e61fb3f174925e6af2e380eca0ce4be01 Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 23 Oct 2006 15:00:31 +0000 Subject: [PATCH] add path_isdir() --- src/utils/pathut.cpp | 12 +++++++++++- src/utils/pathut.h | 33 ++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index d1e28357..f0f07230 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: pathut.cpp,v 1.10 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: pathut.cpp,v 1.11 2006-10-23 15:00:31 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -189,6 +189,16 @@ list path_dirglob(const std::string &dir, return res; } +bool path_isdir(const string& path) +{ + struct stat st; + if (lstat(path.c_str(), &st) < 0) + return false; + if (S_ISDIR(st.st_mode)) + return true; + return false; +} + std::string url_encode(const std::string url, string::size_type offs) { string out = url.substr(0, offs); diff --git a/src/utils/pathut.h b/src/utils/pathut.h index 8012e9a9..173f446f 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -16,32 +16,39 @@ */ #ifndef _PATHUT_H_INCLUDED_ #define _PATHUT_H_INCLUDED_ -/* @(#$Id: pathut.h,v 1.8 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: pathut.h,v 1.9 2006-10-23 15:00:31 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include +#ifndef NO_NAMESPACES +using std::string; +using std::list; +#endif + /// Add a / at the end if none there yet. -extern void path_catslash(std::string &s); +extern void path_catslash(string &s); /// Concatenate 2 paths -extern std::string path_cat(const std::string &s1, const std::string &s2); +extern string path_cat(const string &s1, const string &s2); /// Get the simple file name (get rid of any directory path prefix -extern std::string path_getsimple(const std::string &s); +extern string path_getsimple(const string &s); /// Simple file name + optional suffix stripping -extern std::string path_basename(const std::string &s, const std::string &suff=""); +extern string path_basename(const string &s, const string &suff=""); /// Get the father directory -extern std::string path_getfather(const std::string &s); +extern string path_getfather(const string &s); /// Get the current user's home directory -extern std::string path_home(); +extern string path_home(); /// Expand ~ at the beginning of string -extern std::string path_tildexpand(const std::string &s); +extern string path_tildexpand(const string &s); /// Clean up path by removing duplicated / and resolving ../ -extern std::string path_canon(const std::string &s); +extern string path_canon(const string &s); /// Use glob(3) to return a list of file names matching pattern inside dir -extern std::list path_dirglob(const std::string &dir, - const std::string pattern); +extern list path_dirglob(const string &dir, + const string pattern); /// Encode according to rfc 1738 -extern std::string url_encode(const std::string url, - std::string::size_type offs); +extern string url_encode(const string url, + string::size_type offs); +/// Stat parameter and check if it's a directory +extern bool path_isdir(const string& path); #endif /* _PATHUT_H_INCLUDED_ */