lyx_mirror/src/support/getcwd.C
Georg Baum 77b9dbd557 Fix several filename and environment variable encoding problems
* src/LaTeX.C
	(LaTeX::deplog): Assume that filenames in log files are stored in
	the file system encoding

	* src/frontends/qt4/qt_helpers.[Ch]
	(internal_path): delete

	* src/frontends/qt4/QGraphics.C: Adjust to change above

	* src/frontends/qt4/QPrefsDialog.C: ditto

	* src/frontends/qt4/QExternal.C: ditto

	* src/frontends/qt4/QInclude.C: ditto

	* src/support/os.h: Document the encoding of filename arguments

	* src/support/os_win32.h: ditto

	* src/support/filetools.C
	(findtexfile): Convert filename from file system encoding

	* src/support/os_win32.C: Convert filenames from utf8 to file system
	encoding and vice versa where needed

	* src/support/os_cygwin.C: ditto

	* src/support/getcwd.C
	(getcwd): Use internal_path() with correct encoding

	* src/support/docstring.[Ch]
	(from_filesystem8bit): new conversion function

	* src/support/environment.C
	(getEnv): convert environment variable from local 8bit encoding to utf8
	(setEnv): convert environment variable from utf8 to local 8bit encoding

	* src/support/environment.h: document encoding of function arguments


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16753 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-18 20:47:27 +00:00

74 lines
1.3 KiB
C

/**
* \file getcwd.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "support/lyxlib.h"
#include "support/os.h"
#include <boost/scoped_array.hpp>
#include <cerrno>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef _WIN32
# include <windows.h>
#endif
using boost::scoped_array;
using std::string;
namespace lyx {
namespace support {
namespace {
inline
char * l_getcwd(char * buffer, size_t size)
{
#ifdef _WIN32
GetCurrentDirectory(size, buffer);
return buffer;
#else
return ::getcwd(buffer, size);
#endif
}
} // namespace anon
// Returns current working directory
FileName const getcwd()
{
int n = 256; // Assume path is less than 256 chars
char * err;
scoped_array<char> tbuf(new char[n]);
// Safe. Hopefully all getcwds behave this way!
while (((err = l_getcwd(tbuf.get(), n)) == 0) && (errno == ERANGE)) {
// Buffer too small, double the buffersize and try again
n *= 2;
tbuf.reset(new char[n]);
}
string result;
if (err)
result = tbuf.get();
return FileName(os::internal_path(to_utf8(from_filesystem8bit(result))));
}
} // namespace support
} // namespace lyx