OpenBSD: introduce SCLocalTime function.

This function is a wrapper to localtime_r. It is needed to avoid
a compilation warning on OpenBSD. I'm forced to type the function
to a non pointer first parameter. If not we will have to use two
differents functions in OpenBSD where tv->tv_sec is a long
(different from time_t).
remotes/origin/HEAD
Eric Leblond 13 years ago committed by Victor Julien
parent 00948c86d5
commit a0e57f58e5

@ -89,7 +89,7 @@ typedef struct AlertDebugLogThread_ {
static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
time_t time = ts->tv_sec;
struct tm local_tm;
struct tm *t = (struct tm*)localtime_r(&time, &local_tm);
struct tm *t = (struct tm*)SCLocalTime(time, &local_tm);
snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,

@ -110,7 +110,7 @@ typedef struct AlertFastLogThread_ {
static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
time_t time = ts->tv_sec;
struct tm local_tm;
struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,

@ -1022,7 +1022,7 @@ static int SCPerfOutputCounterFileIface()
gettimeofday(&tval, NULL);
struct tm local_tm;
tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm);
tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm);
/* Calculate the Engine uptime */
int up_time = (int)difftime(tval.tv_sec, sc_start_time);

@ -587,7 +587,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
struct tm *tms;
gettimeofday(&tval, NULL);
struct tm local_tm;
tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm);
tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm);
fprintf(fp_engine_analysis_FD, "----------------------------------------------"
"---------------------\n");
fprintf(fp_engine_analysis_FD, "Date: %" PRId32 "/%" PRId32 "/%04d -- "

@ -188,7 +188,7 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx)
static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
time_t time = ts->tv_sec;
struct tm local_tm;
struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,

@ -93,7 +93,7 @@ typedef struct LogFileLogThread_ {
static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
time_t time = ts->tv_sec;
struct tm local_tm;
struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,

@ -96,7 +96,7 @@ typedef struct LogFilestoreLogThread_ {
static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
time_t time = ts->tv_sec;
struct tm local_tm;
struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,

@ -115,7 +115,7 @@ typedef struct LogHttpLogThread_ {
static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
time_t time = ts->tv_sec;
struct tm local_tm;
struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,

@ -280,7 +280,7 @@ TmEcode PcapLog (ThreadVars *t, Packet *p, void *data, PacketQueue *pq,
if (pl->mode == LOGMODE_SGUIL) {
struct tm local_tm;
struct tm *tms = (struct tm *)localtime_r(&p->ts.tv_sec, &local_tm);
struct tm *tms = (struct tm *)SCLocalTime(p->ts.tv_sec, &local_tm);
if (tms->tm_mday != pl->prev_day) {
rotate = 1;
pl->prev_day = tms->tm_mday;
@ -350,7 +350,7 @@ TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data)
memset(&ts, 0x00, sizeof(struct timeval));
TimeGet(&ts);
struct tm local_tm;
struct tm *tms = (struct tm *)localtime_r(&ts.tv_sec, &local_tm);
struct tm *tms = (struct tm *)SCLocalTime(ts.tv_sec, &local_tm);
pl->prev_day = tms->tm_mday;
*data = (void *)pl;
@ -623,7 +623,7 @@ int PcapLogOpenFileCtx(PcapLogData *pl)
if (pl->mode == LOGMODE_SGUIL) {
struct tm local_tm;
struct tm *tms = (struct tm *)localtime_r(&ts.tv_sec, &local_tm);
struct tm *tms = (struct tm *)SCLocalTime(ts.tv_sec, &local_tm);
char dirname[32], dirfull[PATH_MAX] = "";

@ -320,7 +320,7 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
gettimeofday(&tval, NULL);
struct tm local_tm;
tms = localtime_r(&tval.tv_sec, &local_tm);
tms = SCLocalTime(tval.tv_sec, &local_tm);
cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg),
"%s%d/%d/%04d -- %02d:%02d:%02d",

@ -569,7 +569,7 @@ SCProfilingDump(void)
gettimeofday(&tval, NULL);
struct tm local_tm;
tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm);
tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm);
fprintf(fp, " ----------------------------------------------"
"----------------------------\n");

@ -111,3 +111,8 @@ void TimeSetIncrementTime(uint32_t tv_sec) {
TimeSet(&tv);
}
struct tm *SCLocalTime(time_t timep, struct tm *result)
{
return localtime_r(&timep, result);
}

@ -46,5 +46,7 @@ void TimeSetIncrementTime(uint32_t);
void TimeModeSetLive(void);
void TimeModeSetOffline (void);
struct tm *SCLocalTime(time_t timep, struct tm *result);
#endif /* __UTIL_TIME_H__ */

Loading…
Cancel
Save