The thing is, when wrapping a library function in another function you have to assume that all the functionality should be exposed, because a library does not know what will be calling it. Throw std::runtime_error("Insufficient storage") I'm not sure whether this can happen or not Throw std::runtime_error("Access denied") PATH_MAX includes the terminating nul, EINVAL can't happen - size argument > 0 Let's try and rewrite this simple C call as C++: std::string get_working_path() ![]() Update (2017): The filesystem library has been merged with ISO C++ in C++17, for std::filesystem::current_path() To me it also seems likely that it will become part of a future C++ standard (I would assume C++17, but I am not aware of the current status). This means that it may be available with your compiler already (for instance Visual Studio 2015). ![]() Update (2016): Filesystem has been published as a technical specification in 2015, based on Boost Filesystem v3. Check it out, it is portable as well - which a lot of the string parsing code one would otherwise use likely won't be. The Boost filesystem library allows you to do lots of other useful stuff that you would otherwise need to do a lot of string parsing to do, like checking if files/directories exist, get parent path, make paths complete etcetera. ![]() Ok, I'm answering even though you already have accepted an answer.Īn even better way than to wrap the getcwd call would be to use boost::filesystem, where you get a path object from the current_path() function.
0 Comments
Leave a Reply. |