* [PATCH 1/4] getpwuid: check for standards compliance (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-16 14:38 ` [PATCH 2/4] asctime: " Vladimir.Marek
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ 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>
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 3ba1ec3..b5465e4 100755
--- a/configure
+++ b/configure
@@ -519,6 +519,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... "
@@ -681,6 +692,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}
@@ -725,10 +741,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] 14+ messages in thread
* [PATCH 2/4] asctime: check for standards compliance (Solaris support)
2013-08-16 14:38 Solaris support - missing or incompatible functions (v2) Vladimir.Marek
2013-08-16 14:38 ` [PATCH 1/4] getpwuid: check for standards compliance (Solaris support) Vladimir.Marek
@ 2013-08-16 14:38 ` Vladimir.Marek
2013-08-16 14:38 ` [PATCH 3/4] strsep: check for availability " Vladimir.Marek
2013-08-16 14:38 ` [PATCH 4/4] timegm: add portable implementation " Vladimir.Marek
3 siblings, 0 replies; 14+ messages in thread
From: Vladimir.Marek @ 2013-08-16 14:38 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 b5465e4..e3aa857 100755
--- a/configure
+++ b/configure
@@ -530,6 +530,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... "
@@ -697,6 +708,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}
@@ -743,11 +759,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] 14+ messages in thread
* [PATCH 3/4] strsep: check for availability (Solaris support)
2013-08-16 14:38 Solaris support - missing or incompatible functions (v2) Vladimir.Marek
2013-08-16 14:38 ` [PATCH 1/4] getpwuid: check for standards compliance (Solaris support) Vladimir.Marek
2013-08-16 14:38 ` [PATCH 2/4] asctime: " Vladimir.Marek
@ 2013-08-16 14:38 ` Vladimir.Marek
2013-08-16 14:38 ` [PATCH 4/4] timegm: add portable implementation " Vladimir.Marek
3 siblings, 0 replies; 14+ 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>
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 e3aa857..ac44857 100755
--- a/configure
+++ b/configure
@@ -519,6 +519,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
@@ -703,6 +714,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)
@@ -759,12 +774,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] 14+ 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
` (2 preceding siblings ...)
2013-08-16 14:38 ` [PATCH 3/4] strsep: check for availability " Vladimir.Marek
@ 2013-08-16 14:38 ` Vladimir.Marek
2013-08-17 6:23 ` Tomi Ollila
3 siblings, 1 reply; 14+ 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] 14+ 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 " 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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; 14+ 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] 14+ 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
@ 2013-05-06 15:16 ` Vladimir.Marek
0 siblings, 0 replies; 14+ 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] 14+ messages in thread