Flow123d  jenkins-Flow123d-windows32-release-multijob-51
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 <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...
 
void * operator new (std::size_t size) OPERATOR_NEW_THROW_EXCEPTION
 test & free memory More...
 
void * operator new[] (std::size_t size) OPERATOR_NEW_THROW_EXCEPTION
 
void * operator new[] (std::size_t size, const std::nothrow_t &) throw ()
 
void operator delete (void *p) throw ()
 
void operator delete[] (void *p) throw ()
 
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) 2007 Technical University of Liberec. All rights reserved.

Please make a following refer to Flow123d on your project site if you use the program for any purpose, especially for academic research: Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic

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.

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.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.

$Id$ $Revision$ $LastChangedBy$ $LastChangedDate$

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 74 of file system.cc.

#define SCR_NONE   0

Definition at line 68 of file system.cc.

#define SCR_STDERR   2

Definition at line 70 of file system.cc.

#define SCR_STDOUT   1

Definition at line 69 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 97 of file system.cc.

void operator delete ( void *  p)
throw (
)

Definition at line 285 of file system.cc.

void operator delete[] ( void *  p)
throw (
)

Definition at line 290 of file system.cc.

void* operator new ( std::size_t  size)

test & free memory

Replacement of new/delete operator in the spirit of xmalloc.

Up to my knowledge overloading of original new/delete is the only clean. Possibly disadvantage is that all 'new' calls in system and other templates become also overloaded.

Definition at line 273 of file system.cc.

void* operator new[] ( std::size_t  size)

Definition at line 277 of file system.cc.

void* operator new[] ( std::size_t  size,
const std::nothrow_t &   
)
throw (
)

Definition at line 281 of file system.cc.

int xchdir ( const char *  s)

CHDIR WITH ERROR HANDLING.

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

Definition at line 438 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 382 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 470 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 209 of file system.cc.

int xmkdir ( const char *  s)

MKDIR WITH ERROR HANDLING.

Operations on files and directories.

Definition at line 409 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 243 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 451 of file system.cc.

int xrmdir ( const char *  s)

RMDIR with err handling.

Definition at line 425 of file system.cc.

char* xstrcpy ( const char *  src)

MAKE BRAND NEW COPY OF STRING.

Definition at line 312 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 330 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 348 of file system.cc.

int xsystem ( const char *  cmd)

SYSTEM with err handling.

Definition at line 300 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, "Warning (%s, %s(), %d):\n"},
{UsrErr, true, false, SCR_NONE, true, "User Error (%s, %s(), %d):\n"},
{Err, true, false, SCR_NONE, true, "Error (%s, %s(), %d):\n"},
{PrgErr, true, false, SCR_NONE, true, "Internal Error (%s, %s(), %d):\n"}
}
Definition: system.hh:72
Definition: system.hh:72
Definition: system.hh:72
#define SCR_STDOUT
Definition: system.cc:69
#define SCR_NONE
Definition: system.cc:68
Definition: system.hh:72
Definition: system.hh:72
Definition: system.hh:72
Definition: system.hh:72
#define SCR_STDERR
Definition: system.cc:70

Definition at line 75 of file system.cc.

SystemInfo sys_info

Definition at line 53 of file system.cc.