summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/tmdiff.c
diff options
context:
space:
mode:
authormarkus <>2002-09-05 12:51:52 +0000
committermarkus <>2002-09-05 12:51:52 +0000
commit5514995a9d5ed91db089875adb509c7781357c0e (patch)
tree2484410a46ba6c05ef94c253da36fbceef990b64 /src/lib/libcrypto/tmdiff.c
parentfd9566423b542798f5c8b06e68101a9ea5bb9885 (diff)
downloadopenbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.gz
openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.bz2
openbsd-5514995a9d5ed91db089875adb509c7781357c0e.zip
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/tmdiff.c')
-rw-r--r--src/lib/libcrypto/tmdiff.c138
1 files changed, 81 insertions, 57 deletions
diff --git a/src/lib/libcrypto/tmdiff.c b/src/lib/libcrypto/tmdiff.c
index b93799fc03..7ebf2b202a 100644
--- a/src/lib/libcrypto/tmdiff.c
+++ b/src/lib/libcrypto/tmdiff.c
@@ -57,41 +57,45 @@
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include <stdlib.h> 59#include <stdlib.h>
60#include "cryptlib.h"
61#include <openssl/tmdiff.h>
60 62
61#ifndef MSDOS 63#ifdef TIMEB
62# ifndef WIN32 64#undef OPENSSL_SYS_WIN32
63# define TIMES 65#undef TIMES
64# endif
65#endif 66#endif
66 67
67#ifndef VMS 68#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) || defined(__DECC) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_VXWORKS)
68# ifndef _IRIX 69# define TIMES
69# include <time.h> 70#endif
70# endif 71
71# ifdef TIMES 72#ifndef _IRIX
72# include <sys/types.h> 73# include <time.h>
73# include <sys/times.h> 74#endif
74# endif 75#ifdef TIMES
75#else /* VMS */ 76# include <sys/types.h>
76# include <types.h> 77# include <sys/times.h>
77 struct tms { 78#endif
78 time_t tms_utime; 79
79 time_t tms_stime; 80/* Depending on the VMS version, the tms structure is perhaps defined.
80 time_t tms_uchild; /* I dunno... */ 81 The __TMS macro will show if it was. If it wasn't defined, we should
81 time_t tms_uchildsys; /* so these names are a guess :-) */ 82 undefine TIMES, since that tells the rest of the program how things
82 } 83 should be handled. -- Richard Levitte */
83#endif /* VMS */ 84#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
84 85#undef TIMES
85#ifdef sun 86#endif
87
88#if defined(sun) || defined(__ultrix)
89#define _POSIX_SOURCE
86#include <limits.h> 90#include <limits.h>
87#include <sys/param.h> 91#include <sys/param.h>
88#endif 92#endif
89 93
90#ifndef TIMES 94#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS)
91#include <sys/timeb.h> 95#include <sys/timeb.h>
92#endif 96#endif
93 97
94#ifdef WIN32 98#ifdef OPENSSL_SYS_WIN32
95#include <windows.h> 99#include <windows.h>
96#endif 100#endif
97 101
@@ -99,11 +103,7 @@
99#ifndef HZ 103#ifndef HZ
100# ifndef CLK_TCK 104# ifndef CLK_TCK
101# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ 105# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
102# ifndef VMS 106# define HZ 100.0
103# define HZ 100.0
104# else /* VMS */
105# define HZ 100.0
106# endif
107# else /* _BSD_CLK_TCK_ */ 107# else /* _BSD_CLK_TCK_ */
108# define HZ ((double)_BSD_CLK_TCK_) 108# define HZ ((double)_BSD_CLK_TCK_)
109# endif 109# endif
@@ -117,57 +117,62 @@ typedef struct ms_tm
117#ifdef TIMES 117#ifdef TIMES
118 struct tms ms_tms; 118 struct tms ms_tms;
119#else 119#else
120# ifdef WIN32 120# ifdef OPENSSL_SYS_WIN32
121 HANDLE thread_id; 121 HANDLE thread_id;
122 FILETIME ms_win32; 122 FILETIME ms_win32;
123# else 123# else
124# ifdef OPENSSL_SYS_VSWORKS
125 unsigned long ticks;
126# else
124 struct timeb ms_timeb; 127 struct timeb ms_timeb;
128# endif
125# endif 129# endif
126#endif 130#endif
127 } MS_TM; 131 } MS_TM;
128 132
129char *ms_time_init() 133char *ms_time_new(void)
130 { 134 {
131 MS_TM *ret; 135 MS_TM *ret;
132 136
133 ret=malloc(sizeof(MS_TM)); 137 ret=(MS_TM *)OPENSSL_malloc(sizeof(MS_TM));
134 if (ret == NULL) 138 if (ret == NULL)
135 return(NULL); 139 return(NULL);
136 memset(ret,0,sizeof(MS_TM)); 140 memset(ret,0,sizeof(MS_TM));
137#ifdef WIN32 141#ifdef OPENSSL_SYS_WIN32
138 ret->thread_id=GetCurrentThread(); 142 ret->thread_id=GetCurrentThread();
139#endif 143#endif
140 return((char *)ret); 144 return((char *)ret);
141 } 145 }
142 146
143void ms_time_final(a) 147void ms_time_free(char *a)
144char *a;
145 { 148 {
146 if (a != NULL) 149 if (a != NULL)
147 free(a); 150 OPENSSL_free(a);
148 } 151 }
149 152
150void ms_time_get(a) 153void ms_time_get(char *a)
151char *a;
152 { 154 {
153 MS_TM *tm=(MS_TM *)a; 155 MS_TM *tm=(MS_TM *)a;
154 FILETIME tmpa,tmpb,tmpc; 156#ifdef OPENSSL_SYS_WIN32
157 FILETIME tmpa,tmpb,tmpc;
158#endif
155 159
156#ifdef TIMES 160#ifdef TIMES
157 printf("AAA\n");
158 times(&tm->ms_tms); 161 times(&tm->ms_tms);
159#else 162#else
160# ifdef WIN32 163# ifdef OPENSSL_SYS_WIN32
161 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32)); 164 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32));
162# else 165# else
163 printf("CCC\n"); 166# ifdef OPENSSL_SYS_VSWORKS
164 ftime(tm->ms_timeb); 167 tm->ticks = tickGet();
168# else
169 ftime(&tm->ms_timeb);
170# endif
165# endif 171# endif
166#endif 172#endif
167 } 173 }
168 174
169double ms_time_diff(ap,bp) 175double ms_time_diff(char *ap, char *bp)
170char *ap,*bp;
171 { 176 {
172 MS_TM *a=(MS_TM *)ap; 177 MS_TM *a=(MS_TM *)ap;
173 MS_TM *b=(MS_TM *)bp; 178 MS_TM *b=(MS_TM *)bp;
@@ -176,20 +181,35 @@ char *ap,*bp;
176#ifdef TIMES 181#ifdef TIMES
177 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ; 182 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
178#else 183#else
179# ifdef WIN32 184# ifdef OPENSSL_SYS_WIN32
180 ret =(double)(b->ms_win32.dwHighDateTime&0x000fffff)*10+ 185 {
181 b->ms_win32.dwLowDateTime/1e7; 186#ifdef __GNUC__
182 ret-=(double)(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; 187 signed long long la,lb;
188#else
189 signed _int64 la,lb;
190#endif
191 la=a->ms_win32.dwHighDateTime;
192 lb=b->ms_win32.dwHighDateTime;
193 la<<=32;
194 lb<<=32;
195 la+=a->ms_win32.dwLowDateTime;
196 lb+=b->ms_win32.dwLowDateTime;
197 ret=((double)(lb-la))/1e7;
198 }
183# else 199# else
184 ret= (double)(b->time-a->time)+ 200# ifdef OPENSSL_SYS_VSWORKS
185 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; 201 ret = (double)(b->ticks - a->ticks) / (double)sysClkRateGet();
202# else
203 ret= (double)(b->ms_timeb.time-a->ms_timeb.time)+
204 (((double)b->ms_timeb.millitm)-
205 ((double)a->ms_timeb.millitm))/1000.0;
186# endif 206# endif
207# endif
187#endif 208#endif
188 return((ret < 0.0000001)?0.0000001:ret); 209 return((ret < 0.0000001)?0.0000001:ret);
189 } 210 }
190 211
191int ms_time_cmp(ap,bp) 212int ms_time_cmp(char *ap, char *bp)
192char *ap,*bp;
193 { 213 {
194 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp; 214 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp;
195 double d; 215 double d;
@@ -198,13 +218,17 @@ char *ap,*bp;
198#ifdef TIMES 218#ifdef TIMES
199 d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ; 219 d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
200#else 220#else
201# ifdef WIN32 221# ifdef OPENSSL_SYS_WIN32
202 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7; 222 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
203 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; 223 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
204# else 224# else
205 d= (double)(b->time-a->time)+ 225# ifdef OPENSSL_SYS_VSWORKS
206 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; 226 d = (b->ticks - a->ticks);
227# else
228 d= (double)(b->ms_timeb.time-a->ms_timeb.time)+
229 (((double)b->ms_timeb.millitm)-(double)a->ms_timeb.millitm)/1000.0;
207# endif 230# endif
231# endif
208#endif 232#endif
209 if (d == 0.0) 233 if (d == 0.0)
210 ret=0; 234 ret=0;