| 1057 | } |
| 1058 | |
| 1059 | BOOST_FILESYSTEM_DECL |
| 1060 | path current_path(error_code* ec) |
| 1061 | { |
| 1062 | # ifdef BOOST_POSIX_API |
| 1063 | path cur; |
| 1064 | for (long path_max = 128;; path_max *=2)// loop 'til buffer large enough |
| 1065 | { |
| 1066 | boost::scoped_array<char> |
| 1067 | buf(new char[static_cast<std::size_t>(path_max)]); |
| 1068 | if (::getcwd(buf.get(), static_cast<std::size_t>(path_max))== 0) |
| 1069 | { |
| 1070 | if (error(errno != ERANGE |
| 1071 | // bug in some versions of the Metrowerks C lib on the Mac: wrong errno set |
| 1072 | # if defined(__MSL__) && (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) |
| 1073 | && errno != 0 |
| 1074 | # endif |
| 1075 | , ec, "boost::filesystem::current_path")) |
| 1076 | { |
| 1077 | break; |
| 1078 | } |
| 1079 | } |
| 1080 | else |
| 1081 | { |
| 1082 | cur = buf.get(); |
| 1083 | if (ec != 0) ec->clear(); |
| 1084 | break; |
| 1085 | } |
| 1086 | } |
| 1087 | return cur; |
| 1088 | |
| 1089 | # else |
| 1090 | DWORD sz; |
| 1091 | if ((sz = ::GetCurrentDirectoryW(0, NULL))== 0)sz = 1; |
| 1092 | boost::scoped_array<path::value_type> buf(new path::value_type[sz]); |
| 1093 | error(::GetCurrentDirectoryW(sz, buf.get())== 0, ec, |
| 1094 | "boost::filesystem::current_path"); |
| 1095 | return path(buf.get()); |
| 1096 | # endif |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | BOOST_FILESYSTEM_DECL |