source: trunk/LMDZ.TITAN/libf/muphytitan/csystem.h @ 3094

Last change on this file since 3094 was 3090, checked in by slebonnois, 15 months ago

BdeBatz? : Cleans microphysics and makes few corrections for physics

File size: 9.5 KB
Line 
1/*
2 * Copyright (c) (2013-2015,2017,2022) Jeremie Burgalat (jeremie.burgalat@univ-reims.fr).
3 *
4 * This file is part of SWIFT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of
7 * this software and associated documentation files (the "Software"), to deal in
8 * the Software without restriction, including without limitation the rights to
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 * the Software, and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25
26/* ------------------ WRAPPERS METHODS FOR FORTRAN BINDINGS ------------------ */
27
28/**
29 * Gets the current umask (in decimal system)
30 * @return An int with the current umask set for the current session
31 */
32int c_umask();
33
34/**
35 * Get directory name of input path
36 * @param[in] in A C string with the input path
37 * @return A pointer to a char array with the directory name of @bti{input} path.
38 * @note On error, a NULL pointer is returned.
39 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
40 * (using fsystem::free_c).
41 */
42char * c_dirname(const char *in);
43
44/**
45 * Get base name of input path
46 * @param[in] in A C string with the input path
47 * @return A pointer to a char array with the base name of @bti{input} path.
48 * @note On error, a NULL pointer is returned.
49 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
50 * (using fsystem::free_c).
51 */
52char* c_basename(const char *in);
53
54/**
55 * Get the current working directory.
56 * @return A pointer to a char array with the current workind directory.
57 * @note On error, a NULL pointer is returned.
58 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
59 * (using fsystem::free_c).
60 */
61char* c_getcwd();
62
63
64/**
65 * Get the realpath of input path.
66 * @param[in] input A C string with the input path
67 * @return A pointer to a char array with the realpath of @bti{input} path.
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 */
72char* c_realpath(const char *input);
73
74/**
75 * Get the relative path of two file paths
76 * @details The method computes the relative path of can_fname to can_reldir if
77 * possible.
78 * @param path string with the path to compute in relative representation
79 * @param reldir a directory path from which output should be relative to
80 * @return A pointer to a char array with the relative path.
81 * @note On error, a NULL pointer is returned.
82 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
83 * (using fsystem::free_c).
84 */
85char* c_relpath(const char *path, const char *reldir) ;
86
87/**
88 * Get the corresponding name of the given user id
89 * @param[in] uid An integer with a user id
90 * @return A pointer to a char array with the user name.
91 * @note On error, a NULL pointer is returned.
92 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
93 * (using fsystem::free_c).
94 */
95char* c_uname(int uid);
96
97/**
98 * Get the corresponding name of the given group id
99 * @param[in] gid An integer with a group id
100 * @return A pointer to a char array with the group name.
101 * @note On error, a NULL pointer is returned.
102 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
103 * (using fsystem::free_c).
104 */
105char* c_gname(int gid);
106
107/**
108 * Get last errno from C library
109 * @return An int with last errno saved in C library.
110 */
111int c_get_errno();
112
113/**
114 * Get the error message of the given error id
115 * @param err An integer with the error id
116 * @return A pointer to a char array with the group name.
117 * @note On error, the hard-coded message "Unknown error" is returned.
118 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
119 * (using fsystem::free_c).
120 */
121char* c_strerror(int err);
122
123/**
124 * Creates directories recursively
125 * @note The method is simple stripped copy of mkdir tool source code.
126 * @param[in] path A C string with the path of the directory to create
127 * @param[in] mode A mode_t structure with the permission of the directory
128 * @return An integer with 0 on success, last errno on failure
129 */
130int c_mkdirp(const char *path, mode_t mode);
131
132/**
133 * Rename a path
134 * @param old A string with the (valid) path to rename
135 * @param new A string with the new name of the path
136 * @return An integer with 0 on success, last errno on failure
137 */
138int c_rename(const char *old, const char *new);
139
140/**
141 * Change path permissions
142 * @param path A string with the path
143 * @param mode A integer with the new permissions to set
144 * @return An integer with 0 on success, last errno on failure
145 */
146int c_chmod(const char *path, mode_t mode);
147
148/**
149 * Change current working directory
150 * @param path A C string with the new path
151 * @return An integer with 0 on success, last errno on failure
152 */
153int c_chdir(const char *path);
154
155/**
156 * Create directory
157 * @param[in] path A C string with the path of the directory to create
158 * @param[in] mode A mode_t structure with the permission of the directory
159 *                 (as well as all the parent directorie created, if any).
160 * @return An integer with 0 on success, last errno on failure
161 */
162int c_mkdir(const char *path, mode_t mode);
163
164
165/**
166 * Copy file to another.
167 * @param to A C string with the new filepath
168 * @param from A C string with the filepath to copy
169 * @return An integer with 0 on success, 1 on failure.
170 */
171int c_copy(const char *to, const char *from);
172
173/**
174 * Remove file from filesytem
175 * @note Also works for directory (if empty)
176 * @param path A C string with the filepath to remove
177 * @return An integer with 0 on success, last errno on failure
178 */
179int c_remove(const char *path);
180
181/**
182 * Remove a directory
183 * @param path A C string with the path of the directory to remove.
184 * @return An integer with 0 on success, last errno on failure
185 */
186int c_rmdir(const char *path);
187
188/**
189 * Remove a directory and its contents recursively
190 *
191 * This method mimics 'rm -rf' command.
192 * @param path A C string with the path of the directory to remove.
193 * @return An integer with 0 on success, last errno on failure
194 */
195int c_rmdir_f(const char *path) ;
196
197/**
198 * Get some file informations
199 * @note If the path cannot be "stat", most of the output parameters are set
200 * to -1.
201 * @param[in] p A C string with the path of a file (or directory)
202 * @param[out] pe An int with the permissions of the path
203 * @param[out] nl An int with the inumber of links
204 * @param[out] ty An int with the type of the file :
205 *    - 0 -> file
206 *    - 1 -> link to a file
207 *    - 2 -> directory
208 *    - 3 -> link to a directory
209 *    - 4 -> Other (fifo, socket, block special, char special ...)
210 * @param[out] ui An int with the user id of the path
211 * @param[out] gi An int with the group id of the path
212 * @param[out] si An int with the size of the path
213 * @param[out] a A C string (20 chars wide, including NULL character) with the
214 * last access date
215 * @param[out] m A C string (20 chars wide, including NULL character) with the
216 * last modification date
217 * @param[out] c A C string (20 chars wide, including NULL character) with the
218 * creation date
219 * @return An integer with 0 on success, last errno on failure
220 */
221int c_fstat(const char *p, int *pe, int *nl, int *ty, int *ui, int *gi,
222            long *si, char a[20], char m[20], char c[20]);
223
224/**
225 * Check if path is accessible
226 * @param[in] path A C string with the path to check
227 * @param[in] perm An integer with the user's permission to check :
228 *   - 0 do not check for permissions
229 *   - 1 check for execute permission
230 *   - 2 check for write permission
231 *   - 4 check for read permission
232 * @return An int with 0 on success, errno on failure
233 */
234int c_access(const char *path, int perm) ;
235
236/**
237 * Create a directory or a file in given path
238 * @param[in] path Path to be created
239 * @param[in] mode Permission of the path
240 * @param[in] astype A boolean with False to create a directory, True to create a file.
241 * @param[in] forced A boolean with True to force creation of intermediate directory
242 * @return 0 on success, -9 on allocation failure, last errno otherwise
243 */
244int c_create(const char* path, mode_t mode, int astype, int forced);
245
246/**
247 * Create a directory or a file in given path
248 * @param[out] rows Number of rows of the current terminal window
249 * @param[out] cols Number of columns of the current terminal window
250 * @return An int with 0 on success, errno on failure. On failure, rows is set
251 * to 80 and cols to 20.
252 */
253int c_termsize(int *rows,int *cols);
254
255/**
256 * Get the current resident set size memory used by the program.
257 */
258size_t c_getCurrentRSS();
259
260/**
261 * Get the peak resident set size memory used by the program.
262 */
263size_t c_getPeakRSS();
264
265/**
266 * Get global memory usage informations.
267 *
268 * Note: The method attempts to read /proc/meminfo. If the file does not exists, all the given output arguments are
269 * set to zero.
270 */
271int c_getSystemMemory(long long int *m_total,long long int *m_available,long long int *m_free);
Note: See TracBrowser for help on using the repository browser.