add convenience function to get the output of strerror(errno) as c++ string
This commit is contained in:
@ -14,6 +14,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cerrno>
|
||||||
#include "lammps.h"
|
#include "lammps.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
@ -99,6 +100,14 @@ void utils::logmesg(LAMMPS *lmp, const std::string &mesg)
|
|||||||
if (lmp->logfile) fputs(mesg.c_str(), lmp->logfile);
|
if (lmp->logfile) fputs(mesg.c_str(), lmp->logfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* define this here, so we won't have to include the headers
|
||||||
|
everywhere and utils.h will more likely be included anyway. */
|
||||||
|
|
||||||
|
std::string utils::getsyserror()
|
||||||
|
{
|
||||||
|
return std::string(strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief try to detect pathname from FILE pointer. Currently only supported on Linux, otherwise will report "(unknown)".
|
/** \brief try to detect pathname from FILE pointer. Currently only supported on Linux, otherwise will report "(unknown)".
|
||||||
*
|
*
|
||||||
* \param buf storage buffer for pathname. output will be truncated if not large enough
|
* \param buf storage buffer for pathname. output will be truncated if not large enough
|
||||||
|
|||||||
@ -43,6 +43,14 @@ namespace LAMMPS_NS {
|
|||||||
*/
|
*/
|
||||||
void logmesg(LAMMPS *lmp, const std::string &mesg);
|
void logmesg(LAMMPS *lmp, const std::string &mesg);
|
||||||
|
|
||||||
|
/** \brief return a string representing the current system error status
|
||||||
|
*
|
||||||
|
* This is a wrapper around calling strerror(errno).
|
||||||
|
*
|
||||||
|
* \return error string
|
||||||
|
*/
|
||||||
|
std::string getsyserror();
|
||||||
|
|
||||||
/** \brief safe wrapper around fgets() which aborts on errors
|
/** \brief safe wrapper around fgets() which aborts on errors
|
||||||
* or EOF and prints a suitable error message to help debugging
|
* or EOF and prints a suitable error message to help debugging
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user