LLVM API Documentation
00001 //===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Reid Spencer and is distributed under the 00006 // University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the Unix specific portion of the TimeValue class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 //===----------------------------------------------------------------------===// 00015 //=== WARNING: Implementation here must contain only generic UNIX code that 00016 //=== is guaranteed to work on *all* UNIX variants. 00017 //===----------------------------------------------------------------------===// 00018 00019 #include "Unix.h" 00020 00021 namespace llvm { 00022 using namespace sys; 00023 00024 std::string TimeValue::toString() const { 00025 char buffer[32]; 00026 00027 time_t ourTime = time_t(this->toEpochTime()); 00028 #ifdef __hpux 00029 // note that the following line needs -D_REENTRANT on HP-UX to be picked up 00030 asctime_r(localtime(&ourTime), buffer); 00031 #else 00032 ::asctime_r(::localtime(&ourTime), buffer); 00033 #endif 00034 00035 std::string result(buffer); 00036 return result.substr(0,24); 00037 } 00038 00039 TimeValue TimeValue::now() { 00040 struct timeval the_time; 00041 timerclear(&the_time); 00042 if (0 != ::gettimeofday(&the_time,0)) 00043 ThrowErrno("Couldn't obtain time of day"); 00044 00045 return TimeValue( 00046 static_cast<TimeValue::SecondsType>( the_time.tv_sec ), 00047 static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * 00048 NANOSECONDS_PER_MICROSECOND ) ); 00049 } 00050 00051 }