]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
f2cfaa6bdb2e80f848d5a267b7c36a3b71e944f2
[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 "support/FileName.h"
19
20 #include <string>
21
22
23 namespace lyx {
24 namespace support {
25
26 /// get the current working directory
27 FileName const getcwd();
28 /// change to a directory, 0 is returned on success.
29 int chdir(FileName const & name);
30 /// Change file permissions
31 bool chmod(FileName const & file, unsigned long int mode);
32 /**
33  * rename a file, returns false if it fails.
34  * It can handle renames across partitions.
35  */
36 bool rename(FileName const & from, FileName const & to);
37 /// copy a file, returns false it it fails
38 bool copy(FileName const & from, FileName const & to,
39           unsigned long int mode = (unsigned long int)-1);
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 /// \ret return 0 if the directory is successfully created
46 int mkdir(FileName const & pathname, unsigned long int mode);
47 /// create the given directory with the given mode, create all
48 /// intermediate directories if necessary
49 /// \ret return 0 if the directory is successfully created
50 int makedir(char * pathname, unsigned long int mode=0755);
51 /// (securely) create a temporary file in the given dir with the given mask
52 /// \p mask must be in filesystem encoding
53 FileName const tempName(FileName const & dir = FileName(),
54                       std::string const & mask = std::string());
55
56
57 /**
58  * Returns true if var is approximately equal to number with allowed error
59  * of 'error'.
60  *
61  * Usage: if (float_equal(var, number, 0.0001)) { }
62  *
63  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
64  */
65 inline bool float_equal(double var, double number, double error)
66 {
67         return (number - error <= var && var <= number + error);
68 }
69
70 } // namespace support
71 } // namespace lyx
72
73 #endif /* LYX_LIB_H */