Changeset 3803


Ignore:
Timestamp:
May 12, 2019, 7:35:25 AM (6 weeks ago)
Author:
Peter
Message:

implement wrapper function around getcwd. closes #921.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility.cc

    r3792 r3803  
    6060void test_fnmatch(test::Suite& suite);
    6161bool test_fnmatch(bool, std::string, std::string);
     62void test_getcwd(test::Suite& suite);
    6263void test_remove(test::Suite& suite);
    6364void test_rename(test::Suite& suite);
     
    236237  test_dirname(suite);
    237238  test_fnmatch(suite);
     239  test_getcwd(suite);
    238240  test_remove(suite);
    239241  test_rename(suite);
     
    760762
    761763
     764void test_getcwd(test::Suite& suite)
     765{
     766  std::string cwd = utility::getcwd();
     767  suite.out() << "cwd: " << cwd << "\n";
     768  if (cwd.find("/test/testSubDir/") == std::string::npos) {
     769    suite.add(false);
     770    suite.err() << "error: cwd: expect path to contain 'test/testSubDir/'\n";
     771  }
     772}
     773
     774
    762775void test_remove(test::Suite& suite)
    763776{
  • trunk/yat/utility/utility.cc

    r3792 r3803  
    127127    }
    128128    return false;
     129  }
     130
     131
     132  std::string getcwd(void)
     133  {
     134    char buffer[256];
     135    if (::getcwd(buffer, 256))
     136      return std::string(buffer);
     137    if (errno == ERANGE) {
     138      char buffer2[4096];
     139      if (::getcwd(buffer2, 4096))
     140        return std::string(buffer2);
     141    }
     142    throw errno_error("getcwd failed: ");
     143    return "";
    129144  }
    130145
  • trunk/yat/utility/utility.h

    r3778 r3803  
    191191  bool fnmatch(const std::string& pattern, const std::string& str,
    192192               int flags=0);
     193
     194  /**
     195     \brief current directory
     196
     197     \see ​https://linux.die.net/man/3/getcwd
     198
     199     \since New in yat 0.17
     200   */
     201  std::string getcwd(void);
    193202
    194203  /**
Note: See TracChangeset for help on using the changeset viewer.