LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Unix/TimeValue.cpp

Go to the documentation of this file.
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 #include <time.h>
00022 #include <sys/time.h>
00023 
00024 namespace llvm {
00025   using namespace sys;
00026 
00027 
00028 std::string TimeValue::toString() const {
00029   char buffer[32];
00030 
00031   time_t ourTime = time_t(this->toEpochTime());
00032   ::asctime_r(::localtime(&ourTime), buffer);
00033 
00034   std::string result(buffer);
00035   return result.substr(0,24);
00036 }
00037 
00038 TimeValue TimeValue::now() {
00039   struct timeval the_time;
00040   timerclear(&the_time);
00041   if (0 != ::gettimeofday(&the_time,0)) 
00042     ThrowErrno("Couldn't obtain time of day");
00043 
00044   return TimeValue(
00045     static_cast<TimeValue::SecondsType>( the_time.tv_sec ), 
00046     static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * 
00047       NANOSECONDS_PER_MICROSECOND ) );
00048 }
00049 
00050 }
00051 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab