OSDN Git Service

Add SwiftShader source to repo
[android-x86/external-swiftshader.git] / src / LLVM / lib / System / Unix / TimeValue.inc
1 //===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===//\r
2 // \r
3 //                     The LLVM Compiler Infrastructure\r
4 //\r
5 // This file is distributed under the University of Illinois Open Source\r
6 // License. See LICENSE.TXT for details.\r
7 // \r
8 //===----------------------------------------------------------------------===//\r
9 //\r
10 // This file implements the Unix specific portion of the TimeValue class.\r
11 //\r
12 //===----------------------------------------------------------------------===//\r
13 \r
14 //===----------------------------------------------------------------------===//\r
15 //=== WARNING: Implementation here must contain only generic UNIX code that\r
16 //===          is guaranteed to work on *all* UNIX variants.\r
17 //===----------------------------------------------------------------------===//\r
18 \r
19 #include "Unix.h"\r
20 \r
21 namespace llvm {\r
22   using namespace sys;\r
23 \r
24 std::string TimeValue::str() const {\r
25   char buffer[32];\r
26 \r
27   time_t ourTime = time_t(this->toEpochTime());\r
28 #ifdef __hpux\r
29 // note that the following line needs -D_REENTRANT on HP-UX to be picked up \r
30   asctime_r(localtime(&ourTime), buffer);\r
31 #else\r
32   ::asctime_r(::localtime(&ourTime), buffer);\r
33 #endif\r
34 \r
35   std::string result(buffer);\r
36   return result.substr(0,24);\r
37 }\r
38 \r
39 TimeValue TimeValue::now() {\r
40   struct timeval the_time;\r
41   timerclear(&the_time);\r
42   if (0 != ::gettimeofday(&the_time,0)) {\r
43     // This is *really* unlikely to occur because the only gettimeofday\r
44     // errors concern the timezone parameter which we're passing in as 0.\r
45     // In the unlikely case it does happen, just return MinTime, no error\r
46     // message needed. \r
47     return MinTime;\r
48   }\r
49 \r
50   return TimeValue(\r
51     static_cast<TimeValue::SecondsType>( the_time.tv_sec + PosixZeroTime.seconds_ ), \r
52     static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * \r
53       NANOSECONDS_PER_MICROSECOND ) );\r
54 }\r
55 \r
56 }\r