Skip to content

Instantly share code, notes, and snippets.

@dotanrs
Created May 27, 2015 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotanrs/415df7711dd54eeeb2b8 to your computer and use it in GitHub Desktop.
Save dotanrs/415df7711dd54eeeb2b8 to your computer and use it in GitHub Desktop.
#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