summaryrefslogtreecommitdiff
path: root/source4/lib/replace/replace.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2006-08-26 17:19:58 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:16:47 -0500
commit6e9097045fcea332d91791d9820d7ad8e086f6d4 (patch)
treed78de7e4e3663e2436a32e2778c310a28bb7e214 /source4/lib/replace/replace.c
parenta0d6264b9012372cd2e898003fb4b7db86ea016e (diff)
downloadsamba-6e9097045fcea332d91791d9820d7ad8e086f6d4.tar.gz
samba-6e9097045fcea332d91791d9820d7ad8e086f6d4.tar.bz2
samba-6e9097045fcea332d91791d9820d7ad8e086f6d4.zip
r17842: After talking to Simo, apply the next attempt to resolve the strnlen
problem. Timegm is the same. Simo says this is just a workaround, but it helps for now. Feel free to revert. Volker (This used to be commit fd166ca0c079d83081bc1d631fe40b965c7873d4)
Diffstat (limited to 'source4/lib/replace/replace.c')
-rw-r--r--source4/lib/replace/replace.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/source4/lib/replace/replace.c b/source4/lib/replace/replace.c
index b8f4bc1c3c..f8bd62109d 100644
--- a/source4/lib/replace/replace.c
+++ b/source4/lib/replace/replace.c
@@ -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