File indexing completed on 2025-01-18 09:52:31
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_STACKTRACE_DETAIL_SAFE_DUMP_POSIX_IPP
0008 #define BOOST_STACKTRACE_DETAIL_SAFE_DUMP_POSIX_IPP
0009
0010 #include <boost/config.hpp>
0011 #ifdef BOOST_HAS_PRAGMA_ONCE
0012 # pragma once
0013 #endif
0014
0015 #include <boost/stacktrace/safe_dump_to.hpp>
0016
0017 #include <unistd.h> // ::write
0018 #include <fcntl.h> // ::open
0019 #include <sys/stat.h> // S_IWUSR and friends
0020
0021
0022 namespace boost { namespace stacktrace { namespace detail {
0023
0024 std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept {
0025
0026
0027
0028
0029 if (::write(fd, frames, sizeof(native_frame_ptr_t) * frames_count) == -1) {
0030 return 0;
0031 }
0032
0033 return frames_count;
0034 }
0035
0036 std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept {
0037 const int fd = ::open(
0038 file,
0039 O_CREAT | O_WRONLY | O_TRUNC,
0040 #if defined(S_IWUSR) && defined(S_IRUSR)
0041 S_IWUSR | S_IRUSR
0042 #elif defined(S_IWRITE) && defined(S_IREAD)
0043 S_IWRITE | S_IREAD
0044 #else
0045 0
0046 #endif
0047 );
0048 if (fd == -1) {
0049 return 0;
0050 }
0051
0052 const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
0053 ::close(fd);
0054 return size;
0055 }
0056
0057 }}}
0058
0059 #endif