]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
hopefully fix tex2lyx linking.
[lyx.git] / src / support / lyxlib.h
1 // -*- C++ -*-
2 /**
3  * \file lyxlib.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * A selection of useful system functions made
8  * handy for C++ usage.
9  *
10  * \author Lars Gullik Bjønnes
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LYX_LIB_H
16 #define LYX_LIB_H
17
18 #include <string>
19
20
21 namespace lyx {
22 namespace support {
23
24 /// get the current working directory
25 std::string const getcwd();
26 /// change to a directory, 0 is returned on success.
27 int chdir(std::string const & name);
28 /// Change file permissions
29 bool chmod(std::string const & file, unsigned long int mode);
30 /**
31  * rename a file, returns false if it fails.
32  * It can handle renames across partitions.
33  */
34 bool rename(std::string const & from, std::string const & to);
35 /// copy a file, returns false it it fails
36 bool copy(std::string const & from, std::string const & to,
37           unsigned long int mode = (unsigned long int)-1);
38 /// generates a checksum of a file
39 unsigned long sum(std::string const & file);
40 /// FIXME: some point to this hmm ?
41 int kill(int pid, int sig);
42 /// FIXME: same here
43 void abort();
44 /// create the given directory with the given mode
45 int mkdir(std::string const & pathname, unsigned long int mode);
46 /// unlink the given file
47 int unlink(std::string const & file);
48 /// (securely) create a temporary file in the given dir with the given prefix
49 std::string const tempName(std::string const & dir = std::string(),
50                       std::string const & mask = std::string());
51
52
53 /**
54  * Returns true if var is approximately equal to number with allowed error
55  * of 'error'.
56  *
57  * Usage: if (float_equal(var, number, 0.0001)) { }
58  *
59  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
60  */
61 inline bool float_equal(double var, double number, double error)
62 {
63         return (number - error <= var && var <= number + error);
64 }
65
66 } // namespace support
67 } // namespace lyx
68
69 #endif /* LYX_LIB_H */