From 0a1a19d9d95b5adbe6c3dd3ed689ce7e3b43ab12 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 30 May 2006 05:57:43 +0000 Subject: r15953: our timegm() replacement still doesn't work, so grab the one from Heimdal which does work. This should fix most of the rest of the failures on solaris (This used to be commit acfaa98b5ea686feb81350baf09b3f4480f96edc) --- source4/lib/replace/timegm.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 source4/lib/replace/timegm.c (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c new file mode 100644 index 0000000000..f2741e0eff --- /dev/null +++ b/source4/lib/replace/timegm.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + adapted for Samba4 by Andrew Tridgell +*/ + +#include "includes.h" +#include "system/time.h" + +#ifndef HAVE_TIMEGM + +static int is_leap(unsigned y) +{ + y += 1900; + return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); +} + +time_t timegm(struct tm *tm) +{ + static const unsigned ndays[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}}; + time_t res = 0; + unsigned i; + + for (i = 70; i < tm->tm_year; ++i) + res += is_leap(i) ? 366 : 365; + + for (i = 0; i < tm->tm_mon; ++i) + res += ndays[is_leap(tm->tm_year)][i]; + res += tm->tm_mday - 1; + res *= 24; + res += tm->tm_hour; + res *= 60; + res += tm->tm_min; + res *= 60; + res += tm->tm_sec; + return res; +} + +#endif /* HAVE_TIMEGM */ -- cgit From 09129c73d7b7fc97478fe642dc43f7e5ce9a2ba9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 23 Aug 2006 11:32:29 +0000 Subject: r17750: these have moved to ldb/replace/ now (This used to be commit ac178b52935d7629f8583092e833b74093ca70e1) --- source4/lib/replace/timegm.c | 72 -------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 source4/lib/replace/timegm.c (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c deleted file mode 100644 index f2741e0eff..0000000000 --- a/source4/lib/replace/timegm.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1997 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - adapted for Samba4 by Andrew Tridgell -*/ - -#include "includes.h" -#include "system/time.h" - -#ifndef HAVE_TIMEGM - -static int is_leap(unsigned y) -{ - y += 1900; - return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); -} - -time_t timegm(struct tm *tm) -{ - static const unsigned ndays[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}}; - time_t res = 0; - unsigned i; - - for (i = 70; i < tm->tm_year; ++i) - res += is_leap(i) ? 366 : 365; - - for (i = 0; i < tm->tm_mon; ++i) - res += ndays[is_leap(tm->tm_year)][i]; - res += tm->tm_mday - 1; - res *= 24; - res += tm->tm_hour; - res *= 60; - res += tm->tm_min; - res *= 60; - res += tm->tm_sec; - return res; -} - -#endif /* HAVE_TIMEGM */ -- cgit From 38fdde5d9bf15b10caa60ee216d278ba8d870c2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 4 Sep 2006 12:21:42 +0000 Subject: r18031: Merge my replace fixes: * libreplace can now build stand-alone * add stub testsuite for libreplace * make talloc/tdb/ldb use libreplace (This used to be commit fe7ca4b1454e01a33ed0d53791ebffdd349298b4) --- source4/lib/replace/timegm.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 source4/lib/replace/timegm.c (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c new file mode 100644 index 0000000000..5fb15475f3 --- /dev/null +++ b/source4/lib/replace/timegm.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + adapted for Samba4 by Andrew Tridgell +*/ + +#include "includes.h" +#include "ldb/include/includes.h" + +#ifndef HAVE_TIMEGM + +static int is_leap(unsigned y) +{ + y += 1900; + return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); +} + +time_t timegm(struct tm *tm) +{ + static const unsigned ndays[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}}; + time_t res = 0; + unsigned i; + + for (i = 70; i < tm->tm_year; ++i) + res += is_leap(i) ? 366 : 365; + + for (i = 0; i < tm->tm_mon; ++i) + res += ndays[is_leap(tm->tm_year)][i]; + res += tm->tm_mday - 1; + res *= 24; + res += tm->tm_hour; + res *= 60; + res += tm->tm_min; + res *= 60; + res += tm->tm_sec; + return res; +} + +#endif /* HAVE_TIMEGM */ -- cgit From cb962c93737e8d0facdcd26461aaea5062a3b21d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Sep 2006 13:35:03 +0000 Subject: r18044: timegm.c needs to be in a separate file (This used to be commit 3ec1db7bd12cdc233c37f261073a33fc48ecd7ce) --- source4/lib/replace/timegm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index 5fb15475f3..1c9a0e4165 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -35,8 +35,8 @@ adapted for Samba4 by Andrew Tridgell */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "replace.h" +#include #ifndef HAVE_TIMEGM -- cgit From a587277aa31dcb9dc46e02e165e2c4ebb6e2be1a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 5 Sep 2006 02:03:22 +0000 Subject: r18055: aix needs time.h for timegm.c to compile (This used to be commit 1c91de687f0078100aa9de9111416c9fced45990) --- source4/lib/replace/timegm.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index 1c9a0e4165..c2746db1a4 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -40,6 +40,14 @@ #ifndef HAVE_TIMEGM +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#ifdef TIME_H +#include +#endif + static int is_leap(unsigned y) { y += 1900; -- cgit From 3539b6ae7b6c4187927e30582fde7f8b40672833 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 5 Sep 2006 04:19:16 +0000 Subject: r18057: fixed an #ifdef (This used to be commit e4c3b9ea2fd47540f693ced2fa6b7aa55372315b) --- source4/lib/replace/timegm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index c2746db1a4..bd20da703f 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -44,7 +44,7 @@ #include #endif -#ifdef TIME_H +#ifdef HAVE_TIME_H #include #endif -- cgit From 4c0b19277a495b33869f447166d03a0e1e163b72 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 13 Sep 2006 10:51:26 +0000 Subject: r18460: split out timegm test and only add timegm.o when needed metze (This used to be commit f9bff4dbdad8c7acc649d13a5666b58967bf5d92) --- source4/lib/replace/timegm.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index bd20da703f..ff90626d44 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -36,17 +36,7 @@ */ #include "replace.h" -#include - -#ifndef HAVE_TIMEGM - -#ifdef HAVE_SYS_TIME_H -#include -#endif - -#ifdef HAVE_TIME_H -#include -#endif +#include "system/time.h" static int is_leap(unsigned y) { @@ -76,5 +66,3 @@ time_t timegm(struct tm *tm) res += tm->tm_sec; return res; } - -#endif /* HAVE_TIMEGM */ -- cgit From d04efb30a013c3c9061f62081fc6fc020bbbd7b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Oct 2006 22:33:20 +0000 Subject: r19403: try to fix the crashes in the buildfarm related to timegm (This used to be commit c4e1d2c5ae11acac7dd2cedca411b9b6be84962f) --- source4/lib/replace/timegm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index ff90626d44..608882d0ce 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -44,13 +44,22 @@ static int is_leap(unsigned y) return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); } -time_t timegm(struct tm *tm) +time_t rep_timegm(struct tm *tm) { static const unsigned ndays[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}}; time_t res = 0; unsigned i; + + if (tm->tm_mon > 12 || + tm->tm_mday > 31 || + tm->tm_min > 60 || + tm->tm_sec > 60 || + tm->tm_hour > 24) { + /* invalid tm structure */ + return 0; + } for (i = 70; i < tm->tm_year; ++i) res += is_leap(i) ? 366 : 365; -- cgit From 0ec080d505aa5238ca3733454905f5ce9f65d6dc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 19 Oct 2006 03:04:00 +0000 Subject: r19408: I think tm_mon is ending up as -1 on some platforms (This used to be commit d01bdf1f2dcdf77043a5ad162ee336d3c6f2e944) --- source4/lib/replace/timegm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index 608882d0ce..395c684e11 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -53,6 +53,7 @@ time_t rep_timegm(struct tm *tm) unsigned i; if (tm->tm_mon > 12 || + tm->tm_mon < 0 || tm->tm_mday > 31 || tm->tm_min > 60 || tm->tm_sec > 60 || -- cgit From 3e75f222bcdf114238cc4f2bcc61332dc059135f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 19 Dec 2007 23:27:42 +0100 Subject: r26539: Remove unnecessary statics. (This used to be commit e53e79eebef3ece6978f0a2b4a1ee0a0814bb5d2) --- source4/lib/replace/timegm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index 395c684e11..86f360bd3c 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -46,7 +46,7 @@ static int is_leap(unsigned y) time_t rep_timegm(struct tm *tm) { - static const unsigned ndays[2][12] ={ + const unsigned ndays[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}}; time_t res = 0; -- cgit From 0500b87092540d300b4e021a0fb95ce16a44fbd2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Dec 2007 00:02:15 +0100 Subject: r26540: Revert my previous commit after concerns raised by Andrew. (This used to be commit 6ac86f8be7d9a8c5ab396a93e6d1e6819e11f173) --- source4/lib/replace/timegm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/replace/timegm.c') diff --git a/source4/lib/replace/timegm.c b/source4/lib/replace/timegm.c index 86f360bd3c..395c684e11 100644 --- a/source4/lib/replace/timegm.c +++ b/source4/lib/replace/timegm.c @@ -46,7 +46,7 @@ static int is_leap(unsigned y) time_t rep_timegm(struct tm *tm) { - const unsigned ndays[2][12] ={ + static const unsigned ndays[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}}; time_t res = 0; -- cgit