• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MikkelSchubert / adapterremoval / #46

27 Nov 2024 03:10PM UTC coverage: 27.245% (+1.0%) from 26.244%
#46

push

travis-ci

MikkelSchubert
fix convenience executable make target

2609 of 9576 relevant lines covered (27.25%)

4268.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/errors.cpp
1
/*************************************************************************\
2
 * AdapterRemoval - cleaning next-generation sequencing reads            *
3
 *                                                                       *
4
 * Copyright (C) 2024 by Mikkel Schubert - mikkelsch@gmail.com           *
5
 *                                                                       *
6
 * This program is free software: you can redistribute it and/or modify  *
7
 * it under the terms of the GNU General Public License as published by  *
8
 * the Free Software Foundation, either version 3 of the License, or     *
9
 * (at your option) any later version.                                   *
10
 *                                                                       *
11
 * This program is distributed in the hope that it will be useful,       *
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 * GNU General Public License for more details.                          *
15
 *                                                                       *
16
 * You should have received a copy of the GNU General Public License     *
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
18
\*************************************************************************/
19

20
#include "errors.hpp" // declarations
21
#include <array>      // for array
22
#include <cerrno>     // for errno
23
#include <cstdio>     // for sys_errlist, sys_nerr
24
#include <cstring>    // for strerror_r
25
#include <sstream>    // for operator<<, basic_ostream
26
#include <string>     // for string
27

28
namespace adapterremoval {
29

30
// The function signature of strerror_r depends on the libc used. Rather than
31
// attempting to match defines, simply select the appropriate wrapper based on
32
// the signature of the function
33
using glibc_strerror_r = char* (*)(int, char*, size_t);
34
using posix_strerror_r = int (*)(int, char*, size_t);
35
//! Recommended buffer size according to `strerror` man page
36
using strerror_buf = std::array<char, 1024>;
37

38
std::string
39
strerror_r_wrapper(glibc_strerror_r f, int error_number)
×
40
{
41
  strerror_buf buf{};
×
42
  return f(error_number, buf.data(), buf.size());
×
43
}
44

45
std::string
46
strerror_r_wrapper(posix_strerror_r f, int error_number)
×
47
{
48
  strerror_buf buf{};
×
49
  if (f(error_number, buf.data(), buf.size())) {
×
50
    return "unknown error " + std::to_string(error_number);
×
51
  }
52

53
  return buf.data();
×
54
}
55

56
std::string
57
format_io_error(const std::string& message, const int error_number)
×
58
{
59
  if (error_number) {
×
60
    std::ostringstream stream;
×
61
    stream << message << " ('" << strerror_r_wrapper(::strerror_r, error_number)
×
62
           << "')";
×
63

64
    return stream.str();
×
65
  } else {
×
66
    return message;
×
67
  }
68
}
69

70
} // namespace adapterremoval
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc