Skip to content

Commit

Permalink
Update tests to remove compile warnings on Ubuntu 20.04
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed Oct 2, 2020
1 parent 56bdc82 commit e4c3757
Show file tree
Hide file tree
Showing 18 changed files with 282 additions and 110 deletions.
20 changes: 16 additions & 4 deletions test/test1.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

struct tm *timeinfo;
#else
struct timeval ts;
#endif
struct tm timeinfo;

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

#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
localtime_s(&timeinfo, &ts.time);
#else
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

va_start(args, format);
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
Expand Down
17 changes: 12 additions & 5 deletions test/test10.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2018 IBM Corp.
* Copyright (c) 2009, 2020 IBM Corp. and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -164,23 +164,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

#else
struct timeval ts;
#endif
struct tm timeinfo;

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

strcpy(msg_buf, "");
ftime(&ts);
#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
localtime_s(&timeinfo, &ts.time);
#else
localtime_r(&ts.time, &timeinfo);
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

va_start(args, format);
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
Expand Down
14 changes: 13 additions & 1 deletion test/test11.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

#else
struct timeval ts;
#endif
struct tm *timeinfo;

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

#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
timeinfo = localtime(&ts.time);
#else
gettimeofday(&ts, NULL);
timeinfo = localtime(&ts.tv_sec);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);

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

va_start(args, format);
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
Expand Down
14 changes: 11 additions & 3 deletions test/test15.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

#else
struct timeval ts;
#endif
struct tm timeinfo;

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

ftime(&ts);
#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
localtime_s(&timeinfo, &ts.time);
#else
localtime_r(&ts.time, &timeinfo);
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

va_start(args, format);
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
Expand Down
22 changes: 17 additions & 5 deletions test/test2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2019 IBM Corp.
* Copyright (c) 2009, 2020 IBM Corp. and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -141,18 +141,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

struct tm *timeinfo;
#else
struct timeval ts;
#endif
struct tm timeinfo;

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

#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
localtime_s(&timeinfo, &ts.time);
#else
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

va_start(args, format);
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
Expand Down
22 changes: 17 additions & 5 deletions test/test3.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2019 IBM Corp.
* Copyright (c) 2012, 2020 IBM Corp. and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -269,18 +269,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

struct tm *timeinfo;
#else
struct timeval ts;
#endif
struct tm timeinfo;

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

#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
localtime_s(&timeinfo, &ts.time);
#else
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

va_start(args, format);
vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
Expand Down
25 changes: 16 additions & 9 deletions test/test4.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ void getopts(int argc, char** argv)
}
}

#if 0
#include <logaX.h> /* For general log messages */
#define MyLog logaLine
#else
#define LOGA_DEBUG 0
#define LOGA_INFO 1
#include <stdarg.h>
Expand All @@ -125,18 +121,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

struct tm *timeinfo;
#else
struct timeval ts;
#endif
struct tm timeinfo;

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

#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
localtime_s(&timeinfo, &ts.time);
#else
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

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


#if defined(_WIN32) || defined(_WINDOWS)
Expand Down
20 changes: 12 additions & 8 deletions test/test45.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ void getopts(int argc, char** argv)
}
}

#if 0
#include <logaX.h> /* For general log messages */
#define MyLog logaLine
#else

#define LOGA_DEBUG 0
#define LOGA_INFO 1
#include <stdarg.h>
Expand All @@ -126,22 +123,30 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

#else
struct timeval ts;
#endif
struct tm timeinfo;

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

ftime(&ts);
#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
localtime_s(&timeinfo, &ts.time);
#else
localtime_r(&ts.time, &timeinfo);
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

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


void MySleep(long milliseconds)
Expand Down
25 changes: 18 additions & 7 deletions test/test5.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,33 @@ void MyLog(int LOGA_level, char* format, ...)
{
static char msg_buf[256];
va_list args;
#if defined(_WIN32) || defined(_WINDOWS)
struct timeb ts;

struct tm *timeinfo;
#else
struct timeval ts;
#endif
struct tm timeinfo;

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

#if defined(_WIN32) || defined(_WINDOWS)
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
localtime_s(&timeinfo, &ts.time);
#else
gettimeofday(&ts, NULL);
localtime_r(&ts.tv_sec, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);

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

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

printf("%s\n", msg_buf);
Expand Down
Loading

0 comments on commit e4c3757

Please sign in to comment.