* [PATCH 1/4] getpwuid: check for standards compliance (Solaris support)
2013-05-06 15:15 Solaris support - missing or incompatible functions Vladimir.Marek
@ 2013-05-06 15:15 ` Vladimir.Marek
2013-05-06 15:16 ` [PATCH 2/4] asctime: " Vladimir.Marek
` (3 subsequent siblings)
4 siblings, 0 replies; 24+ messages in thread
From: Vladimir.Marek @ 2013-05-06 15:15 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Blake Jones <blakej@foo.net>
Add checks to "configure" to see whether _POSIX_PTHREAD_SEMANTICS needs
to be defined to get the right number of arguments in the prototypes for
getpwuid_r(). Solaris' default implementation conforms to POSIX.1c
Draft 6, rather than the final POSIX.1c spec. The standards-compliant
version can be used by defining _POSIX_PTHREAD_SEMANTICS.
This change also adds the file "compat/check_getpwuid.c", which
configure uses to perform its check, and modifies compat/compat.h to
define _POSIX_PTHREAD_SEMANTICS if configure detected it was needed.
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/check_getpwuid.c | 11 +++++++++++
compat/compat.h | 4 ++++
configure | 23 +++++++++++++++++++++--
3 files changed, 36 insertions(+), 2 deletions(-)
create mode 100644 compat/check_getpwuid.c
diff --git a/compat/check_getpwuid.c b/compat/check_getpwuid.c
new file mode 100644
index 0000000..c435eb8
--- /dev/null
+++ b/compat/check_getpwuid.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <pwd.h>
+
+int main()
+{
+ struct passwd passwd, *ignored;
+
+ (void) getpwuid_r (0, &passwd, NULL, 0, &ignored);
+
+ return (0);
+}
diff --git a/compat/compat.h b/compat/compat.h
index b2e2736..c1ee0f9 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -30,6 +30,10 @@
extern "C" {
#endif
+#if !STD_GETPWUID
+#define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+
#if !HAVE_GETLINE
#include <stdio.h>
#include <unistd.h>
diff --git a/configure b/configure
index 460fcfc..8ef7bac 100755
--- a/configure
+++ b/configure
@@ -517,6 +517,17 @@ else
fi
rm -f compat/have_strcasestr
+printf "Checking for standard version of getpwuid_r... "
+if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ std_getpwuid=1
+else
+ printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
+ std_getpwuid=0
+fi
+rm -f compat/check_getpwuid
+
printf "int main(void){return 0;}\n" > minimal.c
printf "Checking for rpath support... "
@@ -676,6 +687,11 @@ HAVE_GETLINE = ${have_getline}
# build its own version)
HAVE_STRCASESTR = ${have_strcasestr}
+# Whether the getpwuid_r function is standards-compliant
+# (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
+# to enable the standards-compliant version -- needed for Solaris)
+STD_GETPWUID = ${std_getpwuid}
+
# Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
PLATFORM = ${platform}
@@ -720,10 +736,13 @@ WITH_ZSH = ${WITH_ZSH}
# Combined flags for compiling and linking against all of the above
CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
- \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
+ \$(VALGRIND_CFLAGS) \\
+ -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
+ -DSTD_GETPWUID=\$(STD_GETPWUID)
CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
- -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
+ -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
+ -DSTD_GETPWUID=\$(STD_GETPWUID)
CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
EOF
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 2/4] asctime: check for standards compliance (Solaris support)
2013-05-06 15:15 Solaris support - missing or incompatible functions Vladimir.Marek
2013-05-06 15:15 ` [PATCH 1/4] getpwuid: check for standards compliance (Solaris support) Vladimir.Marek
@ 2013-05-06 15:16 ` Vladimir.Marek
2013-05-06 15:16 ` [PATCH 3/4] strsep: check for availability " Vladimir.Marek
` (2 subsequent siblings)
4 siblings, 0 replies; 24+ messages in thread
From: Vladimir.Marek @ 2013-05-06 15:16 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Vladimir Marek <vlmarek@volny.cz>
Add checks to "configure" to see whether _POSIX_PTHREAD_SEMANTICS needs
to be defined to get the right number of arguments in the prototypes for
asctime_r(). Solaris' default implementation conforms to POSIX.1c
Draft 6, rather than the final POSIX.1c spec. The standards-compliant
version can be used by defining _POSIX_PTHREAD_SEMANTICS.
This change also adds the file "compat/check_asctime.c", which
configure uses to perform its check, and modifies compat/compat.h to
define _POSIX_PTHREAD_SEMANTICS if configure detected it was needed.
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/check_asctime.c | 11 +++++++++++
compat/compat.h | 3 +++
configure | 22 ++++++++++++++++++++--
3 files changed, 34 insertions(+), 2 deletions(-)
create mode 100644 compat/check_asctime.c
diff --git a/compat/check_asctime.c b/compat/check_asctime.c
new file mode 100644
index 0000000..b0e56f0
--- /dev/null
+++ b/compat/check_asctime.c
@@ -0,0 +1,11 @@
+#include <time.h>
+#include <stdio.h>
+
+int main()
+{
+ struct tm tm;
+
+ (void) asctime_r (&tm, NULL);
+
+ return (0);
+}
diff --git a/compat/compat.h b/compat/compat.h
index c1ee0f9..0c4ac66 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -33,6 +33,9 @@ extern "C" {
#if !STD_GETPWUID
#define _POSIX_PTHREAD_SEMANTICS 1
#endif
+#if !STD_ASCTIME
+#define _POSIX_PTHREAD_SEMANTICS 1
+#endif
#if !HAVE_GETLINE
#include <stdio.h>
diff --git a/configure b/configure
index 8ef7bac..99ec71a 100755
--- a/configure
+++ b/configure
@@ -528,6 +528,17 @@ else
fi
rm -f compat/check_getpwuid
+printf "Checking for standard version of asctime_r... "
+if ${CC} -o compat/check_asctime "$srcdir"/compat/check_asctime.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ std_asctime=1
+else
+ printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
+ std_asctime=0
+fi
+rm -f compat/check_asctime
+
printf "int main(void){return 0;}\n" > minimal.c
printf "Checking for rpath support... "
@@ -692,6 +703,11 @@ HAVE_STRCASESTR = ${have_strcasestr}
# to enable the standards-compliant version -- needed for Solaris)
STD_GETPWUID = ${std_getpwuid}
+# Whether the asctime_r function is standards-compliant
+# (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
+# to enable the standards-compliant version -- needed for Solaris)
+STD_ASCTIME = ${std_asctime}
+
# Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
PLATFORM = ${platform}
@@ -738,11 +754,13 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\$(VALGRIND_CFLAGS) \\
-DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
- -DSTD_GETPWUID=\$(STD_GETPWUID)
+ -DSTD_GETPWUID=\$(STD_GETPWUID) \\
+ -DSTD_ASCTIME=\$(STD_ASCTIME)
CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
-DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
- -DSTD_GETPWUID=\$(STD_GETPWUID)
+ -DSTD_GETPWUID=\$(STD_GETPWUID) \\
+ -DSTD_ASCTIME=\$(STD_ASCTIME)
CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
EOF
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 3/4] strsep: check for availability (Solaris support)
2013-05-06 15:15 Solaris support - missing or incompatible functions Vladimir.Marek
2013-05-06 15:15 ` [PATCH 1/4] getpwuid: check for standards compliance (Solaris support) Vladimir.Marek
2013-05-06 15:16 ` [PATCH 2/4] asctime: " Vladimir.Marek
@ 2013-05-06 15:16 ` Vladimir.Marek
2013-05-06 15:16 ` [PATCH 4/4] timegm: add portable implementation " Vladimir.Marek
2013-05-12 20:02 ` Solaris support - missing or incompatible functions Jani Nikula
4 siblings, 0 replies; 24+ messages in thread
From: Vladimir.Marek @ 2013-05-06 15:16 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Blake Jones <blakej@foo.net>
Solaris does not ship a version of the strsep() function. This change
adds a check to "configure" to see whether notmuch needs to provide its
own implementation, and if so, it uses the new version in
"compat/strsep.c" (which was copied from Mutt, and apparently before
that from glibc).
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/Makefile.local | 4 +++
compat/compat.h | 4 +++
compat/have_strsep.c | 11 +++++++++
compat/strsep.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
configure | 17 +++++++++++++
5 files changed, 101 insertions(+)
create mode 100644 compat/have_strsep.c
create mode 100644 compat/strsep.c
diff --git a/compat/Makefile.local b/compat/Makefile.local
index 13f16cd..2c4f65f 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -13,4 +13,8 @@ ifneq ($(HAVE_STRCASESTR),1)
notmuch_compat_srcs += $(dir)/strcasestr.c
endif
+ifneq ($(HAVE_STRSEP),1)
+notmuch_compat_srcs += $(dir)/strsep.c
+endif
+
SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index 0c4ac66..ae762c3 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -53,6 +53,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);
char* strcasestr(const char *haystack, const char *needle);
#endif /* !HAVE_STRCASESTR */
+#if !HAVE_STRSEP
+char *strsep(char **stringp, const char *delim);
+#endif /* !HAVE_STRSEP */
+
/* Silence gcc warnings about unused results. These warnings exist
* for a reason; any use of this needs to be justified. */
#ifdef __GNUC__
diff --git a/compat/have_strsep.c b/compat/have_strsep.c
new file mode 100644
index 0000000..2abab81
--- /dev/null
+++ b/compat/have_strsep.c
@@ -0,0 +1,11 @@
+#define _GNU_SOURCE
+#include <string.h>
+
+int main()
+{
+ char *found;
+ char **stringp;
+ const char *delim;
+
+ found = strsep(stringp, delim);
+}
diff --git a/compat/strsep.c b/compat/strsep.c
new file mode 100644
index 0000000..78ab9e7
--- /dev/null
+++ b/compat/strsep.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 1992, 93, 96, 97, 98, 99, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+
+/* Taken from glibc 2.6.1 */
+
+char *strsep (char **stringp, const char *delim)
+{
+ char *begin, *end;
+
+ begin = *stringp;
+ if (begin == NULL)
+ return NULL;
+
+ /* A frequent case is when the delimiter string contains only one
+ character. Here we don't need to call the expensive `strpbrk'
+ function and instead work using `strchr'. */
+ if (delim[0] == '\0' || delim[1] == '\0')
+ {
+ char ch = delim[0];
+
+ if (ch == '\0')
+ end = NULL;
+ else
+ {
+ if (*begin == ch)
+ end = begin;
+ else if (*begin == '\0')
+ end = NULL;
+ else
+ end = strchr (begin + 1, ch);
+ }
+ }
+ else
+ /* Find the end of the token. */
+ end = strpbrk (begin, delim);
+
+ if (end)
+ {
+ /* Terminate the token and set *STRINGP past NUL character. */
+ *end++ = '\0';
+ *stringp = end;
+ }
+ else
+ /* No more delimiters; this is the last token. */
+ *stringp = NULL;
+
+ return begin;
+}
diff --git a/configure b/configure
index 99ec71a..5243cac 100755
--- a/configure
+++ b/configure
@@ -517,6 +517,17 @@ else
fi
rm -f compat/have_strcasestr
+printf "Checking for strsep... "
+if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ have_strsep="1"
+else
+ printf "No (will use our own instead).\n"
+ have_strsep="0"
+fi
+rm -f compat/have_strsep
+
printf "Checking for standard version of getpwuid_r... "
if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
then
@@ -698,6 +709,10 @@ HAVE_GETLINE = ${have_getline}
# build its own version)
HAVE_STRCASESTR = ${have_strcasestr}
+# Whether the strsep function is available (if not, then notmuch will
+# build its own version)
+HAVE_STRSEP = ${have_strsep}
+
# Whether the getpwuid_r function is standards-compliant
# (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
# to enable the standards-compliant version -- needed for Solaris)
@@ -754,12 +769,14 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\$(VALGRIND_CFLAGS) \\
-DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
+ -DHAVE_STRSEP=\$(HAVE_STRSEP) \\
-DSTD_GETPWUID=\$(STD_GETPWUID) \\
-DSTD_ASCTIME=\$(STD_ASCTIME)
CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
-DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
+ -DHAVE_STRSEP=\$(HAVE_STRSEP) \\
-DSTD_GETPWUID=\$(STD_GETPWUID) \\
-DSTD_ASCTIME=\$(STD_ASCTIME)
CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-05-06 15:15 Solaris support - missing or incompatible functions Vladimir.Marek
` (2 preceding siblings ...)
2013-05-06 15:16 ` [PATCH 3/4] strsep: check for availability " Vladimir.Marek
@ 2013-05-06 15:16 ` Vladimir.Marek
2013-05-12 20:02 ` Solaris support - missing or incompatible functions Jani Nikula
4 siblings, 0 replies; 24+ messages in thread
From: Vladimir.Marek @ 2013-05-06 15:16 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Blake Jones <blakej@foo.net>
The timegm(3) function is a non-standard extension to libc which is
available in GNU libc and on some BSDs. Although SunOS had this
function in its libc, Solaris (unfortunately) removed it. This patch
implements a very simple version of timegm() which is good enough for
parse-time-string.c.
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/Makefile.local | 4 ++++
compat/compat.h | 5 +++++
compat/have_timegm.c | 7 +++++++
compat/timegm.c | 37 +++++++++++++++++++++++++++++++++
configure | 11 ++++++++++
parse-time-string/parse-time-string.c | 1 +
6 files changed, 65 insertions(+)
create mode 100644 compat/have_timegm.c
create mode 100644 compat/timegm.c
diff --git a/compat/Makefile.local b/compat/Makefile.local
index 2c4f65f..b0d5417 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
notmuch_compat_srcs += $(dir)/strsep.c
endif
+ifneq ($(HAVE_TIMEGM),1)
+notmuch_compat_srcs += $(dir)/timegm.c
+endif
+
SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index ae762c3..5a402d5 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
char *strsep(char **stringp, const char *delim);
#endif /* !HAVE_STRSEP */
+#if !HAVE_TIMEGM
+#include <time.h>
+time_t timegm (struct tm *tm);
+#endif /* !HAVE_TIMEGM */
+
/* Silence gcc warnings about unused results. These warnings exist
* for a reason; any use of this needs to be justified. */
#ifdef __GNUC__
diff --git a/compat/have_timegm.c b/compat/have_timegm.c
new file mode 100644
index 0000000..b62b793
--- /dev/null
+++ b/compat/have_timegm.c
@@ -0,0 +1,7 @@
+#include <time.h>
+#include "compat.h"
+
+int main()
+{
+ return (int) timegm((struct tm *)0);
+}
diff --git a/compat/timegm.c b/compat/timegm.c
new file mode 100644
index 0000000..6d76164
--- /dev/null
+++ b/compat/timegm.c
@@ -0,0 +1,37 @@
+#include <time.h>
+#include "compat.h"
+
+static int
+leapyear (int year)
+{
+ return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
+}
+
+/*
+ * This is a simple implementation of timegm() which does what is needed
+ * by create_output() -- just turns the "struct tm" into a GMT time_t.
+ * It does not normalize any of the fields of the "struct tm", nor does
+ * it set tm_wday or tm_yday.
+ */
+time_t
+timegm (struct tm *tm)
+{
+ int monthlen[2][12] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ };
+ int year, month, days;
+
+ days = 365 * (tm->tm_year - 70);
+ for (year = 70; year < tm->tm_year; year++) {
+ if (leapyear(1900 + year)) {
+ days++;
+ }
+ }
+ for (month = 0; month < tm->tm_mon; month++) {
+ days += monthlen[leapyear(1900 + year)][month];
+ }
+ days += tm->tm_mday - 1;
+
+ return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
+}
diff --git a/configure b/configure
index 5243cac..ee037d8 100755
--- a/configure
+++ b/configure
@@ -528,6 +528,17 @@ else
fi
rm -f compat/have_strsep
+printf "Checking for timegm... "
+if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ have_timegm="1"
+else
+ printf "No (will use our own instead).\n"
+ have_timegm="0"
+fi
+rm -f compat/have_timegm
+
printf "Checking for standard version of getpwuid_r... "
if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
then
diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
index 584067d..ccad422 100644
--- a/parse-time-string/parse-time-string.c
+++ b/parse-time-string/parse-time-string.c
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/types.h>
+#include "compat.h"
#include "parse-time-string.h"
/*
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: Solaris support - missing or incompatible functions
2013-05-06 15:15 Solaris support - missing or incompatible functions Vladimir.Marek
` (3 preceding siblings ...)
2013-05-06 15:16 ` [PATCH 4/4] timegm: add portable implementation " Vladimir.Marek
@ 2013-05-12 20:02 ` Jani Nikula
2013-05-12 20:21 ` Vladimir Marek
4 siblings, 1 reply; 24+ messages in thread
From: Jani Nikula @ 2013-05-12 20:02 UTC (permalink / raw)
To: Vladimir.Marek, notmuch
On Mon, 06 May 2013, Vladimir.Marek@oracle.com wrote:
> I can't run the notmuch 'make test' on Solaris (too old bash) and on linux the
> results are
>
> 421/525 tests passed.
> 25 tests failed.
> 79 tests skipped.
>
> but they are the same without my changes too ...
The series LGTM, except I didn't pay much attention to the timegm()
implementation. I hope the time parsing tests pass though. If they do,
and you think the implementation is good enough, then who am I to
argue. ;)
BR,
Jani.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Solaris support - missing or incompatible functions
2013-05-12 20:02 ` Solaris support - missing or incompatible functions Jani Nikula
@ 2013-05-12 20:21 ` Vladimir Marek
2013-05-12 20:45 ` Jani Nikula
0 siblings, 1 reply; 24+ messages in thread
From: Vladimir Marek @ 2013-05-12 20:21 UTC (permalink / raw)
To: Jani Nikula; +Cc: notmuch
> > I can't run the notmuch 'make test' on Solaris (too old bash) and on linux the
> > results are
> >
> > 421/525 tests passed.
> > 25 tests failed.
> > 79 tests skipped.
> >
> > but they are the same without my changes too ...
>
> The series LGTM, except I didn't pay much attention to the timegm()
> implementation. I hope the time parsing tests pass though. If they do,
> and you think the implementation is good enough, then who am I to
> argue. ;)
I didn't pay too much attention to the test output as it's broken on
linux too :)
Thank you
--
Vlad
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Solaris support - missing or incompatible functions
2013-05-12 20:21 ` Vladimir Marek
@ 2013-05-12 20:45 ` Jani Nikula
2013-05-13 5:05 ` Vladimir Marek
0 siblings, 1 reply; 24+ messages in thread
From: Jani Nikula @ 2013-05-12 20:45 UTC (permalink / raw)
To: Vladimir Marek; +Cc: notmuch
On Sun, 12 May 2013, Vladimir Marek <Vladimir.Marek@Oracle.COM> wrote:
> I didn't pay too much attention to the test output as it's broken on
> linux too :)
It shouldn't be. All tests pass for me, and we're pretty strict about
maintaining that.
There may be some prerequisites to running tests that you're missing,
and the test setup fails to tell you about. A pastebin of the 'make
test' output might be helpful.
BR,
Jani.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Solaris support - missing or incompatible functions
2013-05-12 20:45 ` Jani Nikula
@ 2013-05-13 5:05 ` Vladimir Marek
2013-05-18 13:19 ` David Bremner
2013-08-16 12:05 ` Vladimir Marek
0 siblings, 2 replies; 24+ messages in thread
From: Vladimir Marek @ 2013-05-13 5:05 UTC (permalink / raw)
To: Jani Nikula; +Cc: notmuch
> > I didn't pay too much attention to the test output as it's broken on
> > linux too :)
>
> It shouldn't be. All tests pass for me, and we're pretty strict about
> maintaining that.
>
> There may be some prerequisites to running tests that you're missing,
> and the test setup fails to tell you about. A pastebin of the 'make
> test' output might be helpful.
Ok, in that case please let me take a look at the tests first.
--
Vlad
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Solaris support - missing or incompatible functions
2013-05-13 5:05 ` Vladimir Marek
@ 2013-05-18 13:19 ` David Bremner
2013-05-20 9:48 ` Vladimir Marek
2013-08-16 12:05 ` Vladimir Marek
1 sibling, 1 reply; 24+ messages in thread
From: David Bremner @ 2013-05-18 13:19 UTC (permalink / raw)
To: Vladimir Marek, Jani Nikula; +Cc: notmuch
Vladimir Marek <Vladimir.Marek@Oracle.COM> writes:
>>
>> There may be some prerequisites to running tests that you're missing,
>> and the test setup fails to tell you about. A pastebin of the 'make
>> test' output might be helpful.
>
> Ok, in that case please let me take a look at the tests first.
>
For what it's worth, I can confirm no test failures for me either on
linux (Debian wheezy).
d
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Re: Solaris support - missing or incompatible functions
2013-05-18 13:19 ` David Bremner
@ 2013-05-20 9:48 ` Vladimir Marek
2013-05-20 11:10 ` Tomi Ollila
0 siblings, 1 reply; 24+ messages in thread
From: Vladimir Marek @ 2013-05-20 9:48 UTC (permalink / raw)
To: David Bremner; +Cc: notmuch
> >> There may be some prerequisites to running tests that you're missing,
> >> and the test setup fails to tell you about. A pastebin of the 'make
> >> test' output might be helpful.
> >
> > Ok, in that case please let me take a look at the tests first.
> >
>
> For what it's worth, I can confirm no test failures for me either on
> linux (Debian wheezy).
Thank you for looking into that. I'm still not done with fixing the test
suite on Solaris, but form ~70 broken tests I'm at 28. Mostly it's
because Solaris is trying to be posix correct while Linux does not.
There was one surprise though:
A='12\n34'
echo $A
prints two lines on Solaris bug only one line on Linux ('\n' is not
interpreted). That breaks most of json tests as they contain '\n').
Anyway once I'm done I'll have another patch.
--
Vlad
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Re: Solaris support - missing or incompatible functions
2013-05-20 9:48 ` Vladimir Marek
@ 2013-05-20 11:10 ` Tomi Ollila
2013-05-20 13:19 ` Vladimir Marek
0 siblings, 1 reply; 24+ messages in thread
From: Tomi Ollila @ 2013-05-20 11:10 UTC (permalink / raw)
To: Vladimir Marek, David Bremner; +Cc: notmuch
On Mon, May 20 2013, Vladimir Marek <Vladimir.Marek@Oracle.COM> wrote:
>> >> There may be some prerequisites to running tests that you're missing,
>> >> and the test setup fails to tell you about. A pastebin of the 'make
>> >> test' output might be helpful.
>> >
>> > Ok, in that case please let me take a look at the tests first.
>> >
>>
>> For what it's worth, I can confirm no test failures for me either on
>> linux (Debian wheezy).
>
> Thank you for looking into that. I'm still not done with fixing the test
> suite on Solaris, but form ~70 broken tests I'm at 28. Mostly it's
> because Solaris is trying to be posix correct while Linux does not.
>
> There was one surprise though:
>
> A='12\n34'
> echo $A
>
> prints two lines on Solaris bug only one line on Linux ('\n' is not
> interpreted). That breaks most of json tests as they contain '\n').
That must be some setting in (your?) bash:
$ sh -c 'echo '\''foo\nbar'\'''
foo
bar
$ bash -c 'echo '\''foo\nbar'\'''
foo\nbar
$ dash -c 'echo '\''foo\nbar'\'''
foo
bar
... after a bit digging ...
$ bash -c 'shopt -s xpg_echo; echo '\''foo\nbar'\'''
foo
bar
$ bash -c 'shopt -u xpg_echo; echo '\''foo\nbar'\'''
foo\nbar
you could try adding shopt -u xpg_echo into test-lib.sh
Tomi
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Re: Re: Solaris support - missing or incompatible functions
2013-05-20 11:10 ` Tomi Ollila
@ 2013-05-20 13:19 ` Vladimir Marek
0 siblings, 0 replies; 24+ messages in thread
From: Vladimir Marek @ 2013-05-20 13:19 UTC (permalink / raw)
To: Tomi Ollila; +Cc: notmuch
[...]
> That must be some setting in (your?) bash:
>
> $ sh -c 'echo '\''foo\nbar'\'''
> foo
> bar
>
> $ bash -c 'echo '\''foo\nbar'\'''
> foo\nbar
>
> $ dash -c 'echo '\''foo\nbar'\'''
> foo
> bar
>
> ... after a bit digging ...
>
> $ bash -c 'shopt -s xpg_echo; echo '\''foo\nbar'\'''
> foo
> bar
>
> $ bash -c 'shopt -u xpg_echo; echo '\''foo\nbar'\'''
> foo\nbar
>
> you could try adding shopt -u xpg_echo into test-lib.sh
Nice, that's the one! By quickly looking around Solaris it seems that
it's the default compiled in.
Thank you
--
Vlad
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Re: Solaris support - missing or incompatible functions
2013-05-13 5:05 ` Vladimir Marek
2013-05-18 13:19 ` David Bremner
@ 2013-08-16 12:05 ` Vladimir Marek
2013-08-16 12:32 ` Tomi Ollila
1 sibling, 1 reply; 24+ messages in thread
From: Vladimir Marek @ 2013-08-16 12:05 UTC (permalink / raw)
To: Jani Nikula; +Cc: notmuch
Hi,
> > > I didn't pay too much attention to the test output as it's broken on
> > > linux too :)
> >
> > It shouldn't be. All tests pass for me, and we're pretty strict about
> > maintaining that.
> >
> > There may be some prerequisites to running tests that you're missing,
> > and the test setup fails to tell you about. A pastebin of the 'make
> > test' output might be helpful.
>
> Ok, in that case please let me take a look at the tests first.
I'm sorry it took me so long, but finally I got as far as possible with
tests. At the moment the status is
Notmuch test suite complete.
548/557 tests passed.
9 tests failed.
1 test fails because there are new exported symbols in notmuch binary
2 test fails because I don't have gpg
6 test fails because my emacs somehow refuses to send email
With that I would like to ask for including the patches into notmuch
tree. Should I rebase them to the latest git tree or can you push them
as they are?
Thank you
--
Vlad
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Re: Solaris support - missing or incompatible functions
2013-08-16 12:05 ` Vladimir Marek
@ 2013-08-16 12:32 ` Tomi Ollila
0 siblings, 0 replies; 24+ messages in thread
From: Tomi Ollila @ 2013-08-16 12:32 UTC (permalink / raw)
To: Vladimir Marek; +Cc: notmuch
On Fri, Aug 16 2013, Vladimir Marek <Vladimir.Marek@Oracle.COM> wrote:
> Hi,
>
>> > > I didn't pay too much attention to the test output as it's broken on
>> > > linux too :)
>> >
>> > It shouldn't be. All tests pass for me, and we're pretty strict about
>> > maintaining that.
>> >
>> > There may be some prerequisites to running tests that you're missing,
>> > and the test setup fails to tell you about. A pastebin of the 'make
>> > test' output might be helpful.
>>
>> Ok, in that case please let me take a look at the tests first.
>
> I'm sorry it took me so long, but finally I got as far as possible with
> tests. At the moment the status is
>
> Notmuch test suite complete.
> 548/557 tests passed.
> 9 tests failed.
>
> 1 test fails because there are new exported symbols in notmuch binary
> 2 test fails because I don't have gpg
> 6 test fails because my emacs somehow refuses to send email
>
> With that I would like to ask for including the patches into notmuch
> tree. Should I rebase them to the latest git tree or can you push them
> as they are?
Rebase to current tree so we (I) can test those. If those apply
on top of master i run tests and start reviewing those...
>
> Thank you
> --
> Vlad
Tomi
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-16 14:38 Solaris support - missing or incompatible functions (v2) Vladimir.Marek
@ 2013-08-16 14:38 ` Vladimir.Marek
2013-08-17 6:23 ` Tomi Ollila
0 siblings, 1 reply; 24+ messages in thread
From: Vladimir.Marek @ 2013-08-16 14:38 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Blake Jones <blakej@foo.net>
The timegm(3) function is a non-standard extension to libc which is
available in GNU libc and on some BSDs. Although SunOS had this
function in its libc, Solaris (unfortunately) removed it. This patch
implements a very simple version of timegm() which is good enough for
parse-time-string.c.
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/Makefile.local | 4 ++++
compat/compat.h | 5 +++++
compat/have_timegm.c | 7 +++++++
compat/timegm.c | 37 +++++++++++++++++++++++++++++++++
configure | 11 ++++++++++
parse-time-string/parse-time-string.c | 1 +
6 files changed, 65 insertions(+)
create mode 100644 compat/have_timegm.c
create mode 100644 compat/timegm.c
diff --git a/compat/Makefile.local b/compat/Makefile.local
index 2c4f65f..b0d5417 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
notmuch_compat_srcs += $(dir)/strsep.c
endif
+ifneq ($(HAVE_TIMEGM),1)
+notmuch_compat_srcs += $(dir)/timegm.c
+endif
+
SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index ae762c3..5a402d5 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
char *strsep(char **stringp, const char *delim);
#endif /* !HAVE_STRSEP */
+#if !HAVE_TIMEGM
+#include <time.h>
+time_t timegm (struct tm *tm);
+#endif /* !HAVE_TIMEGM */
+
/* Silence gcc warnings about unused results. These warnings exist
* for a reason; any use of this needs to be justified. */
#ifdef __GNUC__
diff --git a/compat/have_timegm.c b/compat/have_timegm.c
new file mode 100644
index 0000000..b62b793
--- /dev/null
+++ b/compat/have_timegm.c
@@ -0,0 +1,7 @@
+#include <time.h>
+#include "compat.h"
+
+int main()
+{
+ return (int) timegm((struct tm *)0);
+}
diff --git a/compat/timegm.c b/compat/timegm.c
new file mode 100644
index 0000000..6d76164
--- /dev/null
+++ b/compat/timegm.c
@@ -0,0 +1,37 @@
+#include <time.h>
+#include "compat.h"
+
+static int
+leapyear (int year)
+{
+ return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
+}
+
+/*
+ * This is a simple implementation of timegm() which does what is needed
+ * by create_output() -- just turns the "struct tm" into a GMT time_t.
+ * It does not normalize any of the fields of the "struct tm", nor does
+ * it set tm_wday or tm_yday.
+ */
+time_t
+timegm (struct tm *tm)
+{
+ int monthlen[2][12] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ };
+ int year, month, days;
+
+ days = 365 * (tm->tm_year - 70);
+ for (year = 70; year < tm->tm_year; year++) {
+ if (leapyear(1900 + year)) {
+ days++;
+ }
+ }
+ for (month = 0; month < tm->tm_mon; month++) {
+ days += monthlen[leapyear(1900 + year)][month];
+ }
+ days += tm->tm_mday - 1;
+
+ return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
+}
diff --git a/configure b/configure
index ac44857..6166917 100755
--- a/configure
+++ b/configure
@@ -530,6 +530,17 @@ else
fi
rm -f compat/have_strsep
+printf "Checking for timegm... "
+if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ have_timegm="1"
+else
+ printf "No (will use our own instead).\n"
+ have_timegm="0"
+fi
+rm -f compat/have_timegm
+
printf "Checking for standard version of getpwuid_r... "
if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
then
diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
index 584067d..ccad422 100644
--- a/parse-time-string/parse-time-string.c
+++ b/parse-time-string/parse-time-string.c
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/types.h>
+#include "compat.h"
#include "parse-time-string.h"
/*
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-16 14:38 ` [PATCH 4/4] timegm: add portable implementation (Solaris support) Vladimir.Marek
@ 2013-08-17 6:23 ` Tomi Ollila
2013-08-20 9:28 ` Vladimir.Marek
2013-08-21 11:09 ` Vladimir.Marek
0 siblings, 2 replies; 24+ messages in thread
From: Tomi Ollila @ 2013-08-17 6:23 UTC (permalink / raw)
To: Vladimir.Marek, notmuch; +Cc: Vladimir Marek
Hi Vladimir, Blake and everyone else.
This patch set looks good to me and tests (in Linux) pass.
From code point of view these patches are IMO pushable.
There is just a small (but not so minor) thing missing;
The timegm(.c) implementation lacks copyright & licensing
information -- all the other compat files that are compiled
into executable does have this information so it is best
to keep this component also in line with those.
If you (either of you) can send new patch 4/4 as a reply to
this message it can be tracked along the first 3 in nmbug (*)
http://nmbug.tethera.net/status/
Tomi
On Fri, Aug 16 2013, Vladimir.Marek@oracle.com wrote:
> From: Blake Jones <blakej@foo.net>
>
> The timegm(3) function is a non-standard extension to libc which is
> available in GNU libc and on some BSDs. Although SunOS had this
> function in its libc, Solaris (unfortunately) removed it. This patch
> implements a very simple version of timegm() which is good enough for
> parse-time-string.c.
>
> Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
> ---
> compat/Makefile.local | 4 ++++
> compat/compat.h | 5 +++++
> compat/have_timegm.c | 7 +++++++
> compat/timegm.c | 37 +++++++++++++++++++++++++++++++++
> configure | 11 ++++++++++
> parse-time-string/parse-time-string.c | 1 +
> 6 files changed, 65 insertions(+)
> create mode 100644 compat/have_timegm.c
> create mode 100644 compat/timegm.c
>
> diff --git a/compat/Makefile.local b/compat/Makefile.local
> index 2c4f65f..b0d5417 100644
> --- a/compat/Makefile.local
> +++ b/compat/Makefile.local
> @@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
> notmuch_compat_srcs += $(dir)/strsep.c
> endif
>
> +ifneq ($(HAVE_TIMEGM),1)
> +notmuch_compat_srcs += $(dir)/timegm.c
> +endif
> +
> SRCS := $(SRCS) $(notmuch_compat_srcs)
> diff --git a/compat/compat.h b/compat/compat.h
> index ae762c3..5a402d5 100644
> --- a/compat/compat.h
> +++ b/compat/compat.h
> @@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
> char *strsep(char **stringp, const char *delim);
> #endif /* !HAVE_STRSEP */
>
> +#if !HAVE_TIMEGM
> +#include <time.h>
> +time_t timegm (struct tm *tm);
> +#endif /* !HAVE_TIMEGM */
> +
> /* Silence gcc warnings about unused results. These warnings exist
> * for a reason; any use of this needs to be justified. */
> #ifdef __GNUC__
> diff --git a/compat/have_timegm.c b/compat/have_timegm.c
> new file mode 100644
> index 0000000..b62b793
> --- /dev/null
> +++ b/compat/have_timegm.c
> @@ -0,0 +1,7 @@
> +#include <time.h>
> +#include "compat.h"
> +
> +int main()
> +{
> + return (int) timegm((struct tm *)0);
> +}
> diff --git a/compat/timegm.c b/compat/timegm.c
> new file mode 100644
> index 0000000..6d76164
> --- /dev/null
> +++ b/compat/timegm.c
> @@ -0,0 +1,37 @@
> +#include <time.h>
> +#include "compat.h"
> +
> +static int
> +leapyear (int year)
> +{
> + return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
> +}
> +
> +/*
> + * This is a simple implementation of timegm() which does what is needed
> + * by create_output() -- just turns the "struct tm" into a GMT time_t.
> + * It does not normalize any of the fields of the "struct tm", nor does
> + * it set tm_wday or tm_yday.
> + */
> +time_t
> +timegm (struct tm *tm)
> +{
> + int monthlen[2][12] = {
> + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
> + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
> + };
> + int year, month, days;
> +
> + days = 365 * (tm->tm_year - 70);
> + for (year = 70; year < tm->tm_year; year++) {
> + if (leapyear(1900 + year)) {
> + days++;
> + }
> + }
> + for (month = 0; month < tm->tm_mon; month++) {
> + days += monthlen[leapyear(1900 + year)][month];
> + }
> + days += tm->tm_mday - 1;
> +
> + return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
> +}
> diff --git a/configure b/configure
> index ac44857..6166917 100755
> --- a/configure
> +++ b/configure
> @@ -530,6 +530,17 @@ else
> fi
> rm -f compat/have_strsep
>
> +printf "Checking for timegm... "
> +if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
> +then
> + printf "Yes.\n"
> + have_timegm="1"
> +else
> + printf "No (will use our own instead).\n"
> + have_timegm="0"
> +fi
> +rm -f compat/have_timegm
> +
> printf "Checking for standard version of getpwuid_r... "
> if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
> then
> diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
> index 584067d..ccad422 100644
> --- a/parse-time-string/parse-time-string.c
> +++ b/parse-time-string/parse-time-string.c
> @@ -32,6 +32,7 @@
> #include <sys/time.h>
> #include <sys/types.h>
>
> +#include "compat.h"
> #include "parse-time-string.h"
>
> /*
> --
> 1.7.9.2
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-17 6:23 ` Tomi Ollila
@ 2013-08-20 9:28 ` Vladimir.Marek
2013-08-20 15:33 ` Blake Jones
2013-08-21 11:09 ` Vladimir.Marek
1 sibling, 1 reply; 24+ messages in thread
From: Vladimir.Marek @ 2013-08-20 9:28 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Blake Jones <blakej@foo.net>
The timegm(3) function is a non-standard extension to libc which is
available in GNU libc and on some BSDs. Although SunOS had this
function in its libc, Solaris (unfortunately) removed it. This patch
implements a very simple version of timegm() which is good enough for
parse-time-string.c.
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/Makefile.local | 4 +++
compat/compat.h | 5 +++
compat/have_timegm.c | 7 ++++
compat/timegm.c | 57 +++++++++++++++++++++++++++++++++
configure | 11 +++++++
parse-time-string/parse-time-string.c | 1 +
6 files changed, 85 insertions(+)
create mode 100644 compat/have_timegm.c
create mode 100644 compat/timegm.c
diff --git a/compat/Makefile.local b/compat/Makefile.local
index 2c4f65f..b0d5417 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
notmuch_compat_srcs += $(dir)/strsep.c
endif
+ifneq ($(HAVE_TIMEGM),1)
+notmuch_compat_srcs += $(dir)/timegm.c
+endif
+
SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index ae762c3..5a402d5 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
char *strsep(char **stringp, const char *delim);
#endif /* !HAVE_STRSEP */
+#if !HAVE_TIMEGM
+#include <time.h>
+time_t timegm (struct tm *tm);
+#endif /* !HAVE_TIMEGM */
+
/* Silence gcc warnings about unused results. These warnings exist
* for a reason; any use of this needs to be justified. */
#ifdef __GNUC__
diff --git a/compat/have_timegm.c b/compat/have_timegm.c
new file mode 100644
index 0000000..b62b793
--- /dev/null
+++ b/compat/have_timegm.c
@@ -0,0 +1,7 @@
+#include <time.h>
+#include "compat.h"
+
+int main()
+{
+ return (int) timegm((struct tm *)0);
+}
diff --git a/compat/timegm.c b/compat/timegm.c
new file mode 100644
index 0000000..213963b
--- /dev/null
+++ b/compat/timegm.c
@@ -0,0 +1,57 @@
+/* timegm.c --- Implementation of replacement timegm function.
+ Copyright (C) 2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Written by Blake Jones. */
+
+#include <time.h>
+#include "compat.h"
+
+static int
+leapyear (int year)
+{
+ return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
+}
+
+/*
+ * This is a simple implementation of timegm() which does what is needed
+ * by create_output() -- just turns the "struct tm" into a GMT time_t.
+ * It does not normalize any of the fields of the "struct tm", nor does
+ * it set tm_wday or tm_yday.
+ */
+time_t
+timegm (struct tm *tm)
+{
+ int monthlen[2][12] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ };
+ int year, month, days;
+
+ days = 365 * (tm->tm_year - 70);
+ for (year = 70; year < tm->tm_year; year++) {
+ if (leapyear(1900 + year)) {
+ days++;
+ }
+ }
+ for (month = 0; month < tm->tm_mon; month++) {
+ days += monthlen[leapyear(1900 + year)][month];
+ }
+ days += tm->tm_mday - 1;
+
+ return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
+}
diff --git a/configure b/configure
index ac44857..6166917 100755
--- a/configure
+++ b/configure
@@ -530,6 +530,17 @@ else
fi
rm -f compat/have_strsep
+printf "Checking for timegm... "
+if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ have_timegm="1"
+else
+ printf "No (will use our own instead).\n"
+ have_timegm="0"
+fi
+rm -f compat/have_timegm
+
printf "Checking for standard version of getpwuid_r... "
if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
then
diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
index 584067d..ccad422 100644
--- a/parse-time-string/parse-time-string.c
+++ b/parse-time-string/parse-time-string.c
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/types.h>
+#include "compat.h"
#include "parse-time-string.h"
/*
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-20 9:28 ` Vladimir.Marek
@ 2013-08-20 15:33 ` Blake Jones
2013-08-20 16:03 ` Tomi Ollila
0 siblings, 1 reply; 24+ messages in thread
From: Blake Jones @ 2013-08-20 15:33 UTC (permalink / raw)
To: Vladimir.Marek; +Cc: notmuch, Vladimir Marek
> From: Blake Jones <blakej@foo.net>
>
> The timegm(3) function is a non-standard extension to libc which is
> available in GNU libc and on some BSDs. Although SunOS had this
> function in its libc, Solaris (unfortunately) removed it. This patch
> implements a very simple version of timegm() which is good enough for
> parse-time-string.c.
LGTM.
Blake
> Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
> ---
> compat/Makefile.local | 4 +++
> compat/compat.h | 5 +++
> compat/have_timegm.c | 7 ++++
> compat/timegm.c | 57 +++++++++++++++++++++++++++++++++
> configure | 11 +++++++
> parse-time-string/parse-time-string.c | 1 +
> 6 files changed, 85 insertions(+)
> create mode 100644 compat/have_timegm.c
> create mode 100644 compat/timegm.c
>
> diff --git a/compat/Makefile.local b/compat/Makefile.local
> index 2c4f65f..b0d5417 100644
> --- a/compat/Makefile.local
> +++ b/compat/Makefile.local
> @@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
> notmuch_compat_srcs += $(dir)/strsep.c
> endif
>
> +ifneq ($(HAVE_TIMEGM),1)
> +notmuch_compat_srcs += $(dir)/timegm.c
> +endif
> +
> SRCS := $(SRCS) $(notmuch_compat_srcs)
> diff --git a/compat/compat.h b/compat/compat.h
> index ae762c3..5a402d5 100644
> --- a/compat/compat.h
> +++ b/compat/compat.h
> @@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
> char *strsep(char **stringp, const char *delim);
> #endif /* !HAVE_STRSEP */
>
> +#if !HAVE_TIMEGM
> +#include <time.h>
> +time_t timegm (struct tm *tm);
> +#endif /* !HAVE_TIMEGM */
> +
> /* Silence gcc warnings about unused results. These warnings exist
> * for a reason; any use of this needs to be justified. */
> #ifdef __GNUC__
> diff --git a/compat/have_timegm.c b/compat/have_timegm.c
> new file mode 100644
> index 0000000..b62b793
> --- /dev/null
> +++ b/compat/have_timegm.c
> @@ -0,0 +1,7 @@
> +#include <time.h>
> +#include "compat.h"
> +
> +int main()
> +{
> + return (int) timegm((struct tm *)0);
> +}
> diff --git a/compat/timegm.c b/compat/timegm.c
> new file mode 100644
> index 0000000..213963b
> --- /dev/null
> +++ b/compat/timegm.c
> @@ -0,0 +1,57 @@
> +/* timegm.c --- Implementation of replacement timegm function.
> + Copyright (C) 2012 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or
> + modify it under the terms of the GNU General Public License as
> + published by the Free Software Foundation; either version 3, or (at
> + your option) any later version.
> +
> + This program is distributed in the hope that it will be useful, but
> + WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + 02110-1301, USA. */
> +
> +/* Written by Blake Jones. */
> +
> +#include <time.h>
> +#include "compat.h"
> +
> +static int
> +leapyear (int year)
> +{
> + return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
> +}
> +
> +/*
> + * This is a simple implementation of timegm() which does what is needed
> + * by create_output() -- just turns the "struct tm" into a GMT time_t.
> + * It does not normalize any of the fields of the "struct tm", nor does
> + * it set tm_wday or tm_yday.
> + */
> +time_t
> +timegm (struct tm *tm)
> +{
> + int monthlen[2][12] = {
> + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
> + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
> + };
> + int year, month, days;
> +
> + days = 365 * (tm->tm_year - 70);
> + for (year = 70; year < tm->tm_year; year++) {
> + if (leapyear(1900 + year)) {
> + days++;
> + }
> + }
> + for (month = 0; month < tm->tm_mon; month++) {
> + days += monthlen[leapyear(1900 + year)][month];
> + }
> + days += tm->tm_mday - 1;
> +
> + return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
> +}
> diff --git a/configure b/configure
> index ac44857..6166917 100755
> --- a/configure
> +++ b/configure
> @@ -530,6 +530,17 @@ else
> fi
> rm -f compat/have_strsep
>
> +printf "Checking for timegm... "
> +if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
> +then
> + printf "Yes.\n"
> + have_timegm="1"
> +else
> + printf "No (will use our own instead).\n"
> + have_timegm="0"
> +fi
> +rm -f compat/have_timegm
> +
> printf "Checking for standard version of getpwuid_r... "
> if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
> then
> diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
> index 584067d..ccad422 100644
> --- a/parse-time-string/parse-time-string.c
> +++ b/parse-time-string/parse-time-string.c
> @@ -32,6 +32,7 @@
> #include <sys/time.h>
> #include <sys/types.h>
>
> +#include "compat.h"
> #include "parse-time-string.h"
>
> /*
> --
> 1.7.9.2
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-20 15:33 ` Blake Jones
@ 2013-08-20 16:03 ` Tomi Ollila
2013-08-20 16:29 ` Blake Jones
0 siblings, 1 reply; 24+ messages in thread
From: Tomi Ollila @ 2013-08-20 16:03 UTC (permalink / raw)
To: Blake Jones, Vladimir.Marek; +Cc: notmuch, Vladimir Marek
On Tue, Aug 20 2013, Blake Jones <blakej@foo.net> wrote:
>> From: Blake Jones <blakej@foo.net>
>>
>> The timegm(3) function is a non-standard extension to libc which is
>> available in GNU libc and on some BSDs. Although SunOS had this
>> function in its libc, Solaris (unfortunately) removed it. This patch
>> implements a very simple version of timegm() which is good enough for
>> parse-time-string.c.
>
> LGTM.
>
> Blake
Thanks Blake for your quick answer to my (perhaps too quick) question.
The copyright header gives FSF "owner"ship to the file -- which would be fine
by the project -- but does assigning copyright to the FSF work like this...
... I started to look around and found (among other pages) this:
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/Copyright/conditions.text;h=6e19adf0233900c9169e10fe7e0aa8d1feb73996;hb=HEAD
Maybe for liability reasons FSF needs more than just stating the copyright
at the beginning of file... I don't know -- but if this is the case maybe
the easiest thing is to remove (amend) the Copyright line out of the file.
In getline.c, and getdelim.c the code is taken from glibc. What I've
understood this timegm.c is new art ?
IMHO this uncertainty is the last thing preventing putting this series
to the nmbug ready (to be pushed) queue...
Tomi
>
>> Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
>> ---
>> compat/Makefile.local | 4 +++
>> compat/compat.h | 5 +++
>> compat/have_timegm.c | 7 ++++
>> compat/timegm.c | 57 +++++++++++++++++++++++++++++++++
>> configure | 11 +++++++
>> parse-time-string/parse-time-string.c | 1 +
>> 6 files changed, 85 insertions(+)
>> create mode 100644 compat/have_timegm.c
>> create mode 100644 compat/timegm.c
>>
>> diff --git a/compat/Makefile.local b/compat/Makefile.local
>> index 2c4f65f..b0d5417 100644
>> --- a/compat/Makefile.local
>> +++ b/compat/Makefile.local
>> @@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
>> notmuch_compat_srcs += $(dir)/strsep.c
>> endif
>>
>> +ifneq ($(HAVE_TIMEGM),1)
>> +notmuch_compat_srcs += $(dir)/timegm.c
>> +endif
>> +
>> SRCS := $(SRCS) $(notmuch_compat_srcs)
>> diff --git a/compat/compat.h b/compat/compat.h
>> index ae762c3..5a402d5 100644
>> --- a/compat/compat.h
>> +++ b/compat/compat.h
>> @@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
>> char *strsep(char **stringp, const char *delim);
>> #endif /* !HAVE_STRSEP */
>>
>> +#if !HAVE_TIMEGM
>> +#include <time.h>
>> +time_t timegm (struct tm *tm);
>> +#endif /* !HAVE_TIMEGM */
>> +
>> /* Silence gcc warnings about unused results. These warnings exist
>> * for a reason; any use of this needs to be justified. */
>> #ifdef __GNUC__
>> diff --git a/compat/have_timegm.c b/compat/have_timegm.c
>> new file mode 100644
>> index 0000000..b62b793
>> --- /dev/null
>> +++ b/compat/have_timegm.c
>> @@ -0,0 +1,7 @@
>> +#include <time.h>
>> +#include "compat.h"
>> +
>> +int main()
>> +{
>> + return (int) timegm((struct tm *)0);
>> +}
>> diff --git a/compat/timegm.c b/compat/timegm.c
>> new file mode 100644
>> index 0000000..213963b
>> --- /dev/null
>> +++ b/compat/timegm.c
>> @@ -0,0 +1,57 @@
>> +/* timegm.c --- Implementation of replacement timegm function.
>> + Copyright (C) 2012 Free Software Foundation, Inc.
>> +
>> + This program is free software; you can redistribute it and/or
>> + modify it under the terms of the GNU General Public License as
>> + published by the Free Software Foundation; either version 3, or (at
>> + your option) any later version.
>> +
>> + This program is distributed in the hope that it will be useful, but
>> + WITHOUT ANY WARRANTY; without even the implied warranty of
>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>> + General Public License for more details.
>> +
>> + You should have received a copy of the GNU General Public License
>> + along with this program; if not, write to the Free Software
>> + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> + 02110-1301, USA. */
>> +
>> +/* Written by Blake Jones. */
>> +
>> +#include <time.h>
>> +#include "compat.h"
>> +
>> +static int
>> +leapyear (int year)
>> +{
>> + return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
>> +}
>> +
>> +/*
>> + * This is a simple implementation of timegm() which does what is needed
>> + * by create_output() -- just turns the "struct tm" into a GMT time_t.
>> + * It does not normalize any of the fields of the "struct tm", nor does
>> + * it set tm_wday or tm_yday.
>> + */
>> +time_t
>> +timegm (struct tm *tm)
>> +{
>> + int monthlen[2][12] = {
>> + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
>> + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
>> + };
>> + int year, month, days;
>> +
>> + days = 365 * (tm->tm_year - 70);
>> + for (year = 70; year < tm->tm_year; year++) {
>> + if (leapyear(1900 + year)) {
>> + days++;
>> + }
>> + }
>> + for (month = 0; month < tm->tm_mon; month++) {
>> + days += monthlen[leapyear(1900 + year)][month];
>> + }
>> + days += tm->tm_mday - 1;
>> +
>> + return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
>> +}
>> diff --git a/configure b/configure
>> index ac44857..6166917 100755
>> --- a/configure
>> +++ b/configure
>> @@ -530,6 +530,17 @@ else
>> fi
>> rm -f compat/have_strsep
>>
>> +printf "Checking for timegm... "
>> +if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
>> +then
>> + printf "Yes.\n"
>> + have_timegm="1"
>> +else
>> + printf "No (will use our own instead).\n"
>> + have_timegm="0"
>> +fi
>> +rm -f compat/have_timegm
>> +
>> printf "Checking for standard version of getpwuid_r... "
>> if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
>> then
>> diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
>> index 584067d..ccad422 100644
>> --- a/parse-time-string/parse-time-string.c
>> +++ b/parse-time-string/parse-time-string.c
>> @@ -32,6 +32,7 @@
>> #include <sys/time.h>
>> #include <sys/types.h>
>>
>> +#include "compat.h"
>> #include "parse-time-string.h"
>>
>> /*
>> --
>> 1.7.9.2
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch
>>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-20 16:03 ` Tomi Ollila
@ 2013-08-20 16:29 ` Blake Jones
0 siblings, 0 replies; 24+ messages in thread
From: Blake Jones @ 2013-08-20 16:29 UTC (permalink / raw)
To: Tomi Ollila; +Cc: notmuch, Vladimir Marek
> The copyright header gives FSF "owner"ship to the file -- which would
> be fine by the project -- but does assigning copyright to the FSF work
> like this... ... I started to look around and found (among other
> pages) this:
>
> http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/Copyright/conditions.text;h=6e19adf0233900c9169
> e10fe7e0aa8d1feb73996;hb=HEAD
>
> Maybe for liability reasons FSF needs more than just stating the
> copyright at the beginning of file... I don't know -- but if this is
> the case maybe the easiest thing is to remove (amend) the Copyright
> line out of the file.
I don't really care what sort of copyright it has. Vladimir is the one
with the up-to-date tree at this point, so he would be best positioned
to update the text with whatever works best for the rest of notmuch.
> In getline.c, and getdelim.c the code is taken from glibc. What I've
> understood this timegm.c is new art ?
To the best of my recollection, yes, I implemented this version of
timegm() from scratch, based on my understanding of what it needed to
do.
Blake
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-17 6:23 ` Tomi Ollila
2013-08-20 9:28 ` Vladimir.Marek
@ 2013-08-21 11:09 ` Vladimir.Marek
2013-08-21 11:26 ` Tomi Ollila
2013-08-23 16:06 ` David Bremner
1 sibling, 2 replies; 24+ messages in thread
From: Vladimir.Marek @ 2013-08-21 11:09 UTC (permalink / raw)
To: notmuch; +Cc: Vladimir Marek
From: Blake Jones <blakej@foo.net>
The timegm(3) function is a non-standard extension to libc which is
available in GNU libc and on some BSDs. Although SunOS had this
function in its libc, Solaris (unfortunately) removed it. This patch
implements a very simple version of timegm() which is good enough for
parse-time-string.c.
Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
---
compat/Makefile.local | 4 +++
compat/compat.h | 5 +++
compat/have_timegm.c | 7 +++++
compat/timegm.c | 56 +++++++++++++++++++++++++++++++++
configure | 11 +++++++
parse-time-string/parse-time-string.c | 1 +
6 files changed, 84 insertions(+)
create mode 100644 compat/have_timegm.c
create mode 100644 compat/timegm.c
diff --git a/compat/Makefile.local b/compat/Makefile.local
index 2c4f65f..b0d5417 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)
notmuch_compat_srcs += $(dir)/strsep.c
endif
+ifneq ($(HAVE_TIMEGM),1)
+notmuch_compat_srcs += $(dir)/timegm.c
+endif
+
SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index ae762c3..5a402d5 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);
char *strsep(char **stringp, const char *delim);
#endif /* !HAVE_STRSEP */
+#if !HAVE_TIMEGM
+#include <time.h>
+time_t timegm (struct tm *tm);
+#endif /* !HAVE_TIMEGM */
+
/* Silence gcc warnings about unused results. These warnings exist
* for a reason; any use of this needs to be justified. */
#ifdef __GNUC__
diff --git a/compat/have_timegm.c b/compat/have_timegm.c
new file mode 100644
index 0000000..b62b793
--- /dev/null
+++ b/compat/have_timegm.c
@@ -0,0 +1,7 @@
+#include <time.h>
+#include "compat.h"
+
+int main()
+{
+ return (int) timegm((struct tm *)0);
+}
diff --git a/compat/timegm.c b/compat/timegm.c
new file mode 100644
index 0000000..a986887
--- /dev/null
+++ b/compat/timegm.c
@@ -0,0 +1,56 @@
+/* timegm.c --- Implementation of replacement timegm function.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Written by Blake Jones. */
+
+#include <time.h>
+#include "compat.h"
+
+static int
+leapyear (int year)
+{
+ return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
+}
+
+/*
+ * This is a simple implementation of timegm() which does what is needed
+ * by create_output() -- just turns the "struct tm" into a GMT time_t.
+ * It does not normalize any of the fields of the "struct tm", nor does
+ * it set tm_wday or tm_yday.
+ */
+time_t
+timegm (struct tm *tm)
+{
+ int monthlen[2][12] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ };
+ int year, month, days;
+
+ days = 365 * (tm->tm_year - 70);
+ for (year = 70; year < tm->tm_year; year++) {
+ if (leapyear(1900 + year)) {
+ days++;
+ }
+ }
+ for (month = 0; month < tm->tm_mon; month++) {
+ days += monthlen[leapyear(1900 + year)][month];
+ }
+ days += tm->tm_mday - 1;
+
+ return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
+}
diff --git a/configure b/configure
index ac44857..6166917 100755
--- a/configure
+++ b/configure
@@ -530,6 +530,17 @@ else
fi
rm -f compat/have_strsep
+printf "Checking for timegm... "
+if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+ have_timegm="1"
+else
+ printf "No (will use our own instead).\n"
+ have_timegm="0"
+fi
+rm -f compat/have_timegm
+
printf "Checking for standard version of getpwuid_r... "
if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1
then
diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c
index 584067d..ccad422 100644
--- a/parse-time-string/parse-time-string.c
+++ b/parse-time-string/parse-time-string.c
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/types.h>
+#include "compat.h"
#include "parse-time-string.h"
/*
--
1.7.9.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-21 11:09 ` Vladimir.Marek
@ 2013-08-21 11:26 ` Tomi Ollila
2013-08-23 16:06 ` David Bremner
1 sibling, 0 replies; 24+ messages in thread
From: Tomi Ollila @ 2013-08-21 11:26 UTC (permalink / raw)
To: Vladimir.Marek, notmuch; +Cc: Vladimir Marek
On Wed, Aug 21 2013, Vladimir.Marek@oracle.com wrote:
> From: Blake Jones <blakej@foo.net>
>
> The timegm(3) function is a non-standard extension to libc which is
> available in GNU libc and on some BSDs. Although SunOS had this
> function in its libc, Solaris (unfortunately) removed it. This patch
> implements a very simple version of timegm() which is good enough for
> parse-time-string.c.
>
> Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
> ---
Thanks, LGTM.
> compat/Makefile.local | 4 +++
> compat/compat.h | 5 +++
> compat/have_timegm.c | 7 +++++
> compat/timegm.c | 56 +++++++++++++++++++++++++++++++++
> configure | 11 +++++++
> parse-time-string/parse-time-string.c | 1 +
> 6 files changed, 84 insertions(+)
> create mode 100644 compat/have_timegm.c
> create mode 100644 compat/timegm.c
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 4/4] timegm: add portable implementation (Solaris support)
2013-08-21 11:09 ` Vladimir.Marek
2013-08-21 11:26 ` Tomi Ollila
@ 2013-08-23 16:06 ` David Bremner
1 sibling, 0 replies; 24+ messages in thread
From: David Bremner @ 2013-08-23 16:06 UTC (permalink / raw)
To: Vladimir.Marek, notmuch
Vladimir.Marek@oracle.com writes:
> From: Blake Jones <blakej@foo.net>
>
> The timegm(3) function is a non-standard extension to libc which is
> available in GNU libc and on some BSDs. Although SunOS had this
> function in its libc, Solaris (unfortunately) removed it. This patch
> implements a very simple version of timegm() which is good enough for
> parse-time-string.c.
I pushed these 4 patches, with the small amendment of
s/Written by Blake Jones/Copyright 2013 Blake Jones/
Hope that's ok
d
^ permalink raw reply [flat|nested] 24+ messages in thread