Changeset 1627 for trunk/yat


Ignore:
Timestamp:
Nov 17, 2008, 2:27:46 AM (12 years ago)
Author:
Peter
Message:

adding a function FileUtil::lexists that uses lstat rather than stat.

Location:
trunk/yat/utility
Files:
2 edited

Legend:

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

    r1487 r1627  
    9090  {
    9191    struct stat statt;
    92     if ( stat(path_.c_str(),&statt) && (errno!=ENOENT) ) {
     92    return exists_common(stat(path_.c_str(),&statt));
     93  }
     94
     95
     96  bool FileUtil::exists_common(bool failed) const
     97  {
     98    if ( failed && (errno!=ENOENT) ) {
    9399      std::stringstream ss;
    94100      ss << "stat(2) call failed with errno: " << errno;
     
    103109
    104110
     111  bool FileUtil::lexists(void) const
     112  {
     113    struct stat statt;
     114    return exists_common(lstat(path_.c_str(),&statt));
     115  }
     116
     117
    105118  const std::string& FileUtil::path(void) const
    106119  {
  • trunk/yat/utility/FileUtil.h

    r1487 r1627  
    8888    bool exists(void) const;
    8989
     90    /**
     91       Same as exists(void) but uses \a lstat rather than \a
     92       stat. That implies that the function will return true also if
     93       \a path is a broken link.
     94
     95       \return true if file exists
     96
     97       \see lstat(2)
     98       
     99       \since New in yat 0.5
     100     */
     101    bool lexists(void) const;
     102
    90103    ///
    91104    /// \brief Get path associated with the object.
     
    98111    ///
    99112    FileUtil(const FileUtil&);
     113    FileUtil& operator=(const FileUtil&);
     114
     115    bool exists_common(bool) const;
    100116
    101117    std::string path_;
Note: See TracChangeset for help on using the changeset viewer.