Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
1086c4aa
You need to sign in or sign up before continuing.
Unverified
Commit
1086c4aa
authored
Jan 09, 2018
by
Mihai Moldovan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Ionic-bugfix/ctime' into 3.6.x
Attributes GH PR #623:
https://github.com/ArcticaProject/nx-libs/pull/623
Fixes: ArcticaProject/nx-libs#616
parents
70e1e6a0
2eb2f2e6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
20 deletions
+64
-20
configure.ac
nxcomp/configure.ac
+17
-0
Timestamp.cpp
nxcomp/src/Timestamp.cpp
+36
-15
Timestamp.h
nxcomp/src/Timestamp.h
+11
-5
No files found.
nxcomp/configure.ac
View file @
1086c4aa
...
...
@@ -94,6 +94,23 @@ std::tm tm = *std::localtime(&t);
[Use std::put_time to format times, must be made available by the compiler if turned on.])],
[AC_MSG_RESULT([no])])
# Check if ::ctime_s is available.
AC_MSG_CHECKING([if ::ctime_s is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
#define __STDC_WANT_LIB_EXT1__ 1
#include <ctime>
]],
[[
time_t res = time(NULL);
char str[26] = { };
::ctime_s(str, sizeof(str), &res);
]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_CTIME_S, [1],
[Use ::ctime_s to format times, must be made available by the compiler if turned on.])],
[AC_MSG_RESULT([no])])
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[enable to get info session log output (disabled by default)])],
...
...
nxcomp/src/Timestamp.cpp
View file @
1086c4aa
...
...
@@ -44,34 +44,55 @@
T_timestamp
timestamp
;
//
// The following functions all use the ctime
// static buffer from the C library.
//
char
*
strTimestamp
(
const
T_timestamp
&
ts
)
std
::
string
strTimestamp
(
const
T_timestamp
&
ts
)
{
char
*
ctime_now
=
ctime
((
time_t
*
)
&
ts
.
tv_sec
);
std
::
string
ret
;
char
ctime_now
[
26
]
=
{
};
bool
err
=
true
;
#if HAVE_CTIME_S
errno_t
retval
=
::
ctime_s
(
ctime_now
,
sizeof
(
ctime_now
),
static_cast
<
const
time_t
*>
(
&
ts
.
tv_sec
));
if
(
retval
!=
0
)
#else
char
*
retval
=
::
ctime_r
(
static_cast
<
const
time_t
*>
(
&
ts
.
tv_sec
),
ctime_now
);
if
(
!
(
retval
))
#endif
{
std
::
cerr
<<
"WARNING: converting time to string failed."
<<
std
::
endl
;
}
else
{
/* Replace newline at position 25 with a NULL byte. */
ctime_now
[
24
]
=
'\0'
;
return
ctime_now
;
ret
=
ctime_now
;
}
return
ret
;
}
//
// This is especially dirty.
//
char
*
strMsTimestamp
(
const
T_timestamp
&
ts
)
std
::
string
strMsTimestamp
(
const
T_timestamp
&
ts
)
{
char
*
ctime_now
=
ctime
((
time_t
*
)
&
ts
.
tv_sec
);
std
::
string
ret
;
std
::
string
ctime_now
=
strTimestamp
(
ts
);
char
ctime_new
[
25
];
if
(
!
(
ctime_now
.
empty
()))
{
char
ctime_new
[
26
]
=
{
};
sprintf
(
ctime_new
,
"%.8s:%3.3f"
,
ctime_now
+
11
,
(
float
)
ts
.
tv_usec
/
1000
);
snprintf
(
ctime_new
,
sizeof
(
ctime_new
),
"%.8s:%3.3f"
,
ctime_now
.
c_str
()
+
11
,
static_cast
<
float
>
(
ts
.
tv_usec
)
/
1000
);
strncpy
(
ctime_now
,
ctime_new
,
24
);
ret
=
ctime_new
;
}
return
ctime_now
;
return
ret
;
}
nxcomp/src/Timestamp.h
View file @
1086c4aa
...
...
@@ -26,11 +26,17 @@
#ifndef Timestamp_H
#define Timestamp_H
#if HAVE_CTIME_S
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
#endif
/* HAVE_CTIME_S */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <time.h>
#include <sys/time.h>
#include "Misc.h"
...
...
@@ -260,15 +266,15 @@ inline int checkDiffTimestamp(const T_timestamp &ts1, const T_timestamp &ts2,
// Return a string representing the timestamp.
//
char
*
strTimestamp
(
const
T_timestamp
&
ts
);
char
*
strMsTimestamp
(
const
T_timestamp
&
ts
);
std
::
string
strTimestamp
(
const
T_timestamp
&
ts
);
std
::
string
strMsTimestamp
(
const
T_timestamp
&
ts
);
inline
char
*
strTimestamp
()
inline
std
::
string
strTimestamp
()
{
return
strTimestamp
(
getTimestamp
());
}
inline
char
*
strMsTimestamp
()
inline
std
::
string
strMsTimestamp
()
{
return
strMsTimestamp
(
getTimestamp
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment