Changeset 482 for trunk/lib/utility.cc


Ignore:
Timestamp:
Oct 13, 2007, 3:40:38 AM (14 years ago)
Author:
Peter Johansson
Message:

fixes #79 and #5. Only updating changed files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.cc

    r465 r482  
    2424#include "utility.h"
    2525
     26#include <cerrno>
    2627#include <cstdlib>
    2728#include <fstream>
     
    7980
    8081
     82  std::string directory_name(std::string path)
     83  {
     84    size_t pos = path.find_last_of("/");
     85    if (pos==path.size()-1)
     86      return directory_name(path.substr(0,path.size()-2));
     87    return path.substr(0,pos+1);
     88  }
     89
     90
    8191  std::string file_name(const std::string& full_path)
    8292  {
     
    140150  }
    141151
     152  void mkdir(const std::string& dir)
     153  {
     154    int code = ::mkdir(dir.c_str(),0777);
     155    if (code){
     156      std::stringstream ss;
     157      ss << "mkdir(" << dir << "): failed with error code: errno=" << errno;
     158      throw std::runtime_error(ss.str());
     159    }
     160  }
     161
     162
     163  bool node_exist(const std::string& path)
     164  {
     165    struct stat buf;
     166    return !stat(path.c_str(),&buf);
     167  }
     168
    142169
    143170  int percent(int a, int b)
     
    146173      return (100*a)/b;
    147174    return 0;
    148   }
    149 
    150 
    151   bool node_exist(const std::string& path)
    152   {
    153     struct stat buf;
    154     return !stat(path.c_str(),&buf);
    155175  }
    156176
Note: See TracChangeset for help on using the changeset viewer.