Doxygen Generated Documentation of Ben-Jose Trainable SAT Solver Library
file_funcs.h
1 
2 
3 /*************************************************************
4 
5 This file is part of ben-jose.
6 
7 ben-jose is free software: you can redistribute it and/or modify
8 it under the terms of the version 3 of the GNU General Public
9 License as published by the Free Software Foundation.
10 
11 ben-jose is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with ben-jose. If not, see <http://www.gnu.org/licenses/>.
18 
19 ------------------------------------------------------------
20 
21 Copyright (C) 2007-2012, 2014-2016. QUIROGA BELTRAN, Jose Luis.
22 Id (cedula): 79523732 de Bogota - Colombia.
23 See https://github.com/joseluisquiroga/ben-jose
24 
25 ben-jose is free software thanks to The Glory of Our Lord
26  Yashua Melej Hamashiaj.
27 Our Resurrected and Living, both in Body and Spirit,
28  Prince of Peace.
29 
30 ------------------------------------------------------------
31 
32 file_funcs.h
33 
34 file funcs.
35 
36 --------------------------------------------------------------*/
37 
38 #ifndef FILE_FUNCS_H
39 #define FILE_FUNCS_H
40 
41 #include "top_exception.h"
42 #include "tools.h"
43 #include <unistd.h>
44 //include <limits.h>
45 
46 #define FILE_FN_CK(prm) DBG_CK(prm)
47 #define FILE_FN_CK_2(prm, comm) DBG_CK_2(prm, comm)
48 
49 #define BJ_FILE_MAX_PATH_DEPTH 40
50 #define BJ_PATH_MAX 500 // should be PATH_MAX as in limits.h
51 
52 #define BJ_LOCK_NAME "lock.skl"
53 #define BJ_SECS_DEAD_LOCK 10000
54 
55 #define END_OF_SEC 0
56 
57 typedef enum {
58  flx_cannot_open,
59  flx_cannot_calc_size,
60  flx_cannot_fit_in_mem,
61  flx_path_too_long
62 } fl_ex_cod_t;
63 
64 class file_exception : public top_exception {
65 public:
66  ch_string f_nm;
67  file_exception(long the_id = 0, ch_string ff = "unknow_file") : top_exception(the_id)
68  {
69  f_nm = ff;
70  }
71 };
72 
73 void
74 read_file(ch_string f_nam, row<char>& f_data);
75 
76 bool
77 write_file(ch_string& the_pth, row<char>& cnn, bool write_once);
78 
79 bool
80 rename_file(ch_string& old_pth, ch_string& nw_pth);
81 
82 // fnum = concurrent safe consec counter kept in file f_nam
83 
84 bj_big_int_t
85 inc_fnum(ch_string f_nam);
86 
87 ch_string
88 get_fstr(ch_string f_nam);
89 
90 long
91 set_fstr(ch_string f_nam, ch_string the_val_str);
92 
93 bj_big_float_t
94 update_elapsed(ch_string f_nam);
95 
96 long
97 read_elapsed(ch_string f_nam, average& the_avg);
98 
99 ch_string
100 get_nftw_flag_str(long ff);
101 
102 ch_string
103 get_errno_str(long val_errno);
104 
105 int
106 delete_dir_entry(const char *fpath, const struct stat *sb,
107  int tflag, struct FTW *ftwbuf);
108 
109 void
110 delete_directory(ch_string& dir_nm);
111 
112 bool
113 file_touch(ch_string the_pth);
114 
115 int
116 get_file_write_lock(ch_string lk_dir);
117 
118 void
119 drop_file_write_lock(int fd_lock);
120 
121 bool
122 file_exists(ch_string th_pth);
123 
124 bool
125 file_newer_than(ch_string the_pth, time_t tm1);
126 
127 time_t
128 path_verify(ch_string the_pth);
129 
130 bool
131 make_dir(ch_string the_pth, mode_t mod);
132 
133 ch_string
134 path_get_running_path();
135 
136 ch_string
137 path_to_absolute_path(ch_string pth);
138 
139 bool
140 path_create(ch_string n_pth);
141 
142 bool
143 path_begins_with(ch_string the_pth, ch_string the_beg);
144 
145 bool
146 path_ends_with(ch_string& the_str, ch_string& the_suf);
147 
148 void
149 path_delete(ch_string full_pth, ch_string up_to);
150 
151 ch_string
152 path_get_directory(ch_string the_pth, bool add_last_dir_sep);
153 
154 ch_string
155 path_get_name(ch_string the_pth);
156 
157 bool
158 path_create_link(ch_string old_pth, ch_string new_pth);
159 
160 ch_string
161 get_relative_path(ch_string pth1, ch_string pth2);
162 
163 ch_string
164 path_slice(ch_string nam, row_long_t& sections);
165 
166 #endif // FILE_FUNCS_H
167 
168