Ignore:
Timestamp:
Dec 20, 2006, 10:49:02 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Addresses #1 and #80. Issues fixed, but bogus params to functions exists. cleanup needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/FileIO.cc

    r687 r709  
    2626#include "FileIO.h"
    2727
     28#include <cerrno>
    2829#include <iostream>
     30#include <string>
     31
     32#include <sys/stat.h>
    2933#include <unistd.h>
    3034
     
    3438namespace utility {
    3539
     40
     41  FileIO::FileIO(const std::string& path)
     42    : no_file_(false), path_(path)
     43  {
     44    if ( stat(path_.c_str(),&stat_) && !(no_file_=(errno==ENOENT)) )
     45        throw IO_error(std::string("stat(2) call failed with errno: "+errno));
     46  }
     47
     48
    3649  int FileIO::access_rights(const std::string& path,
    37                             const std::string& bits) const {
    38     if (int value=access(path.c_str(),F_OK)) {
    39       std::cerr << "access_rights: File '" << path << "' does not exist."
    40                 << std::endl;
    41       return value;
     50                            const std::string& bits) const
     51  {
     52    std::string tryme=path_;
     53    if (no_file_) {
     54      std::string::size_type pos=path_.find_last_of('/');
     55      tryme = ( (pos!=std::string::npos) ? path_.substr(0,pos) : "." );
    4256    }
     57
    4358    int mode=0;
    4459    for (u_int i=0; i<bits.length(); i++)
     
    5469            break;
    5570      }
    56     return access(path.c_str(),mode);
     71
     72    return access(tryme.c_str(),mode);
     73  }
     74
     75
     76  bool FileIO::file_exists(const std::string& file) const
     77  {
     78    return !no_file_;
     79  }
     80
     81
     82  const std::string& FileIO::path(void) const
     83  {
     84    return path_;
    5785  }
    5886
Note: See TracChangeset for help on using the changeset viewer.