r17842: After talking to Simo, apply the next attempt to resolve the strnlen
authorVolker Lendecke <vlendec@samba.org>
Sat, 26 Aug 2006 17:19:58 +0000 (17:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:16:47 +0000 (14:16 -0500)
problem. Timegm is the same. Simo says this is just a workaround, but it helps
for now. Feel free to revert.

Volker

source/lib/ldb/replace/replace.c
source/lib/ldb/replace/timegm.c
source/lib/replace/config.m4
source/lib/replace/replace.c

index faa5771a76c51d7490412ebadd6ffee62643c8a1..a63613fc1057b303c2f97936f2746af69057739d 100644 (file)
@@ -23,7 +23,7 @@
 #include "includes.h"
 #include "ldb/include/includes.h"
 
-#ifndef HAVE_STRNLEN
+#if !defined(HAVE_STRNLEN) && !defined(_SAMBA_BUILD_)
 /**
  Some platforms don't have strnlen
 **/
index 5fb15475f3ffc12ca3b399ba335b7de26e69a711..10631befd97af5f3d49b83e9511af94e56f61718 100644 (file)
@@ -38,7 +38,7 @@
 #include "includes.h"
 #include "ldb/include/includes.h"
 
-#ifndef HAVE_TIMEGM
+#if !defined(HAVE_TIMEGM) && !defined(_SAMBA_BUILD_)
 
 static int is_leap(unsigned y)
 {
index 93f0bb34a776d8f6ba284366147bc674319613c8..adaba74568f43c950f5ccff7b6c68aa176a68f8f 100644 (file)
@@ -50,7 +50,7 @@ AC_CHECK_HEADERS(sys/syslog.h syslog.h)
 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
-AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
+AC_CHECK_FUNCS(pread pwrite strndup strnlen strcasestr strtok_r mkdtemp)
 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
 AC_HAVE_DECL(errno, [#include <errno.h>])
index b8f4bc1c3c9eb15b516750db4e8e8a8767d4ad22..f8bd62109d8a800c48cde15f91d2c22b83b9a702 100644 (file)
@@ -387,6 +387,20 @@ duplicate a string
 }
 #endif
 
+#ifndef HAVE_STRNLEN
+/**
+ Some platforms don't have strnlen
+**/
+
+ size_t strnlen(const char *s, size_t n)
+{
+       size_t i;
+       for (i=0; i<n && s[i] != '\0'; i++)
+               /* noop */ ;
+       return i;
+}
+#endif
+
 #ifndef HAVE_WAITPID
 int waitpid(pid_t pid,int *status,int options)
 {
@@ -519,3 +533,35 @@ char *strtok_r(char *s, const char *delim, char **save_ptr)
        return token;
 }
 #endif
+
+#if !defined(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