Coverage Report

Created: 2017-10-03 07:32

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