FreeBSD has BSD extension timezone, which conflicts with XSI extension
with the same name, according to time.h:
char *timezone(int, int); /* XXX XSI conflict */
...
FreeBSD also has long tm_gmtoff member of struct tm, which is offset
from UTC in seconds, according to time.h:
struct tm {
...
long tm_gmtoff; /* offset from UTC in seconds */
char *tm_zone; /* timezone abbreviation */
}
which is the same as XSI extension timezone.
Co-authored-by: Jan Beich <jbeich@FreeBSD.org> (downstream patch)
---
main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/main.c b/main.c
index 1042d17..4319745 100644
--- a/main.c+++ b/main.c
@@ -17,6 +17,10 @@
#include "wlr-gamma-control-unstable-v1-client-protocol.h"
#include "color_math.h"
+#if defined(__FreeBSD__)+#define timezone tm.tm_gmtoff+#endif+
At the moment, rg 'timezone' yields 1 result in main.c. The other two
*.c, *.h files are color_math.{c,h}. I can't understand why one would
need to have several functions getting timezone offset from OS vs one.
I can understand that due to "tm.tm_gmtoff" this macro is useful only
for a scope where struct tm is declared as "tm", but this will be the
case when one has only one function that gets timezone offset from OS.
Besides, main.c is neater when preprocessor directives are at the top.
I meant the name of the struct tm variable, which in parse_time_of_day
happens to be "tm".
As this is the only real ifdef in wlsunset with only one use I think
inlining it is a fine solution. :)
https://github.com/dragonflybsd/dragonflybsd/commit/7d013f972434
https://github.com/netbsd/src/commit/a495a577a009
https://github.com/openbsd/src/commit/c9da469ac913
https://opensource.apple.com/source/Libc/Libc-391/include/time.h.auto.html
See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=24590
FreeBSD has BSD extension timezone, which conflicts with XSI extension
with the same name, according to time.h:
char *timezone(int, int); /* XXX XSI conflict */
...
FreeBSD also has long tm_gmtoff member of struct tm, which is offset
from UTC in seconds, according to time.h:
struct tm {
...
long tm_gmtoff; /* offset from UTC in seconds */
char *tm_zone; /* timezone abbreviation */
}
which is the same as XSI extension timezone.
Co-authored-by: Jan Beich <jbeich@FreeBSD.org> (downstream patch)
Reviewed by: Kenny Levinsen <kl@kl.wtf>
---
main.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
index 1042d17..38e0faa 100644
--- a/main.c+++ b/main.c
@@ -707,7 +707,12 @@ static int parse_time_of_day(const char *s, time_t *time) {
if (strptime(s, "%H:%M", &tm) == NULL) {
return -1;
}
- *time = tm.tm_hour * 3600 + tm.tm_min * 60 + timezone;+ *time = tm.tm_hour * 3600 + tm.tm_min * 60;+#if defined(__FreeBSD__)+ *time += tm.tm_gmtoff;+#else+ *time += timezone;+#endif return 0;
}
--
2.34.1