1 | /* Copyright Jérémie Burgalat (2010-2015) |
---|
2 | * |
---|
3 | * burgalat.jeremie@gmail.com |
---|
4 | * |
---|
5 | * This software is a computer program whose purpose is to provide configuration |
---|
6 | * file and command line arguments parsing features to Fortran programs. |
---|
7 | * |
---|
8 | * This software is governed by the CeCILL-B license under French law and |
---|
9 | * abiding by the rules of distribution of free software. You can use, |
---|
10 | * modify and/ or redistribute the software under the terms of the CeCILL-B |
---|
11 | * license as circulated by CEA, CNRS and INRIA at the following URL |
---|
12 | * "http://www.cecill.info". |
---|
13 | * |
---|
14 | * As a counterpart to the access to the source code and rights to copy, |
---|
15 | * modify and redistribute granted by the license, users are provided only |
---|
16 | * with a limited warranty and the software's author, the holder of the |
---|
17 | * economic rights, and the successive licensors have only limited |
---|
18 | * liability. |
---|
19 | * |
---|
20 | * In this respect, the user's attention is drawn to the risks associated |
---|
21 | * with loading, using, modifying and/or developing or reproducing the |
---|
22 | * software by the user in light of its specific status of free software, |
---|
23 | * that may mean that it is complicated to manipulate, and that also |
---|
24 | * therefore means that it is reserved for developers and experienced |
---|
25 | * professionals having in-depth computer knowledge. Users are therefore |
---|
26 | * encouraged to load and test the software's suitability as regards their |
---|
27 | * requirements in conditions enabling the security of their systems and/or |
---|
28 | * data to be ensured and, more generally, to use and operate it in the |
---|
29 | * same conditions as regards security. |
---|
30 | * |
---|
31 | * The fact that you are presently reading this means that you have had |
---|
32 | * knowledge of the CeCILL-B license and that you accept its terms. |
---|
33 | *//* csystem.h */ |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | /* ------------------ WRAPPERS METHODS FOR FORTRAN BINDINGS ------------------ */ |
---|
38 | |
---|
39 | /** |
---|
40 | * Gets the current umask (in decimal system) |
---|
41 | * @return An int with the current umask set for the current session |
---|
42 | */ |
---|
43 | int c_umask(); |
---|
44 | |
---|
45 | /** |
---|
46 | * Get directory name of input path |
---|
47 | * @param[in] in A C string with the input path |
---|
48 | * @return A pointer to a char array with the directory name of @bti{input} path. |
---|
49 | * @note On error, a NULL pointer is returned. |
---|
50 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
51 | * (using fsystem::free_c). |
---|
52 | */ |
---|
53 | char * c_dirname(const char *in); |
---|
54 | |
---|
55 | /** |
---|
56 | * Get base name of input path |
---|
57 | * @param[in] in A C string with the input path |
---|
58 | * @return A pointer to a char array with the base name of @bti{input} path. |
---|
59 | * @note On error, a NULL pointer is returned. |
---|
60 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
61 | * (using fsystem::free_c). |
---|
62 | */ |
---|
63 | char* c_basename(const char *in); |
---|
64 | |
---|
65 | /** |
---|
66 | * Get the current working directory. |
---|
67 | * @return A pointer to a char array with the current workind directory. |
---|
68 | * @note On error, a NULL pointer is returned. |
---|
69 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
70 | * (using fsystem::free_c). |
---|
71 | */ |
---|
72 | char* c_getcwd(); |
---|
73 | |
---|
74 | |
---|
75 | /** |
---|
76 | * Get the realpath of input path. |
---|
77 | * @param[in] input A C string with the input path |
---|
78 | * @return A pointer to a char array with the realpath of @bti{input} path. |
---|
79 | * @note On error, a NULL pointer is returned. |
---|
80 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
81 | * (using fsystem::free_c). |
---|
82 | */ |
---|
83 | char* c_realpath(const char *input); |
---|
84 | |
---|
85 | /** |
---|
86 | * Get the relative path of two file paths |
---|
87 | * @details The method computes the relative path of can_fname to can_reldir if |
---|
88 | * possible. |
---|
89 | * @param path string with the path to compute in relative representation |
---|
90 | * @param reldir a directory path from which output should be relative to |
---|
91 | * @return A pointer to a char array with the relative path. |
---|
92 | * @note On error, a NULL pointer is returned. |
---|
93 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
94 | * (using fsystem::free_c). |
---|
95 | */ |
---|
96 | char* c_relpath(const char *path, const char *reldir) ; |
---|
97 | |
---|
98 | /** |
---|
99 | * Get the corresponding name of the given user id |
---|
100 | * @param[in] uid An integer with a user id |
---|
101 | * @return A pointer to a char array with the user name. |
---|
102 | * @note On error, a NULL pointer is returned. |
---|
103 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
104 | * (using fsystem::free_c). |
---|
105 | */ |
---|
106 | char* c_uname(int uid); |
---|
107 | |
---|
108 | /** |
---|
109 | * Get the corresponding name of the given group id |
---|
110 | * @param[in] gid An integer with a group id |
---|
111 | * @return A pointer to a char array with the group name. |
---|
112 | * @note On error, a NULL pointer is returned. |
---|
113 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
114 | * (using fsystem::free_c). |
---|
115 | */ |
---|
116 | char* c_gname(int gid); |
---|
117 | |
---|
118 | /** |
---|
119 | * Get last errno from C library |
---|
120 | * @return An int with last errno saved in C library. |
---|
121 | */ |
---|
122 | int c_get_errno(); |
---|
123 | |
---|
124 | /** |
---|
125 | * Get the error message of the given error id |
---|
126 | * @param err An integer with the error id |
---|
127 | * @return A pointer to a char array with the group name. |
---|
128 | * @note On error, the hard-coded message "Unknown error" is returned. |
---|
129 | * @warning In any case, the returned pointer must be freed in the Fortran counterpart |
---|
130 | * (using fsystem::free_c). |
---|
131 | */ |
---|
132 | char* c_strerror(int err); |
---|
133 | |
---|
134 | /** |
---|
135 | * Creates directories recursively |
---|
136 | * @note The method is simple stripped copy of mkdir tool source code. |
---|
137 | * @param[in] path A C string with the path of the directory to create |
---|
138 | * @param[in] mode A mode_t structure with the permission of the directory |
---|
139 | * @return An integer with 0 on success, last errno on failure |
---|
140 | */ |
---|
141 | int c_mkdirp(const char *path, mode_t mode); |
---|
142 | |
---|
143 | /** |
---|
144 | * Rename a path |
---|
145 | * @param old A string with the (valid) path to rename |
---|
146 | * @param new A string with the new name of the path |
---|
147 | * @return An integer with 0 on success, last errno on failure |
---|
148 | */ |
---|
149 | int c_rename(const char *old, const char *new); |
---|
150 | |
---|
151 | /** |
---|
152 | * Change path permissions |
---|
153 | * @param path A string with the path |
---|
154 | * @param mode A integer with the new permissions to set |
---|
155 | * @return An integer with 0 on success, last errno on failure |
---|
156 | */ |
---|
157 | int c_chmod(const char *path, mode_t mode); |
---|
158 | |
---|
159 | /** |
---|
160 | * Change current working directory |
---|
161 | * @param path A C string with the new path |
---|
162 | * @return An integer with 0 on success, last errno on failure |
---|
163 | */ |
---|
164 | int c_chdir(const char *path); |
---|
165 | |
---|
166 | /** |
---|
167 | * Create directory |
---|
168 | * @param[in] path A C string with the path of the directory to create |
---|
169 | * @param[in] mode A mode_t structure with the permission of the directory |
---|
170 | * (as well as all the parent directorie created, if any). |
---|
171 | * @return An integer with 0 on success, last errno on failure |
---|
172 | */ |
---|
173 | int c_mkdir(const char *path, mode_t mode); |
---|
174 | |
---|
175 | /** |
---|
176 | * Remove file from filesytem |
---|
177 | * @note Also works for directory (if empty) |
---|
178 | * @param path A C string with the filepath to remove |
---|
179 | * @return An integer with 0 on success, last errno on failure |
---|
180 | */ |
---|
181 | int c_remove(const char *path); |
---|
182 | |
---|
183 | /** |
---|
184 | * Remove a directory |
---|
185 | * @param path A C string with the path of the directory to remove. |
---|
186 | * @return An integer with 0 on success, last errno on failure |
---|
187 | */ |
---|
188 | int c_rmdir(const char *path); |
---|
189 | |
---|
190 | /** |
---|
191 | * Remove a directory and its contents recursively |
---|
192 | * |
---|
193 | * This method mimics 'rm -rf' command. |
---|
194 | * @param path A C string with the path of the directory to remove. |
---|
195 | * @return An integer with 0 on success, last errno on failure |
---|
196 | */ |
---|
197 | int c_rmdir_f(const char *path) ; |
---|
198 | |
---|
199 | /** |
---|
200 | * Get some file informations |
---|
201 | * @note If the path cannot be "stat", most of the output parameters are set |
---|
202 | * to -1. |
---|
203 | * @param[in] p A C string with the path of a file (or directory) |
---|
204 | * @param[out] pe An int with the permissions of the path |
---|
205 | * @param[out] nl An int with the inumber of links |
---|
206 | * @param[out] ty An int with the type of the file : |
---|
207 | * - 0 -> file |
---|
208 | * - 1 -> link to a file |
---|
209 | * - 2 -> directory |
---|
210 | * - 3 -> link to a directory |
---|
211 | * - 4 -> Other (fifo, socket, block special, char special ...) |
---|
212 | * @param[out] ui An int with the user id of the path |
---|
213 | * @param[out] gi An int with the group id of the path |
---|
214 | * @param[out] si An int with the size of the path |
---|
215 | * @param[out] a A C string (20 chars wide, including NULL character) with the |
---|
216 | * last access date |
---|
217 | * @param[out] m A C string (20 chars wide, including NULL character) with the |
---|
218 | * last modification date |
---|
219 | * @param[out] c A C string (20 chars wide, including NULL character) with the |
---|
220 | * creation date |
---|
221 | * @return An integer with 0 on success, last errno on failure |
---|
222 | */ |
---|
223 | int c_fstat(const char *p, int *pe, int *nl, int *ty, int *ui, int *gi, |
---|
224 | long *si, char a[20], char m[20], char c[20]); |
---|
225 | |
---|
226 | /** |
---|
227 | * Check if path is accessible |
---|
228 | * @param[in] path A C string with the path to check |
---|
229 | * @param[in] perm An integer with the user's permission to check : |
---|
230 | * - 0 do not check for permissions |
---|
231 | * - 1 check for execute permission |
---|
232 | * - 2 check for write permission |
---|
233 | * - 4 check for read permission |
---|
234 | * @return An int with 0 on success, errno on failure |
---|
235 | */ |
---|
236 | int c_access(const char *path, int perm) ; |
---|
237 | |
---|
238 | /** |
---|
239 | * Create a directory or a file in given path |
---|
240 | * @param[in] path Path to be created |
---|
241 | * @param[in] mode Permission of the path |
---|
242 | * @param[in] astype A boolean with False to create a directory, True to create a file. |
---|
243 | * @param[in] forced A boolean with True to force creation of intermediate directory |
---|
244 | * @return 0 on success, -9 on allocation failure, last errno otherwise |
---|
245 | */ |
---|
246 | int c_create(const char* path, mode_t mode, int astype, int forced); |
---|
247 | |
---|
248 | /** |
---|
249 | * Create a directory or a file in given path |
---|
250 | * @param[out] rows Number of rows of the current terminal window |
---|
251 | * @param[out] cols Number of columns of the current terminal window |
---|
252 | * @return An int with 0 on success, errno on failure. On failure, rows is set |
---|
253 | * to 80 and cols to 20. |
---|
254 | */ |
---|
255 | int c_termsize(int *rows,int *cols); |
---|
256 | |
---|