LLVM: lib/Support/Unix/Unix.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_LIB_SUPPORT_UNIX_UNIX_H
14#define LLVM_LIB_SUPPORT_UNIX_UNIX_H
15
16
17
18
19
20
21#include "llvm/Config/config.h"
25#include <assert.h>
26#include
27#include
28#include
29#include
30#include
31#include <sys/types.h>
32#include <sys/wait.h>
33
34#ifdef HAVE_UNISTD_H
35#include <unistd.h>
36#endif
37
38#include <sys/time.h>
39#include <time.h>
40
41#include <dlfcn.h>
42
43# include <fcntl.h>
44
45
46
47
48
49
50
51
53 std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
54 if (!ErrMsg)
55 return true;
56 if (errnum == -1)
57 errnum = errno;
59 return true;
60}
61
62
63[[noreturn]] static inline void ReportErrnumFatal(const char *Msg, int errnum) {
64 std::string ErrMsg;
67}
68
69namespace llvm {
70namespace sys {
71
72
73
74inline std::chrono::microseconds toDuration(const struct timeval &TV) {
75 return std::chrono::seconds(TV.tv_sec) +
76 std::chrono::microseconds(TV.tv_usec);
77}
78
79
81 using namespace std::chrono;
82
83 struct timespec RetVal;
84 RetVal.tv_sec = toTimeT(TP);
85 RetVal.tv_nsec = (TP.time_since_epoch() % seconds(1)).count();
86 return RetVal;
87}
88
89
91 using namespace std::chrono;
92
93 struct timeval RetVal;
94 RetVal.tv_sec = toTimeT(TP);
95 RetVal.tv_usec = (TP.time_since_epoch() % seconds(1)).count();
96 return RetVal;
97}
98
99}
100}
101
102#endif
static bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix, int errnum=-1)
This function builds an error message into ErrMsg using the prefix string and the Unix error number g...
Definition Unix.h:52
static void ReportErrnumFatal(const char *Msg, int errnum)
Definition Unix.h:63
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::chrono::nanoseconds toDuration(FILETIME Time)
LLVM_ABI std::string StrError()
Returns a string representation of the errno value, using whatever thread-safe variant of strerror() ...
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
struct timespec toTimeSpec(TimePoint<> TP)
Convert a time point to struct timespec.
Definition Unix.h:80
struct timeval toTimeVal(TimePoint< std::chrono::microseconds > TP)
Convert a time point to struct timeval.
Definition Unix.h:90
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Implement std::hash so that hash_code can be used in STL containers.