tjtools.h
1 /***************************************************************************
2  tjtools.h - description
3  -------------------
4  begin : Thu Jul 13 2000
5  copyright : (C) 2000-2015 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 
20 // This is a collection of frequently used C-routines
21 
22 
23 #ifndef TJTOOLS_H
24 #define TJTOOLS_H
25 
26 #include <tjutils/tjutils.h>
27 
33 #ifndef PII
34 #define PII 3.14159265358979323846264338327950288
35 #endif
36 
37 #ifndef ODIN_MAXCHAR
38 #define ODIN_MAXCHAR 4096
39 #endif
40 
41 #ifdef HAVE_LONG_LONG
42 #define LONGEST_INT long long
43 #else
44 #define LONGEST_INT long
45 #endif
46 
47 
48 // functions of large file extension, define them here so
49 // these macros can re-used in other modules
50 #ifdef HAVE_STAT64
51 #define ODIN_STAT stat64
52 #else
53 #ifdef HAVE_STAT
54 #define ODIN_STAT stat
55 #endif
56 #endif
57 
58 #ifdef HAVE_OPEN64
59 #define ODIN_OPEN open64
60 #else
61 #define ODIN_OPEN open
62 #endif
63 
64 #ifdef HAVE_FOPEN64
65 #define ODIN_FOPEN fopen64
66 #else
67 #define ODIN_FOPEN fopen
68 #endif
69 
70 #ifdef HAVE_FSEEKO64
71 #define ODIN_FSEEK fseeko64
72 #else
73 #ifdef HAVE_FSEEKO
74 #define ODIN_FSEEK fseeko
75 #else
76 #define ODIN_FSEEK fseek
77 #endif
78 #endif
79 
80 #ifdef HAVE_FTELLO64
81 #define ODIN_FTELL ftello64
82 #else
83 #ifdef HAVE_FTELLO
84 #define ODIN_FTELL ftello
85 #else
86 #define ODIN_FTELL ftell
87 #endif
88 #endif
89 
90 #ifdef HAVE_MMAP64
91 #define ODIN_MMAP mmap64
92 #else
93 #define ODIN_MMAP mmap
94 #endif
95 
96 
97 // macro to avoid compiler warnings about unused static string arrays
98 #define AVOID_CC_WARNING(strArray) inline const char* strArray##_dummyfunc() {return strArray[0];}
99 
107 enum fopenMode {readMode,overwriteMode,appendMode};
108 
109 
113 double norm(double x, double y);
114 
115 
119 double norm3(double x,double y,double z);
120 
121 
122 
127 double maxof3(double f1, double f2, double f3);
128 
129 
130 #ifndef NO_FILEHANDLING
131 
132 
137 const char* modestring(fopenMode mode);
138 
139 
144 LONGEST_INT filesize(const char *filename);
145 
146 
151 const char* getpwd();
152 
153 
158 int chpwd(const char *dirname);
159 
160 
165 int createdir(const char *dirname);
166 
167 
172 bool checkdir(const char *dirname);
173 
174 
179 int movefile(const char *src, const char* dst);
180 
181 
186 int copyfile(const char *src, const char* dst);
187 
188 
193 int rmfile(const char *fname);
194 
195 
200 int chperm(const char *fname, int perm);
201 
202 
203 
211 void* filemap(const STD_string& filename, LONGEST_INT nbytes, LONGEST_INT offset, bool readonly, int& fd);
212 
213 
219 void fileunmap(int fd, void* start, LONGEST_INT nbytes, LONGEST_INT offset);
220 
221 
226 STD_string tempfile();
227 
228 
234 int create_empty_file(const STD_string& filename, LONGEST_INT nbytes, fopenMode mode=overwriteMode);
235 
236 
237 #endif
238 
239 
244 const char* lasterr();
245 
246 
251 void sleep_ms(unsigned int ms);
252 
253 
258 double current_time_s();
259 
260 
265 double secureDivision(double numerator, double denominator);
266 
271 inline double secureInv(double denominator) {return secureDivision(1.0, denominator); }
272 
273 
274 
279 const char* getenv_nonnull(const char* variable_name);
280 
281 
287 
292 unsigned int numof_cores();
293 
299 double sinc(double x);
300 
301 
302 #ifndef NO_CMDLINE
303 
313 int getCommandlineOption(int argc, char *argv[], const char *option, char *returnvalue, int maxchar,bool modify=true);
314 
315 
321 int isCommandlineOption(int argc, char *argv[], const char *option,bool modify=true);
322 
323 
332 int getLastArgument(int argc, char *argv[], char *returnvalue, int maxchar,bool modify=true);
333 
334 
339 int hasHelpOption(int argc, char *argv[]);
340 
345 const char* helpUsage();
346 
347 #endif
348 
349 
352 #endif
353 
double current_time_s()
LONGEST_INT filesize(const char *filename)
int chperm(const char *fname, int perm)
const char * lasterr()
double norm3(double x, double y, double z)
const char * getpwd()
int create_empty_file(const STD_string &filename, LONGEST_INT nbytes, fopenMode mode=overwriteMode)
double maxof3(double f1, double f2, double f3)
const char * getenv_nonnull(const char *variable_name)
const char * helpUsage()
int movefile(const char *src, const char *dst)
void * filemap(const STD_string &filename, LONGEST_INT nbytes, LONGEST_INT offset, bool readonly, int &fd)
double secureInv(double denominator)
Definition: tjtools.h:271
bool checkdir(const char *dirname)
unsigned int numof_cores()
int isCommandlineOption(int argc, char *argv[], const char *option, bool modify=true)
double norm(double x, double y)
int getCommandlineOption(int argc, char *argv[], const char *option, char *returnvalue, int maxchar, bool modify=true)
void fileunmap(int fd, void *start, LONGEST_INT nbytes, LONGEST_INT offset)
int rmfile(const char *fname)
fopenMode
Definition: tjtools.h:107
void sleep_ms(unsigned int ms)
bool little_endian_byte_order()
int copyfile(const char *src, const char *dst)
int chpwd(const char *dirname)
int createdir(const char *dirname)
double secureDivision(double numerator, double denominator)
const char * modestring(fopenMode mode)
int getLastArgument(int argc, char *argv[], char *returnvalue, int maxchar, bool modify=true)
double sinc(double x)
int hasHelpOption(int argc, char *argv[])
STD_string tempfile()