Skip to content

Commit e4c3757

Browse files
committed
Update tests to remove compile warnings on Ubuntu 20.04
1 parent 56bdc82 commit e4c3757

18 files changed

+282
-110
lines changed

test/test1.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,30 @@ void MyLog(int LOGA_level, char* format, ...)
150150
{
151151
static char msg_buf[256];
152152
va_list args;
153+
#if defined(_WIN32) || defined(_WINDOWS)
153154
struct timeb ts;
154-
155-
struct tm *timeinfo;
155+
#else
156+
struct timeval ts;
157+
#endif
158+
struct tm timeinfo;
156159

157160
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
158161
return;
159162

163+
#if defined(_WIN32) || defined(_WINDOWS)
160164
ftime(&ts);
161-
timeinfo = localtime(&ts.time);
162-
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
165+
localtime_s(&timeinfo, &ts.time);
166+
#else
167+
gettimeofday(&ts, NULL);
168+
localtime_r(&ts.tv_sec, &timeinfo);
169+
#endif
170+
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
163171

172+
#if defined(_WIN32) || defined(_WINDOWS)
164173
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
174+
#else
175+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
176+
#endif
165177

166178
va_start(args, format);
167179
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);

test/test10.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2018 IBM Corp.
2+
* Copyright (c) 2009, 2020 IBM Corp. and others
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
@@ -164,23 +164,30 @@ void MyLog(int LOGA_level, char* format, ...)
164164
{
165165
static char msg_buf[256];
166166
va_list args;
167+
#if defined(_WIN32) || defined(_WINDOWS)
167168
struct timeb ts;
168-
169+
#else
170+
struct timeval ts;
171+
#endif
169172
struct tm timeinfo;
170173

171174
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
172175
return;
173176

174-
strcpy(msg_buf, "");
175-
ftime(&ts);
176177
#if defined(_WIN32) || defined(_WINDOWS)
178+
ftime(&ts);
177179
localtime_s(&timeinfo, &ts.time);
178180
#else
179-
localtime_r(&ts.time, &timeinfo);
181+
gettimeofday(&ts, NULL);
182+
localtime_r(&ts.tv_sec, &timeinfo);
180183
#endif
181184
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
182185

186+
#if defined(_WIN32) || defined(_WINDOWS)
183187
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
188+
#else
189+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
190+
#endif
184191

185192
va_start(args, format);
186193
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);

test/test11.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,30 @@ void MyLog(int LOGA_level, char* format, ...)
126126
{
127127
static char msg_buf[256];
128128
va_list args;
129+
#if defined(_WIN32) || defined(_WINDOWS)
129130
struct timeb ts;
130-
131+
#else
132+
struct timeval ts;
133+
#endif
131134
struct tm *timeinfo;
132135

133136
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
134137
return;
135138

139+
#if defined(_WIN32) || defined(_WINDOWS)
136140
ftime(&ts);
137141
timeinfo = localtime(&ts.time);
142+
#else
143+
gettimeofday(&ts, NULL);
144+
timeinfo = localtime(&ts.tv_sec);
145+
#endif
138146
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
139147

148+
#if defined(_WIN32) || defined(_WINDOWS)
140149
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
150+
#else
151+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
152+
#endif
141153

142154
va_start(args, format);
143155
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);

test/test15.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,30 @@ void MyLog(int LOGA_level, char* format, ...)
152152
{
153153
static char msg_buf[256];
154154
va_list args;
155+
#if defined(_WIN32) || defined(_WINDOWS)
155156
struct timeb ts;
156-
157+
#else
158+
struct timeval ts;
159+
#endif
157160
struct tm timeinfo;
158161

159162
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
160163
return;
161164

162-
ftime(&ts);
163165
#if defined(_WIN32) || defined(_WINDOWS)
166+
ftime(&ts);
164167
localtime_s(&timeinfo, &ts.time);
165168
#else
166-
localtime_r(&ts.time, &timeinfo);
169+
gettimeofday(&ts, NULL);
170+
localtime_r(&ts.tv_sec, &timeinfo);
167171
#endif
168172
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
169173

174+
#if defined(_WIN32) || defined(_WINDOWS)
170175
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
176+
#else
177+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
178+
#endif
171179

172180
va_start(args, format);
173181
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);

test/test2.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2019 IBM Corp.
2+
* Copyright (c) 2009, 2020 IBM Corp. and others
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
@@ -141,18 +141,30 @@ void MyLog(int LOGA_level, char* format, ...)
141141
{
142142
static char msg_buf[256];
143143
va_list args;
144+
#if defined(_WIN32) || defined(_WINDOWS)
144145
struct timeb ts;
145-
146-
struct tm *timeinfo;
146+
#else
147+
struct timeval ts;
148+
#endif
149+
struct tm timeinfo;
147150

148151
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
149152
return;
150153

154+
#if defined(_WIN32) || defined(_WINDOWS)
151155
ftime(&ts);
152-
timeinfo = localtime(&ts.time);
153-
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
156+
localtime_s(&timeinfo, &ts.time);
157+
#else
158+
gettimeofday(&ts, NULL);
159+
localtime_r(&ts.tv_sec, &timeinfo);
160+
#endif
161+
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
154162

163+
#if defined(_WIN32) || defined(_WINDOWS)
155164
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
165+
#else
166+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
167+
#endif
156168

157169
va_start(args, format);
158170
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);

