source: trunk/lib/utility.cc @ 177

Last change on this file since 177 was 177, checked in by Peter Johansson, 15 years ago

moved html related utility to its own 'html_utility'

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: utility.cc 177 2006-09-02 04:30:57Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "utility.h"
25
26#include <fstream>
27#include <iostream> // remove this when 'blame' is removed
28#include <sstream>
29#include <stdexcept>
30#include <string>
31#include <sys/param.h>
32#include <unistd.h>
33
34namespace theplu{
35namespace svndigest{
36
37  int access_rights(const std::string& path, const std::string& bits)
38  {
39    if (access(path.c_str(),F_OK)) {
40      throw std::runtime_error(std::string("access_rights: ") + path +
41                               "' does not exist.");
42    }
43    int mode=0;
44    for (u_int i=0; i<bits.length(); ++i)
45      switch (bits[i]) {
46          case 'r':
47            mode|=R_OK;
48            break;
49          case 'w':
50            mode|=W_OK;
51            break;
52          case 'x':
53            mode|=X_OK;
54            break;
55      }
56    return access(path.c_str(),mode);
57  }
58
59
60  std::string file_name(const std::string& full_path)
61  {
62    std::stringstream ss(full_path);
63    std::string name;
64    while (getline(ss,name,'/')) {}
65    return name;
66  }
67
68
69  std::string pwd(void)
70  {
71    char buffer[MAXPATHLEN];
72    if (!getcwd(buffer, MAXPATHLEN))
73      throw std::runtime_error("Failed to get current working directory");
74    return std::string(buffer);
75  }
76
77}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.