]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
Revert qprocess code. Revisions reverted: 22026, 22030, 22044, 22048,
[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 file permissions
29 bool chmod(FileName 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(FileName const & from, FileName const & to);
35 /// copy a file, returns false it it fails
36 bool copy(FileName const & from, FileName const & to,
37           unsigned long int mode = (unsigned long int)-1);
38 /// FIXME: some point to this hmm ?
39 int kill(int pid, int sig);
40 /// FIXME: same here
41 void abort();
42 /// create the given directory with the given mode
43 /// \ret return 0 if the directory is successfully created
44 int mkdir(FileName const & pathname, unsigned long int mode);
45 /// create the given directory with the given mode, create all
46 /// intermediate directories if necessary
47 /// \ret return 0 if the directory is successfully created
48 int makedir(char * pathname, unsigned long int mode=0755);
49 /// (securely) create a temporary file in the given dir with the given mask
50 /// \p mask must be in filesystem encoding
51 FileName const tempName(FileName const & dir = FileName(),
52                       std::string const & mask = std::string());
53
54
55 /**
56  * Returns true if var is approximately equal to number with allowed error
57  * of 'error'.
58  *
59  * Usage: if (float_equal(var, number, 0.0001)) { }
60  *
61  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
62  */
63 inline bool float_equal(double var, double number, double error)
64 {
65         return (number - error <= var && var <= number + error);
66 }
67
68 } // namespace support
69 } // namespace lyx
70
71 #endif /* LYX_LIB_H */