00001 00002 00003 00004 00005 00006 00007 // =========================================================== 00008 // 00009 // Copyright (C) 2005-2007, all rights reserved by 00010 // - Institute of Telematics, Universitaet Karlsruhe (TH) 00011 // 00012 // More information and contact: 00013 // https://projekte.tm.uka.de/trac/NSIS 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; version 2 of the License 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License along 00025 // with this program; if not, write to the Free Software Foundation, Inc., 00026 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00027 // 00028 // =========================================================== 00035 #include <sys/time.h> 00036 #include <unistd.h> 00037 00038 /* struct timezone tz = { 0, DST_NONE }; */ 00039 static struct timeval tv; 00040 typedef int clockid_t; 00041 00042 /* syntax for clock_gettime: 00043 int clock_gettime (clockid_t clock_id, struct timespec *tp); 00044 00045 to supply it include the following (because of speed): 00046 extern int eclock_gettime(struct timespec *tp); 00047 #define clock_gettime(clock_id, tspec) eclock_gettime(tspec) 00048 */ 00049 00050 int eclock_gettime(struct timespec *tp) 00051 { 00052 /* DESCRIPTION 00053 00054 The clock_gettime function returns the current time (in seconds and 00055 nanoseconds) for the specified clock. The clock_settime function sets the 00056 specified clock. The CLOCK_REALTIME clock measures the amount of time 00057 elapsed since 00:00:00:00 January 1, 1970 Greenwich Mean Time (GMT), other- 00058 wise known as the Epoch. Time values that fall between two non-negative 00059 integer multiples of the resolution are truncated down to the smaller mul- 00060 tiple of the resolution. 00061 00062 */ 00063 if (gettimeofday(&tv, 0) == 0) 00064 { 00065 #ifdef DEBUG 00066 if (tp) 00067 #endif 00068 { 00069 tp->tv_sec= tv.tv_sec; 00070 tp->tv_nsec= tv.tv_usec*1000; 00071 return 0; 00072 } 00073 } 00074 else 00075 return -1; 00076 } 00077