Flow123d  JB-rel-int-test-ea53151
system.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file system.cc
15  * @ingroup system
16  * @brief Various system-wide functions
17  */
18 
19 #include <cstring>
20 #include <cstdarg>
21 #include <ctime>
22 #include <cstdlib>
23 #include <sys/stat.h>
24 #include <cerrno>
25 #include <sstream>
26 
27 #include <fstream>
28 #include <string>
29 #include "mpi.h"
30 
31 #include "system/system.hh"
32 #include "system/file_path.hh"
33 #include "system/sys_profiler.hh"
34 
35 #include <boost/algorithm/string/predicate.hpp>
36 #include <boost/algorithm/string/trim.hpp>
37 #include <boost/format.hpp>
38 
39 
40 
42 
43 
44 /*
45 void *operator new (std::size_t size, const my_new_t &) throw() {
46  return xmalloc(size);
47 }
48 
49 void *operator new[] (std::size_t size, const my_new_t &) throw() {
50  return xmalloc(size);
51 }
52 
53 void operator delete( void *p, const my_new_t &) throw ()
54 {
55  xfree(p);
56 }
57 
58 void operator delete[]( void *p, const my_new_t &) throw ()
59 {
60  xfree(p);
61 }
62 */
63 
64 
65 
66 
67 /*!
68  * @brief SYSTEM with err handling
69  */
70 /*
71 int xsystem( const char *cmd )
72 {
73  int rc;
74 
75  rc = system( cmd );
76  INPUT_CHECK(!( rc != 0 ),"Error executing external command: %s\n", cmd );
77  return(rc);
78 }*/
79 
80 /*!
81  * @brief MAKE BRAND NEW COPY OF STRING
82  */
83 /*
84 char *xstrcpy( const char *src )
85 {
86  char *rc;
87  size_t length;
88 
89  ASSERT_PERMANENT_PTR(src).error("NULL pointer as argument of function xstrcpy()\n");
90  length = strlen( src ) + 1;
91  rc = (char*) xmalloc(length * sizeof(char));
92  strcpy( rc, src );
93  return(rc);
94 }*/
95 
96 /*!
97  * @brief STRTOK WITH ERROR HANDLING and whitespace delimiters
98  * @param[in] s strtok string pointer
99  * @param[in] position requested position of the token
100  * @return strtok return
101  */
102 /*
103 char *xstrtok(char *s, int position)
104 {
105  char *rc;
106  const char * const whitespace_delim=" \t\r\n";
107 
108  rc = xstrtok( s, whitespace_delim, position);
109  return(rc);
110 }
111 */
112 
113 /*!
114  * @brief STRTOK WITH ERROR HANDLING and user specified delimiters
115  * @param[in] s1 strtok string pointer
116  * @param[in] delim delimiters
117  * @param[in] position requested position of the token
118  * @return strtok return
119  *
120  * Function behaves like original strtok
121  */
122 /*
123 char *xstrtok( char *s1, const char *delim, int position )
124 {
125  char *rc;
126  static char * full_string = NULL;
127  static int token_count;
128 
129  ASSERT_PERMANENT_PTR(delim).error("NULL pointer as delimiter in xstrtok()\n");
130 
131  if ( s1 )
132  {
133  if ( !full_string )
134  {
135  full_string = (char *)xmalloc( LINE_SIZE );
136  full_string[0] = 0x0;
137  }
138 
139  strncpy( full_string, s1, LINE_SIZE );
140  token_count = 0;
141  }
142 
143  INPUT_CHECK( token_count == position || position < 0, "Requested position %d dosn't match token position %d", position, token_count);
144  rc = strtok( s1, delim );
145  token_count++;
146 
147  INPUT_CHECK(!( rc == NULL ),"Missing token no. %d: original string '%s' with delimiters '%s'\n", token_count, full_string, delim );
148 
149  return(rc);
150 }
151 */
152 
153 /*!
154  * @brief Delete trailing whitespace characters (space,tab,CR,NL).
155  * @param[in,out] s string to change
156  * @return number of deleted characters
157  */
158 /*
159 int xchomp( char * s )
160 {
161  int no_erased = 0;
162  char * p;
163 
164  ASSERT_PERMANENT(s).error("Can not chomp NULL string.");
165 
166  if ( *s ) //string not empty
167  {
168  p = s;
169  while (*p)
170  p++; //find end of string
171  p--; //set p to the last character
172  while ((p >= s) && ((*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n')))
173  {
174  *p = 0x0;
175  no_erased++;
176  p--;
177  }
178  }
179  return(no_erased);
180 }*/
181 
182 
183 /*!
184  * @brief MKDIR WITH ERROR HANDLING
185  */
186 /*
187 int xmkdir( const char *s )
188 {
189  int rc;
190 
191  ASSERT_PERMANENT_PTR(s).error("NULL pointer as argument of function xmkdir()\n");
192  rc = mkdir(s, S_IRWXU); // create dir with rwx perm. for user
193  if (errno == EEXIST)
194  rc = 0;
195  INPUT_CHECK(!( rc != 0 ),"Cannot make directory %s\n", s );
196 
197  return(rc);
198 }*/
199 
200 /*!
201  * @brief RMDIR with err handling
202  */
203 /*
204 int xrmdir( const char *s )
205 {
206  int rc;
207 
208  ASSERT_PERMANENT_PTR(s).error("NULL pointer as argument of function xrmdir()\n");
209  rc = rmdir( s );
210  INPUT_CHECK(!( rc != 0 ),"Cannot delete directory %s\n", s );
211  return(rc);
212 }*/
213 
214 /*!
215  * @brief CHDIR WITH ERROR HANDLING
216  */
217 /*
218 int xchdir( const char *s )
219 {
220  int rc;
221 
222  ASSERT_PERMANENT_PTR(s).error("NULL pointer as argument of function xchdir()\n");
223  rc = chdir( s );
224  INPUT_CHECK(!( rc != 0 ),"Cannot change directory to %s\n", s );
225  return(rc);
226 }*/
227 
228 /*!
229  * @brief DELETE a FILE with error handling
230  */
231 
232 /*
233 int xremove( const char *fname )
234 {
235  int rc;
236 
237  ASSERT_PERMANENT_PTR(fname).error("NULL pointer as argument of function xremove()\n");
238  if( access( fname , F_OK ) == 0 )
239  {
240  rc = remove( fname );
241  INPUT_CHECK(!( rc != 0 ),"Cannot remove file %s\n", fname );
242  }
243  else
244  WarningOut() << "File '" << fname << "' does not exist, can not remove. Ignoring." << std::endl;
245 
246  return(rc);
247 }*/
248 
249 /*!
250  * @brief GET CURRENT WORKING DIRECTORY with error handling
251  */
252 /*
253 char *xgetcwd( void )
254 {
255  char tmp[PATH_MAX];
256  char * rc;
257 
258  rc = getcwd( tmp, PATH_MAX );
259  ASSERT_PERMANENT_PTR(rc(.error("Cannot get name of current working directory\n");
260 
261  return(xstrcpy( tmp ));
262 }*/
263 
System structure for various global variables.
Definition: system.hh:72
SystemInfo sys_info
Definition: system.cc:41