X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsupport%2Fgetcwd.C;h=47d67fa2743a86f1068c8cd9b5ac2f7f185b7171;hb=342cdf432246110db37bee4e0aebb4b72c933ddb;hp=305c8107b9bd5ad74ede6259549c92dc9457879b;hpb=9fe2fd47ea5e09eb70069fd6efd943ae843a3025;p=lyx.git diff --git a/src/support/getcwd.C b/src/support/getcwd.C index 305c8107b9..47d67fa274 100644 --- a/src/support/getcwd.C +++ b/src/support/getcwd.C @@ -3,17 +3,26 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include +#include "support/lyxlib.h" + +#include + #include -#include +#ifdef HAVE_UNISTD_H +# include +#endif + +using boost::scoped_array; + +using std::string; -#include "support/lyxlib.h" namespace { @@ -31,22 +40,21 @@ char * l_getcwd(char * buffer, size_t size) // Returns current working directory -string const lyx::getcwd() +string const lyx::support::getcwd() { int n = 256; // Assume path is less than 256 chars char * err; - char * tbuf = new char[n]; + scoped_array tbuf(new char[n]); // Safe. Hopefully all getcwds behave this way! - while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) { + while (((err = l_getcwd(tbuf.get(), n)) == 0) && (errno == ERANGE)) { // Buffer too small, double the buffersize and try again - delete[] tbuf; - n = 2 * n; - tbuf = new char[n]; + n *= 2; + tbuf.reset(new char[n]); } string result; - if (err) result = tbuf; - delete[] tbuf; + if (err) + result = tbuf.get(); return result; }