lyx_mirror/src/support/getcwd.C
Georg Baum 479abc6efd Remove remaining OS/2 bits:
* src/lyx_cb.C
	(newFile): Remove OS/2 code

	* src/lyxserver.C
	(LyXComm::startPipe): ditto
	(LyXComm::endPipe): ditto
	(LyXComm::send): ditto

	* src/support/rename.C
	(lyx::support::rename): ditto

	* src/support/filetools.C
	(fileOpenSearch): ditto
	(createTmpDir): ditto
	(createLyXTmpDir): ditto
	(makeAbsPath): ditto

	* src/support/getcwd.C
	(l_getcwd): ditto

	* src/support/forkedcall.C
	(Forkedcall::generateChild): ditto

	* src/support/chdir.C
	(lyx::support::chdir): ditto

	* src/support/os.C: ditto
	* configure.ac: ditto
	* development/scons/scons_utils.py: ditto
	* development/Win32/config.h: ditto

	* lyx.man: Remove OS/2 related stuff
	* lib/doc/Customization.lyx: ditto
	* lib/doc/fr_Customization.lyx: ditto
	* lib/doc/it_Customization.lyx: ditto

	* src/support/os2_defines.h: Remove
	* src/support/os2_errortable.h: ditto
	* src/support/os_os2.C: ditto
	* INSTALL.OS2: ditto
	* README.OS2: ditto
	* development/OS2/quick_fix.patch: ditto
	* development/OS2/gnugettext.diff: ditto
	* development/OS2: ditto

	* src/support/Makefile.am: Remove deleted files
	* development/Makefile.am: Remove deleted OS2 directory


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13848 a592a061-630c-0410-9148-cb99ea01b6c8
2006-05-14 17:00:53 +00:00

66 lines
1.1 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 <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 {
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
string const lyx::support::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 result;
}