]> git.lyx.org Git - lyx.git/blob - src/support/path.C
Fix my breakage. Sorry guys.
[lyx.git] / src / support / path.C
1 /**
2  * \file path.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 // Needed to prevent the definition of the unnamed_Path macro in the header file.
14 #define PATH_C
15
16 #include "support/path.h"
17 #include "support/lyxlib.h"
18
19
20 using std::string;
21
22
23 namespace lyx {
24 namespace support {
25
26 Path::Path(string const & path)
27         : popped_(false)
28 {
29         if (!path.empty()) {
30                 pushedDir_ = getcwd();
31
32                 if (pushedDir_.empty() || chdir(path))
33                         /* FIXME: throw */;
34         } else {
35                 popped_ = true;
36         }
37 }
38
39
40 Path::~Path()
41 {
42         if (!popped_) pop();
43 }
44
45
46 int Path::pop()
47 {
48         if (popped_) {
49                 // should throw an exception
50                 // throw logical_error();
51                 return 0;
52         }
53
54         if (chdir(pushedDir_)) {
55                 // should throw an exception
56                 // throw DirChangeError();
57         }
58         popped_ = true;
59
60         return 0;
61 }
62
63 } // namespace support
64 } // namespace lyx