This file is indexed.

/usr/include/tjutils/tjtools.h is in libodin-dev 1.8.8-2ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/***************************************************************************
                          tjtools.h  -  description
                             -------------------
    begin                : Thu Jul 13 2000
    copyright            : (C) 2000-2014 by Thies Jochimsen
    email                : thies@jochimsen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/



// This is a collection of frequently used C-routines


#ifndef TJTOOLS_H
#define TJTOOLS_H

#include <tjutils/tjutils.h>

/**
  * @addtogroup tjutils
  * @{
  */

#ifndef PII
#define PII 3.14159265358979323846264338327950288
#endif

#ifndef ODIN_MAXCHAR
#define ODIN_MAXCHAR 4096
#endif

#ifdef HAVE_LONG_LONG
#define LONGEST_INT long long
#else
#define LONGEST_INT long
#endif


// functions of large file extension, define them here so
// these macros can re-used in other modules
#ifdef HAVE_STAT64
#define STAT stat64
#else
#ifdef HAVE_STAT 
#define STAT stat
#endif
#endif

#ifdef HAVE_OPEN64
#define OPEN open64
#else
#define OPEN open
#endif

#ifdef HAVE_FOPEN64
#define FOPEN fopen64
#else
#define FOPEN fopen
#endif

#ifdef HAVE_FSEEKO64
#define FSEEK fseeko64
#else
#ifdef HAVE_FSEEKO
#define FSEEK fseeko
#else
#define FSEEK fseek
#endif
#endif

#ifdef HAVE_FTELLO64
#define FTELL ftello64
#else
#ifdef HAVE_FTELLO
#define FTELL ftello
#else
#define FTELL ftell
#endif
#endif

#ifdef HAVE_MMAP64
#define MMAP mmap64
#else
#define MMAP mmap
#endif


/**
  *
  * Mode flag when reading/writing raw data to disk:
  * - readMode: Read-only access
  * - overwriteMode: If a file with the same name already exists, it is overwritten
  * - appendMode: If a file with the same name already exists, the data is appended
  */
enum fopenMode {readMode,overwriteMode,appendMode};


/**
  * Norm of a double vector
  */
double norm(double x, double y);


/**
  * Norm of a triple vector
  */
double norm3(double x,double y,double z);



/**
  *
  * Maximum value of 3 numbers
  */
double maxof3(double f1, double f2, double f3);


#ifndef NO_FILEHANDLING


/**
  * 
  * Returns mode string suitable for fopen according to 'mode'
  */
const char* modestring(fopenMode mode);


/**
  * 
  * Returns file size in bytes if file exists, otherwise -1
  */
LONGEST_INT filesize(const char *filename);


/**
  *
  * Returns the current directory of the process
  */
const char* getpwd();


/**
  *
  * Changes the current directory of the process to dirname. On success, zero is returned.  On error, -1 is returned.
  */
int chpwd(const char *dirname);


/**
  *
  * Creates the given directory. On success, zero is returned.  On error, -1 is returned.
  */
int createdir(const char *dirname);


/**
  *
  * Returns true if directory 'dirname' exists, otherwise false
  */
bool checkdir(const char *dirname);


/**
  *
  * Moves a file 'src' to destination 'dst'. On success, zero is returned.  On error, -1 is returned.
  */
int movefile(const char *src, const char* dst);


/**
  *
  * Copies a file 'src' to destination 'dst'. On success, zero is returned.  On error, -1 is returned.
  */
int copyfile(const char *src, const char* dst);


/**
  *
  * Removes the file or directory 'fname'. On success, zero is returned.  On error, -1 is returned.
  */
int rmfile(const char *fname);


/**
  *
  * Changes permissions of file 'fname' to 'perm'. On success, zero is returned.  On error, -1 is returned.
  */
int chperm(const char *fname, int perm);



/**
  *
  * Creates a file mapping of file 'filename' with 'nbytes' length starting at 'offset' bytes into the file,
  * optionally in 'readonly' mode.
  * The 'fd' will hold the file descriptor (handle) of the mapped file.
  * Returns a pointer to the mapped memory region.
  */
void* filemap(const STD_string& filename, LONGEST_INT nbytes, LONGEST_INT offset, bool readonly, int& fd);


/**
  *
  * Deletes a file mapping of file descriptor 'fd' which maps a region at memory location 'start' of 'nbytes' length
  * starting at 'offset' bytes into the file.
  */
void fileunmap(int fd, void* start, LONGEST_INT nbytes, LONGEST_INT offset);


/**
  *
  * Return a unique name for a temporary file.
  */
STD_string tempfile();


/**
  *
  * Create an empty file, filled with zeroes. Overwrite or append according to 'mode'.
  *   On error, -1 is returned.
  */
int create_empty_file(const STD_string& filename, LONGEST_INT nbytes, fopenMode mode=overwriteMode);


#endif


/**
  *
  * Returns the last system error as a string
  */
const char* lasterr();


/**
  *
  * Halt process/thread for 'ms' miliseconds.
  */
void sleep_ms(unsigned int ms);


/**
  *
  * Returns the current time in s
  */
double current_time_s();


/**
  *
  * If denominator is zero the functions returns 0, otherwise numerator/denominator
  */
double secureDivision(double numerator, double denominator);

/**
  *
  * If denominator is zero the functions returns 0, otherwise 1/denominator
  */
inline double secureInv(double denominator) {return secureDivision(1.0, denominator); }



/**
  *
  * Same as getenv, but returns empty string instead of NULL if variable is not found
  */
const char* getenv_nonnull(const char* variable_name);


/**
  *
  * Returns true if the current platform has little endian byte order, otherwise false
  */
bool little_endian_byte_order();

/**
  *
  * Returns the number of (virtual) CPUs
  */
unsigned int numof_cores();

/**
  *
  * Returns sinc function with accurate results for small x
  * (in contrast to using sin(x)/x directly)
  */
double sinc(double x);


#ifndef NO_CMDLINE

/**
  *
  * Copies maximum of 'maxchar' characters from the argv[] which
  * follows an argv[] that matches 'option' into 'returnvalue';
  * returns TRUE if successful; 'maxchar' should NOT be greater
  * than the number of bytes allocated for 'returnvalue' even if
  * the number of chars in argv[] is smaller.
  * If 'modify' is true, remove argument from the list.
  */
int getCommandlineOption(int argc, char *argv[], const char *option, char *returnvalue, int maxchar,bool modify=true);


/**
  *
  * Returns TRUE if 'option' is found in argv[]
  * If 'modify' is true, remove argument from the list.
  */
int isCommandlineOption(int argc, char *argv[], const char *option,bool modify=true);


/**
  *
  * Copies maximum of 'maxchar' characters from the last argv[]
  * that DOESN'T start with '-' into 'returnvalue';
  * returns TRUE if successful; 'maxchar' should NOT be greater
  * than the number of bytes allocated for 'returnvalue' even if
  * the number of chars in argv[] is smaller
  */
int getLastArgument(int argc, char *argv[], char *returnvalue, int maxchar,bool modify=true);


/**
  *
  * Returns whether one of the options '-h, -help, --help or --version' was given
  */
int hasHelpOption(int argc, char *argv[]);

/**
  *
  * Returns description of the standard help, version options
  */
const char* helpUsage();

#endif


/** @}
  */
#endif