test/test3.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2019 IBM Corp.
2+
* Copyright (c) 2012, 2020 IBM Corp. and others
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
@@ -269,18 +269,30 @@ void MyLog(int LOGA_level, char* format, ...)
269269
{
270270
static char msg_buf[256];
271271
va_list args;
272+
#if defined(_WIN32) || defined(_WINDOWS)
272273
struct timeb ts;
273-
274-
struct tm *timeinfo;
274+
#else
275+
struct timeval ts;
276+
#endif
277+
struct tm timeinfo;
275278

276279
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
277280
return;
278281

282+
#if defined(_WIN32) || defined(_WINDOWS)
279283
ftime(&ts);
280-
timeinfo = localtime(&ts.time);
281-
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
284+
localtime_s(&timeinfo, &ts.time);
285+
#else
286+
gettimeofday(&ts, NULL);
287+
localtime_r(&ts.tv_sec, &timeinfo);
288+
#endif
289+
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
282290

291+
#if defined(_WIN32) || defined(_WINDOWS)
283292
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
293+
#else
294+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
295+
#endif
284296

285297
va_start(args, format);
286298
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);

test/test4.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ void getopts(int argc, char** argv)
112112
}
113113
}
114114

115-
#if 0
116-
#include <logaX.h> /* For general log messages */
117-
#define MyLog logaLine
118-
#else
119115
#define LOGA_DEBUG 0
120116
#define LOGA_INFO 1
121117
#include <stdarg.h>
@@ -125,18 +121,30 @@ void MyLog(int LOGA_level, char* format, ...)
125121
{
126122
static char msg_buf[256];
127123
va_list args;
124+
#if defined(_WIN32) || defined(_WINDOWS)
128125
struct timeb ts;
129-
130-
struct tm *timeinfo;
126+
#else
127+
struct timeval ts;
128+
#endif
129+
struct tm timeinfo;
131130

132131
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
133132
return;
134133

134+
#if defined(_WIN32) || defined(_WINDOWS)
135135
ftime(&ts);
136-
timeinfo = localtime(&ts.time);
137-
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
136+
localtime_s(&timeinfo, &ts.time);
137+
#else
138+
gettimeofday(&ts, NULL);
139+
localtime_r(&ts.tv_sec, &timeinfo);
140+
#endif
141+
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
138142

143+
#if defined(_WIN32) || defined(_WINDOWS)
139144
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
145+
#else
146+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
147+
#endif
140148

141149
va_start(args, format);
142150
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
@@ -145,7 +153,6 @@ void MyLog(int LOGA_level, char* format, ...)
145153
printf("%s\n", msg_buf);
146154
fflush(stdout);
147155
}
148-
#endif
149156

150157

151158
#if defined(_WIN32) || defined(_WINDOWS)

test/test45.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ void getopts(int argc, char** argv)
113113
}
114114
}
115115

116-
#if 0
117-
#include <logaX.h> /* For general log messages */
118-
#define MyLog logaLine
119-
#else
116+
120117
#define LOGA_DEBUG 0
121118
#define LOGA_INFO 1
122119
#include <stdarg.h>
@@ -126,22 +123,30 @@ void MyLog(int LOGA_level, char* format, ...)
126123
{
127124
static char msg_buf[256];
128125
va_list args;
126+
#if defined(_WIN32) || defined(_WINDOWS)
129127
struct timeb ts;
130-
128+
#else
129+
struct timeval ts;
130+
#endif
131131
struct tm timeinfo;
132132

133133
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
134134
return;
135135

136-
ftime(&ts);
137136
#if defined(_WIN32) || defined(_WINDOWS)
137+
ftime(&ts);
138138
localtime_s(&timeinfo, &ts.time);
139139
#else
140-
localtime_r(&ts.time, &timeinfo);
140+
gettimeofday(&ts, NULL);
141+
localtime_r(&ts.tv_sec, &timeinfo);
141142
#endif
142143
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
143144

145+
#if defined(_WIN32) || defined(_WINDOWS)
144146
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
147+
#else
148+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
149+
#endif
145150

146151
va_start(args, format);
147152
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
@@ -150,7 +155,6 @@ void MyLog(int LOGA_level, char* format, ...)
150155
printf("%s\n", msg_buf);
151156
fflush(stdout);
152157
}
153-
#endif
154158

155159

156160
void MySleep(long milliseconds)

test/test5.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,33 @@ void MyLog(int LOGA_level, char* format, ...)
233233
{
234234
static char msg_buf[256];
235235
va_list args;
236+
#if defined(_WIN32) || defined(_WINDOWS)
236237
struct timeb ts;
237-
238-
struct tm *timeinfo;
238+
#else
239+
struct timeval ts;
240+
#endif
241+
struct tm timeinfo;
239242

240243
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
241-
return;
244+
return;
242245

246+
#if defined(_WIN32) || defined(_WINDOWS)
243247
ftime(&ts);
244-
timeinfo = localtime(&ts.time);
245-
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
248+
localtime_s(&timeinfo, &ts.time);
249+
#else
250+
gettimeofday(&ts, NULL);
251+
localtime_r(&ts.tv_sec, &timeinfo);
252+
#endif
253+
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
246254

255+
#if defined(_WIN32) || defined(_WINDOWS)
247256
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
257+
#else
258+
sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
259+
#endif
248260

249261
va_start(args, format);
250-
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf),
251-
format, args);
262+
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
252263
va_end(args);
253264

254265
printf("%s\n", msg_buf);

0 commit comments

Comments
 (0)