2000-01-17 21:01:30 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
#include <cerrno>
|
2000-01-17 21:01:30 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
inline
|
2000-11-08 09:39:46 +00:00
|
|
|
char * l_getcwd(char * buffer, size_t size)
|
2000-01-17 21:01:30 +00:00
|
|
|
{
|
|
|
|
#ifndef __EMX__
|
|
|
|
return ::getcwd(buffer, size);
|
|
|
|
#else
|
|
|
|
return ::_getcwd2(buffer, size);
|
|
|
|
#endif
|
|
|
|
}
|
2000-11-08 09:39:46 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
|
|
|
|
// Returns current working directory
|
|
|
|
string const lyx::getcwd()
|
|
|
|
{
|
2002-03-21 17:09:55 +00:00
|
|
|
int n = 256; // Assume path is less than 256 chars
|
2000-11-08 09:39:46 +00:00
|
|
|
char * err;
|
2002-03-21 17:09:55 +00:00
|
|
|
char * tbuf = new char[n];
|
|
|
|
|
|
|
|
// Safe. Hopefully all getcwds behave this way!
|
|
|
|
while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) {
|
2000-11-08 09:39:46 +00:00
|
|
|
// Buffer too small, double the buffersize and try again
|
2002-03-21 17:09:55 +00:00
|
|
|
delete[] tbuf;
|
|
|
|
n = 2 * n;
|
|
|
|
tbuf = new char[n];
|
|
|
|
}
|
2000-11-08 09:39:46 +00:00
|
|
|
|
|
|
|
string result;
|
|
|
|
if (err) result = tbuf;
|
|
|
|
delete[] tbuf;
|
|
|
|
return result;
|
|
|
|
}
|