add path_isdir()
This commit is contained in:
parent
974dfae991
commit
07d4d26e61
@ -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<std::string> 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);
|
||||
|
||||
@ -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 <string>
|
||||
#include <list>
|
||||
|
||||
#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<std::string> path_dirglob(const std::string &dir,
|
||||
const std::string pattern);
|
||||
extern list<string> 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_ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user