Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
38b3ecb0
Commit
38b3ecb0
authored
Jun 01, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use fmt::safe_strerror
parent
f2bc1571
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
53 deletions
+14
-53
include/spdlog/common.h
include/spdlog/common.h
+12
-1
include/spdlog/details/os.h
include/spdlog/details/os.h
+2
-52
No files found.
include/spdlog/common.h
View file @
38b3ecb0
...
...
@@ -158,7 +158,18 @@ public:
spdlog_ex
(
const
std
::
string
&
msg
,
int
last_errno
)
{
_msg
=
msg
+
": "
+
details
::
os
::
errno_str
(
last_errno
);
std
::
string
errno_string
;
char
buf
[
256
],
*
buf_ptr
=
buf
;
if
(
fmt
::
safe_strerror
(
last_errno
,
buf_ptr
,
sizeof
(
buf
))
==
0
)
{
errno_string
=
buf_ptr
;
}
else
{
errno_string
=
"Unknown error"
;
}
_msg
=
msg
+
": "
+
errno_string
;
}
const
char
*
what
()
const
SPDLOG_NOEXCEPT
override
...
...
include/spdlog/details/os.h
View file @
38b3ecb0
...
...
@@ -4,7 +4,7 @@
//
#pragma once
#include "
spdlog
/common.h"
#include "
..
/common.h"
#include <algorithm>
#include <chrono>
...
...
@@ -13,7 +13,6 @@
#include <cstring>
#include <ctime>
#include <functional>
#include <mutex>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
...
...
@@ -283,7 +282,7 @@ inline int utc_minutes_offset(const std::tm &tm = details::os::localtime())
return
offset
;
#else
#if defined(sun) || defined(__sun)
#if defined(sun) || defined(__sun)
|| defined(_AIX)
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
struct
helper
{
...
...
@@ -384,54 +383,6 @@ inline std::string filename_to_str(const filename_t &filename)
}
#endif
inline
std
::
string
errno_to_string
(
char
[
256
],
char
*
res
)
{
return
std
::
string
(
res
);
}
inline
std
::
string
errno_to_string
(
char
buf
[
256
],
int
res
)
{
if
(
res
==
0
)
{
return
std
::
string
(
buf
);
}
return
"Unknown error"
;
}
// Return errno string (thread safe)
inline
std
::
string
errno_str
(
int
err_num
)
{
char
buf
[
256
];
SPDLOG_CONSTEXPR
auto
buf_size
=
sizeof
(
buf
);
#ifdef _WIN32
if
(
strerror_s
(
buf
,
buf_size
,
err_num
)
==
0
)
{
return
std
::
string
(
buf
);
}
else
{
return
"Unknown error"
;
}
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(ANDROID) || defined(__SUNPRO_CC) || \
((_POSIX_C_SOURCE >= 200112L) && !defined(_GNU_SOURCE)) // posix version
if
(
strerror_r
(
err_num
,
buf
,
buf_size
)
==
0
)
{
return
std
::
string
(
buf
);
}
else
{
return
"Unknown error"
;
}
#else // gnu version (might not use the given buf, so its retval pointer must be used)
auto
err
=
strerror_r
(
err_num
,
buf
,
buf_size
);
// let compiler choose type
return
errno_to_string
(
buf
,
err
);
// use overloading to select correct stringify function
#endif
}
inline
int
pid
()
{
...
...
@@ -475,7 +426,6 @@ inline bool in_terminal(FILE *file)
return
isatty
(
fileno
(
file
))
!=
0
;
#endif
}
}
// namespace os
}
// namespace details
}
// namespace spdlog
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment