Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/Unix/Unix.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file defines things specific to Unix implementations.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_LIB_SUPPORT_UNIX_UNIX_H
14
#define LLVM_LIB_SUPPORT_UNIX_UNIX_H
15
16
//===----------------------------------------------------------------------===//
17
//=== WARNING: Implementation here must contain only generic UNIX code that
18
//===          is guaranteed to work on all UNIX variants.
19
//===----------------------------------------------------------------------===//
20
21
#include "llvm/Config/config.h"
22
#include "llvm/Support/Chrono.h"
23
#include "llvm/Support/Errno.h"
24
#include <algorithm>
25
#include <assert.h>
26
#include <cerrno>
27
#include <cstdio>
28
#include <cstdlib>
29
#include <cstring>
30
#include <string>
31
#include <sys/types.h>
32
#include <sys/wait.h>
33
34
#ifdef HAVE_UNISTD_H
35
#include <unistd.h>
36
#endif
37
38
#ifdef HAVE_SYS_PARAM_H
39
#include <sys/param.h>
40
#endif
41
42
#ifdef HAVE_SYS_TIME_H
43
# include <sys/time.h>
44
#endif
45
#include <time.h>
46
47
#ifdef HAVE_DLFCN_H
48
# include <dlfcn.h>
49
#endif
50
51
#ifdef HAVE_FCNTL_H
52
# include <fcntl.h>
53
#endif
54
55
/// This function builds an error message into \p ErrMsg using the \p prefix
56
/// string and the Unix error number given by \p errnum. If errnum is -1, the
57
/// default then the value of errno is used.
58
/// Make an error message
59
///
60
/// If the error number can be converted to a string, it will be
61
/// separated from prefix by ": ".
62
static inline bool MakeErrMsg(
63
1
  std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
64
1
  if (!ErrMsg)
65
0
    return true;
66
1
  if (errnum == -1)
67
0
    errnum = errno;
68
1
  *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
69
1
  return true;
70
1
}
Unexecuted instantiation: RandomNumberGenerator.cpp:MakeErrMsg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
Unexecuted instantiation: Host.cpp:MakeErrMsg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
Unexecuted instantiation: Path.cpp:MakeErrMsg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
Unexecuted instantiation: Process.cpp:MakeErrMsg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
Program.cpp:MakeErrMsg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
Line
Count
Source
63
1
  std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
64
1
  if (!ErrMsg)
65
0
    return true;
66
1
  if (errnum == -1)
67
0
    errnum = errno;
68
1
  *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
69
1
  return true;
70
1
}
Unexecuted instantiation: Signals.cpp:MakeErrMsg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
71
72
namespace llvm {
73
namespace sys {
74
75
/// Convert a struct timeval to a duration. Note that timeval can be used both
76
/// as a time point and a duration. Be sure to check what the input represents.
77
21.6k
inline std::chrono::microseconds toDuration(const struct timeval &TV) {
78
21.6k
  return std::chrono::seconds(TV.tv_sec) +
79
21.6k
         std::chrono::microseconds(TV.tv_usec);
80
21.6k
}
81
82
/// Convert a time point to struct timespec.
83
26
inline struct timespec toTimeSpec(TimePoint<> TP) {
84
26
  using namespace std::chrono;
85
26
86
26
  struct timespec RetVal;
87
26
  RetVal.tv_sec = toTimeT(TP);
88
26
  RetVal.tv_nsec = (TP.time_since_epoch() % seconds(1)).count();
89
26
  return RetVal;
90
26
}
91
92
/// Convert a time point to struct timeval.
93
0
inline struct timeval toTimeVal(TimePoint<std::chrono::microseconds> TP) {
94
0
  using namespace std::chrono;
95
0
96
0
  struct timeval RetVal;
97
0
  RetVal.tv_sec = toTimeT(TP);
98
0
  RetVal.tv_usec = (TP.time_since_epoch() % seconds(1)).count();
99
0
  return RetVal;
100
0
}
101
102
} // namespace sys
103
} // namespace llvm
104
105
#endif