Created
May 27, 2015 18:13
-
-
Save dotanrs/415df7711dd54eeeb2b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <vector> | |
/** check if name names a valid path | |
* | |
*/ | |
inline bool path_exists(const std::string& name) { | |
struct stat buffer; | |
return (stat (name.c_str(), &buffer) == 0); | |
} | |
/** check if the string s is a positive | |
* integer | |
*/ | |
bool is_positive_number(const std::string& s) | |
{ | |
if (!s.empty() && std::find_if(s.begin(), | |
s.end(), [](char c) { return !std::isdigit(c); }) == s.end()) { | |
return (std::stoi(s) > 0); | |
} | |
return false; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
std::cout << argc << "\t" << !is_positive_number(argv[3]) << std::endl; | |
if (argc != 5 || !is_positive_number(argv[3]) || !is_positive_number(argv[4]) || | |
!path_exists(argv[1] + 1) || !path_exists(argv[2] + 1)) { | |
std::cout << "usage: CachingFileSystem rootdir mountdir numberOfBlocks blockSize\n"; | |
return FUNC_FAIL; | |
} | |
NumOfBlocks = std::stoi(argv[3]); // TODO: make extern | |
BlockSize = std::stoi(argv[4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment