00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TJTOOLS_H
00024 #define TJTOOLS_H
00025
00026 #include <tjutils/tjutils.h>
00027
00033 #ifndef PII
00034 #define PII 3.14159265358979323846264338327950288
00035 #endif
00036
00037 #ifndef ODIN_MAXCHAR
00038 #define ODIN_MAXCHAR 4096
00039 #endif
00040
00041 #ifdef HAVE_LONG_LONG
00042 #define LONGEST_INT long long
00043 #else
00044 #define LONGEST_INT long
00045 #endif
00046
00047
00048
00049
00050 #ifdef HAVE_STAT64
00051 #define STAT stat64
00052 #else
00053 #ifdef HAVE_STAT
00054 #define STAT stat
00055 #endif
00056 #endif
00057
00058 #ifdef HAVE_OPEN64
00059 #define OPEN open64
00060 #else
00061 #define OPEN open
00062 #endif
00063
00064 #ifdef HAVE_FOPEN64
00065 #define FOPEN fopen64
00066 #else
00067 #define FOPEN fopen
00068 #endif
00069
00070 #ifdef HAVE_FSEEKO64
00071 #define FSEEK fseeko64
00072 #else
00073 #ifdef HAVE_FSEEKO
00074 #define FSEEK fseeko
00075 #else
00076 #define FSEEK fseek
00077 #endif
00078 #endif
00079
00080 #ifdef HAVE_FTELLO64
00081 #define FTELL ftello64
00082 #else
00083 #ifdef HAVE_FTELLO
00084 #define FTELL ftello
00085 #else
00086 #define FTELL ftell
00087 #endif
00088 #endif
00089
00090 #ifdef HAVE_MMAP64
00091 #define MMAP mmap64
00092 #else
00093 #define MMAP mmap
00094 #endif
00095
00096
00104 enum fopenMode {readMode,overwriteMode,appendMode};
00105
00106
00110 double norm(double x, double y);
00111
00112
00116 double norm3(double x,double y,double z);
00117
00118
00119
00124 double maxof3(double f1, double f2, double f3);
00125
00126
00127 #ifndef NO_FILEHANDLING
00128
00129
00134 const char* modestring(fopenMode mode);
00135
00136
00141 LONGEST_INT filesize(const char *filename);
00142
00143
00148 const char* getpwd();
00149
00150
00155 int chpwd(const char *dirname);
00156
00157
00162 int createdir(const char *dirname);
00163
00164
00169 bool checkdir(const char *dirname);
00170
00171
00176 int movefile(const char *src, const char* dst);
00177
00178
00183 int copyfile(const char *src, const char* dst);
00184
00185
00190 int rmfile(const char *fname);
00191
00192
00197 int chperm(const char *fname, int perm);
00198
00199
00200
00208 void* filemap(const STD_string& filename, LONGEST_INT nbytes, LONGEST_INT offset, bool readonly, int& fd);
00209
00210
00216 void fileunmap(int fd, void* start, LONGEST_INT nbytes, LONGEST_INT offset);
00217
00218
00223 STD_string tempfile();
00224
00225
00231 int create_empty_file(const STD_string& filename, LONGEST_INT nbytes, fopenMode mode=overwriteMode);
00232
00233
00234 #endif
00235
00236
00241 const char* lasterr();
00242
00243
00248 void sleep_ms(unsigned int ms);
00249
00250
00255 double current_time_s();
00256
00257
00262 double secureDivision(double numerator, double denominator);
00263
00268 inline double secureInv(double denominator) {return secureDivision(1.0, denominator); }
00269
00270
00271
00276 const char* secure_getenv(const char* variable_name);
00277
00278
00283 bool little_endian_byte_order();
00284
00289 unsigned int numof_cores();
00290
00296 double sinc(double x);
00297
00298
00299 #ifndef NO_CMDLINE
00300
00310 int getCommandlineOption(int argc, char *argv[], const char *option, char *returnvalue, int maxchar,bool modify=true);
00311
00312
00318 int isCommandlineOption(int argc, char *argv[], const char *option,bool modify=true);
00319
00320
00329 int getLastArgument(int argc, char *argv[], char *returnvalue, int maxchar,bool modify=true);
00330
00331
00336 int hasHelpOption(int argc, char *argv[]);
00337
00342 const char* helpUsage();
00343
00344 #endif
00345
00346
00349 #endif
00350