Fix compilation for FreeBSD
libyang-source/src/plugins_types/date_and_time.c:122:19: warning: arithmetic on a pointer to the function type 'char *(int, int)' is a GNU extension [-Wpointer-arith]
val->time += timezone;
^ ~~~~~~~~
libyang-source/src/plugins_types/date_and_time.c:122:19: warning: incompatible pointer to integer conversion assigning to 'time_t' (aka 'long') from 'char *(*)(int, int)' [-Wint-conversion]
val->time += timezone;
^ ~~~~~~~~
/usr/home/ci/cibuild.167/libyang-source/src/plugins_types/date_and_time.c:125:13: error: use of undeclared identifier 'daylight'
if (daylight) {
^
2 warnings and 1 error generated.
* localtime_r() tells about DST already. In FreeBSD `daylight` variable
is not exposed. I believe we can use DST from tm?
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
diff --git a/compat/strptime.c b/compat/strptime.c
index 38e9d03..0520a75 100644
--- a/compat/strptime.c
+++ b/compat/strptime.c
@@ -166,7 +166,7 @@
for (i = 1; i <= min + range && isdigit(*s); i *= 10) {
*dest = *dest * 10 + *s++ - '0';
}
- if (*dest - min >= (unsigned)range) {
+ if (*dest - min >= range) {
return 0;
}
*dest -= adj;
diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c
index 627869b..5ccb86d 100644
--- a/src/plugins_types/date_and_time.c
+++ b/src/plugins_types/date_and_time.c
@@ -119,22 +119,20 @@
if (!strncmp(((char *)value + value_len) - 6, "-00:00", 6)) {
/* unknown timezone, move the timestamp to UTC */
tzset();
- val->time += timezone;
+ val->time += (time_t)timezone;
val->unknown_tz = 1;
- if (daylight) {
- /* DST may apply, adjust accordingly */
- if (!localtime_r(&val->time, &tm)) {
- ret = ly_err_new(err, LY_ESYS, LYVE_DATA, NULL, NULL, "localtime_r() call failed (%s).", strerror(errno));
- goto cleanup;
- } else if (tm.tm_isdst < 0) {
- ret = ly_err_new(err, LY_EINT, LYVE_DATA, NULL, NULL, "Failed to get DST information.");
- goto cleanup;
- }
- if (tm.tm_isdst) {
- /* move an hour back */
- val->time -= 3600;
- }
+ /* DST may apply, adjust accordingly */
+ if (!localtime_r(&val->time, &tm)) {
+ ret = ly_err_new(err, LY_ESYS, LYVE_DATA, NULL, NULL, "localtime_r() call failed (%s).", strerror(errno));
+ goto cleanup;
+ } else if (tm.tm_isdst < 0) {
+ ret = ly_err_new(err, LY_EINT, LYVE_DATA, NULL, NULL, "Failed to get DST information.");
+ goto cleanup;
+ }
+ if (tm.tm_isdst) {
+ /* move an hour back */
+ val->time -= 3600;
}
}
#else