Changeset 2907


Ignore:
Timestamp:
Dec 15, 2012, 8:48:48 AM (9 years ago)
Author:
Peter
Message:

extend intererface with mode_t as in C api and improve docs. refs #717

Location:
trunk/yat/utility
Files:
2 edited

Legend:

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

    r2906 r2907  
    113113
    114114
    115   bool fnmatch(const std::string& pattern, const std::string& str)
     115  bool fnmatch(const std::string& pattern, const std::string& str, int flags)
    116116  {
    117     int res = ::fnmatch(pattern.c_str(), str.c_str(), 0);
     117    int res = ::fnmatch(pattern.c_str(), str.c_str(), flags);
    118118    if (res==0)
    119119      return true;
     
    165165
    166166
    167   void mkdir(const std::string& dir)
     167  void mkdir(const std::string& dir, mode_t mode)
    168168  {
    169     int code = ::mkdir(dir.c_str(),0777);
     169    int code = ::mkdir(dir.c_str(), mode);
    170170    if (code){
    171171      std::stringstream ss;
     
    176176
    177177
    178   void mkdir_p(const std::string& dir)
     178  void mkdir_p(const std::string& dir, mode_t mode)
    179179  {
    180180    if (FileUtil(dir).exists())
    181181      return;
    182     mkdir_p(dirname(dir));
    183     mkdir(dir);
     182    mkdir_p(dirname(dir), mode);
     183    mkdir(dir, mode);
    184184  }
    185185
  • trunk/yat/utility/utility.h

    r2906 r2907  
    5656
    5757  /**
     58     Same as posix C function with same name but works on \c
     59     std::string rather than \c char*.
     60
     61     \see http://linux.die.net/man/3/basename
     62
    5863     \return everything after last '/'
    5964
     
    7378  */
    7479  template<typename InputIterator, typename OutputIterator>
    75   bool binary_weight(InputIterator first, InputIterator last, 
     80  bool binary_weight(InputIterator first, InputIterator last,
    7681                     OutputIterator result);
    7782
    7883  /**
    79      wrapper around GNU C Library function chdir
    80 
    81      \throw if underlying chdir call does not return 0
     84     Same as C function \c chdir but throws on failure (instead of
     85     retrning non-zero).
     86
     87     \throw runtime_error if underlying chdir returns non-zero
     88
     89     \see http://linux.die.net/man/3/chdir
    8290
    8391     \since New in yat 0.10
     
    8694
    8795  /**
     96     same as C function \c chmod but throws on failure (instead of
     97     returning non-zero).
     98
     99     \see http://linux.die.net/man/3/chmod
     100
    88101     \since New in yat 0.10
    89102   */
     
    111124     @brief Copy file \a source to \a target.
    112125
    113      @throw std::runtime_error when read error of \a source or write
    114      error for \a target is encountered.
     126     @throw runtime_error if read error of \a source or write error
     127     for \a target is encountered.
    115128  */
    116129  void copy_file(const std::string& source, const std::string& target);
    117130
    118131  /**
     132     Same as posix C function with same name but works on \c
     133     std::string rather than \c char*.
     134
     135     \see http://linux.die.net/man/3/dirname
     136
    119137     \return everything prior last '/'.
    120138
     
    130148     \since New in yat 0.10
    131149  */
    132   bool fnmatch(const std::string& pattern, const std::string& str);
     150  bool fnmatch(const std::string& pattern, const std::string& str,
     151               int flags=0);
    133152
    134153  /**
     
    309328
    310329  /**
    311      create a directory \a dir
     330     \brief create a directory \a dir
     331
     332     \see http://linux.die.net/man/3/mkdir
    312333
    313334     \throw if creation failed
    314335   */
    315   void mkdir(const std::string& dir);
    316 
    317   /**
    318      Similar to 'mkdir -p'. Does not throw on error and create parent
    319      directories if missing.
    320    */
    321   void mkdir_p(const std::string& dir);
     336  void mkdir(const std::string& dir, mode_t mode=0777);
     337
     338  /**
     339     Similar to mkdir(const std::string&, mode_t).
     340
     341     No error if \a dir already exist. Make parent directories as needed.
     342   */
     343  void mkdir_p(const std::string& dir, mode_t mode=0777);
    322344
    323345  /**
    324346     same as C function remove but throws errno_error at failure
    325347
    326      \see man remove
     348     \see http://linux.die.net/man/3/remove
    327349   */
    328350  void remove(const std::string& fn);
    329351
    330352  /**
    331      same as rename(2) but throws errno_error if error is encountered
    332 
    333      \see man rename
     353     same as C function with same name but throws errno_error if error
     354     is encountered
     355
     356     \see http://linux.die.net/man/3/rename
    334357
    335358     \since New in yat 0.10
Note: See TracChangeset for help on using the changeset viewer.