]> git.lyx.org Git - lyx.git/blob - src/support/getcwd.C
split LyXText::rowlist_ into individual Paragraph::rows_ chunks
[lyx.git] / src / support / getcwd.C
1 /**
2  * \file getcwd.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include <cerrno>
14 #include <unistd.h>
15
16 #include "support/lyxlib.h"
17
18 namespace {
19
20 inline
21 char * l_getcwd(char * buffer, size_t size)
22 {
23 #ifndef __EMX__
24         return ::getcwd(buffer, size);
25 #else
26         return ::_getcwd2(buffer, size);
27 #endif
28 }
29
30 } // namespace anon
31
32
33 // Returns current working directory
34 string const lyx::support::getcwd()
35 {
36         int n = 256;    // Assume path is less than 256 chars
37         char * err;
38         char * tbuf = new char[n];
39
40         // Safe. Hopefully all getcwds behave this way!
41         while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) {
42                 // Buffer too small, double the buffersize and try again
43                 delete[] tbuf;
44                 n = 2 * n;
45                 tbuf = new char[n];
46         }
47
48         string result;
49         if (err) result = tbuf;
50         delete[] tbuf;
51         return result;
52 }