Flow123d  release_1.8.2-1603-g0109a2b
Classes | Functions | Variables
system.cc File Reference

Various system-wide functions. More...

#include <cstring>
#include <cstdarg>
#include <ctime>
#include <cstdlib>
#include <sys/stat.h>
#include <cerrno>
#include <sstream>
#include <fstream>
#include <string>
#include "mpi.h"
#include "system/system.hh"
#include "system/xio.h"
#include "system/file_path.hh"
#include "system/sys_profiler.hh"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/format.hpp>

Go to the source code of this file.

Classes

struct  MsgFmt
 INTERNAL DEFINITIONS FOR XPRINTF. More...
 

Functions

int _xprintf (const char *const xprintf_file, const char *const xprintf_func, const int xprintf_line, MessageType type, const char *const fmt,...)
 Multi-purpose printing routine: messages, warnings, errors. More...
 
void * xmalloc (size_t size)
 Memory allocation with checking. More...
 
void * xrealloc (void *ptr, size_t size)
 Reallocation of memory block with checking. More...
 
int xsystem (const char *cmd)
 SYSTEM with err handling. More...
 
char * xstrcpy (const char *src)
 MAKE BRAND NEW COPY OF STRING. More...
 
char * xstrtok (char *s, int position)
 STRTOK WITH ERROR HANDLING and whitespace delimiters. More...
 
char * xstrtok (char *s1, const char *delim, int position)
 STRTOK WITH ERROR HANDLING and user specified delimiters. More...
 
int xchomp (char *s)
 Delete trailing whitespace characters (space,tab,CR,NL). More...
 
int xmkdir (const char *s)
 MKDIR WITH ERROR HANDLING. More...
 
int xrmdir (const char *s)
 RMDIR with err handling. More...
 
int xchdir (const char *s)
 CHDIR WITH ERROR HANDLING. More...
 
int xremove (const char *fname)
 DELETE a FILE with error handling. More...
 
char * xgetcwd (void)
 GET CURRENT WORKING DIRECTORY with error handling. More...
 

Variables

SystemInfo sys_info
 
#define SCR_NONE   0
 
#define SCR_STDOUT   1
 
#define SCR_STDERR   2
 
#define NUM_OF_FMTS   8
 
static struct MsgFmt msg_fmt []
 

Detailed Description

Various system-wide functions.

 * Copyright (C) 2015 Technical University of Liberec. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Definition in file system.cc.

Macro Definition Documentation

#define NUM_OF_FMTS   8

configuration table for individual message types defined in system.h Msg type Log mpi screen Stop message header

Definition at line 63 of file system.cc.

#define SCR_NONE   0

Definition at line 57 of file system.cc.

#define SCR_STDERR   2

Definition at line 59 of file system.cc.

#define SCR_STDOUT   1

Definition at line 58 of file system.cc.

Function Documentation

int _xprintf ( const char *const  xprintf_file,
const char *const  xprintf_func,
const int  xprintf_line,
MessageType  type,
const char *const  fmt,
  ... 
)

Multi-purpose printing routine: messages, warnings, errors.

Parameters
[in]xprintf_filecurrent file
[in]xprintf_funccurrent function
[in]xprintf_linecurrent line number
[in]typemessage type
[in]fmtmessage format
Returns
Same as printf, what internal printing routine returns.

Definition at line 86 of file system.cc.

int xchdir ( const char *  s)

CHDIR WITH ERROR HANDLING.

Change directory (GLIBC function, original in <unistd.h>)

Definition at line 406 of file system.cc.

int xchomp ( char *  s)

Delete trailing whitespace characters (space,tab,CR,NL).

Parameters
[in,out]sstring to change
Returns
number of deleted characters

Definition at line 350 of file system.cc.

char* xgetcwd ( void  )

GET CURRENT WORKING DIRECTORY with error handling.

Get current working directory (GLIBC function, original in <unistd.h>)

Definition at line 438 of file system.cc.

void* xmalloc ( size_t  size)

Memory allocation with checking.

Allocates memory block with checking of correct size and successful allocation.

Parameters
[in]sizeNew size for the memory block, in bytes.
Returns
same as ISO C realloc()

Definition at line 198 of file system.cc.

Here is the caller graph for this function:

int xmkdir ( const char *  s)

MKDIR WITH ERROR HANDLING.

Operations on files and directories.

Definition at line 377 of file system.cc.

void* xrealloc ( void *  ptr,
size_t  size 
)

Reallocation of memory block with checking.

Reallocates memory block with checking of successful reallocation. The size of the memory block pointed to by the ptr parameter is changed to the size bytes, expanding or reducing the amount of memory available in the block.

The function may move the memory block to a new location, in which case the new location is returned. The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved. If the new size is larger, the value of the newly allocated portion is indeterminate.

In case that ptr is NULL, the function behaves exactly as malloc, assigning a new block of size bytes and returning a pointer to the beginning of it.

In case that the size is 0, the memory previously allocated in ptr is deallocated as if a call to free was made, and a NULL pointer is returned.

Parameters
[in]ptrPointer to a memory block previously allocated
[in]sizeNew size for the memory block, in bytes.
Returns
same as ISO C realloc()

Definition at line 232 of file system.cc.

Here is the caller graph for this function:

int xremove ( const char *  fname)

DELETE a FILE with error handling.

Remove file or directory (function)

Definition at line 419 of file system.cc.

int xrmdir ( const char *  s)

RMDIR with err handling.

Definition at line 393 of file system.cc.

char* xstrcpy ( const char *  src)

MAKE BRAND NEW COPY OF STRING.

Definition at line 280 of file system.cc.

Here is the caller graph for this function:

char* xstrtok ( char *  s,
int  position 
)

STRTOK WITH ERROR HANDLING and whitespace delimiters.

Parameters
[in]sstrtok string pointer
[in]positionrequested position of the token
Returns
strtok return

Definition at line 298 of file system.cc.

Here is the caller graph for this function:

char* xstrtok ( char *  s1,
const char *  delim,
int  position 
)

STRTOK WITH ERROR HANDLING and user specified delimiters.

Parameters
[in]s1strtok string pointer
[in]delimdelimiters
[in]positionrequested position of the token
Returns
strtok return

Function behaves like original strtok

Definition at line 316 of file system.cc.

int xsystem ( const char *  cmd)

SYSTEM with err handling.

Definition at line 268 of file system.cc.

Variable Documentation

struct MsgFmt msg_fmt[]
static
Initial value:
= {
{Msg, true, false, SCR_STDOUT, false, NULL},
{MsgDbg, true, false, SCR_STDOUT, false, " DBG (%s, %s(), %d):"},
{MsgLog, true, false, SCR_NONE, false, NULL},
{MsgVerb, false, false, SCR_STDOUT, false, NULL},
{Warn, true, false, SCR_STDERR, false, "\nWarning (%s, %s(), %d):\n"},
{UsrErr, true, false, SCR_NONE, true, "\nUser Error (%s, %s(), %d):\n"},
{Err, true, false, SCR_NONE, true, "\nError (%s, %s(), %d):\n"},
{PrgErr, true, false, SCR_NONE, true, "\nInternal Error (%s, %s(), %d):\n"}
}
Definition: system.hh:59
Definition: system.hh:59
Definition: system.hh:59
#define SCR_STDOUT
Definition: system.cc:58
#define SCR_NONE
Definition: system.cc:57
Definition: system.hh:59
Definition: system.hh:59
Definition: system.hh:59
Definition: system.hh:59
#define SCR_STDERR
Definition: system.cc:59

Definition at line 64 of file system.cc.

SystemInfo sys_info

Definition at line 42 of file system.cc.