mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-12 19:38:18 +00:00
fc8465aa1f
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1795 a592a061-630c-0410-9148-cb99ea01b6c8
43 lines
764 B
C
43 lines
764 B
C
#include <config.h>
|
|
|
|
#include <cerrno>
|
|
#include <unistd.h>
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
namespace {
|
|
|
|
inline
|
|
char * l_getcwd(char * buffer, size_t size)
|
|
{
|
|
#ifndef __EMX__
|
|
return ::getcwd(buffer, size);
|
|
#else
|
|
return ::_getcwd2(buffer, size);
|
|
#endif
|
|
}
|
|
|
|
} // namespace anon
|
|
|
|
|
|
// Returns current working directory
|
|
string const lyx::getcwd()
|
|
{
|
|
int n = 256; // Assume path is less than 256 chars
|
|
char * err;
|
|
char * tbuf = new char[n];
|
|
|
|
// Safe. Hopefully all getcwds behave this way!
|
|
while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) {
|
|
// Buffer too small, double the buffersize and try again
|
|
delete[] tbuf;
|
|
n = 2 * n;
|
|
tbuf = new char[n];
|
|
}
|
|
|
|
string result;
|
|
if (err) result = tbuf;
|
|
delete[] tbuf;
|
|
return result;
|
|
}
|