diff options
author | Nullspoon <nullspoon@iohq.net> | 2014-09-05 15:22:33 -0600 |
---|---|---|
committer | Nullspoon <nullspoon@iohq.net> | 2014-09-05 15:22:33 -0600 |
commit | 5d4f925ad75ba8e441ab5ebefacdcb6673d413b3 (patch) | |
tree | c40b49686305205dcc70b34994702b4d9bd7d25b | |
parent | c36cfcc7dcf53d8aed550b62f02690bd7223b669 (diff) | |
download | noteless-5d4f925ad75ba8e441ab5ebefacdcb6673d413b3.tar.gz noteless-5d4f925ad75ba8e441ab5ebefacdcb6673d413b3.tar.xz |
Implemented path::is_dir and other misc path stuff
Path::is_dir simply returns 1 or 0 as to whether the complete path instance
ends in a directory.
Wrote placeholder for path::append. Just returns 1 for now.
Moved delim variable from constructor into a public class level so other
methods could share (be nice!)
-rw-r--r-- | src/lib/path.cpp | 37 | ||||
-rw-r--r-- | src/lib/path.h | 3 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/path.cpp b/src/lib/path.cpp index 54d21f7..c7efc40 100644 --- a/src/lib/path.cpp +++ b/src/lib/path.cpp @@ -24,7 +24,7 @@ path::path( string p ) { long cur_dir_begin = 0; // Setting this to a variable so we can handle Windows in the future - char delim = '/'; + delim = '/'; // Set the path type ( [r]elative or [a]bsolute ) based on the first char in // the path. @@ -96,6 +96,41 @@ bool path::exists() { return true; } +/** + * Detects if the instance is a directory + * + * @return int Directory or not + */ +int path::is_dir() { + int dir_sig = 0x41ed; + // Not needed since this is an else, but good information to have handy + // int file_sig = 0x81a4; + + // Stat the item + struct stat sb; + stat( value.c_str(), &sb ); + // Check if it's a file or a dir + if( sb.st_mode == dir_sig ) { + // Is dir + return 1; + } + // Is a file [or something else] + return 0; +} + +/** + * Appends the given directory(s) to the path instance. + * TODO + * + * @param const char* path Path to be appended + * + * @return int Error (1) or not (0) + */ +int path::append(string path) { + return 1; +} + + string path::out() { return value; } diff --git a/src/lib/path.h b/src/lib/path.h index 79f2baa..4b115d8 100644 --- a/src/lib/path.h +++ b/src/lib/path.h @@ -29,12 +29,15 @@ class path { string value; string filename; char type; + char delim; vector<string> dirs; path(); path( string ); bool exists(); int create(); + int is_dir(); + int append(string); string out(); }; |