From a0b6661eb6980095f24d6317a31404596d70ba8c Mon Sep 17 00:00:00 2001 From: James Bursa Date: Mon, 29 Jan 2007 22:27:15 +0000 Subject: Make GTK build compile on FreeBSD. svn path=/trunk/netsurf/; revision=3154 --- utils/filename.c | 4 ++-- utils/talloc.h | 2 ++ utils/utils.c | 29 ++++++++++++++++++++++++++++- utils/utils.h | 6 +++++- 4 files changed, 37 insertions(+), 4 deletions(-) (limited to 'utils') diff --git a/utils/filename.c b/utils/filename.c index 194d11c74..84b286dfc 100644 --- a/utils/filename.c +++ b/utils/filename.c @@ -216,8 +216,8 @@ bool filename_flush_directory(const char *folder, int depth) { parent = opendir(folder); while ((entry = readdir(parent))) { - if ((entry->d_ino == 0) || (!strcmp(entry->d_name, ".")) || - (!strcmp(entry->d_name, ".."))) + if (!strcmp(entry->d_name, ".") || + !strcmp(entry->d_name, "..")) continue; /* first 3 depths are directories only, then files only */ diff --git a/utils/talloc.h b/utils/talloc.h index 8b448f63c..b0321384e 100644 --- a/utils/talloc.h +++ b/utils/talloc.h @@ -21,6 +21,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include + /* this is only needed for compatibility with the old talloc */ typedef void TALLOC_CTX; diff --git a/utils/utils.c b/utils/utils.c index 63b8e9b29..05f0059ec 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf-browser.org/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2004 James Bursa + * Copyright 2004-2007 James Bursa * Copyright 2003 Phil Mellor * Copyright 2003 John M Bell * Copyright 2004 John Tytgat @@ -235,3 +235,30 @@ char *strcasestr(const char *haystack, const char *needle) return NULL; } + + +#ifdef __FreeBSD__ + +/** + * Duplicate up to n characters of a string. + */ + +char *strndup(const char *s, size_t n) +{ + size_t len; + char *s2; + + for (len = 0; len != n && s[len]; len++) + continue; + + s2 = malloc(len + 1); + if (!s2) + return 0; + + memcpy(s2, s, len); + s2[len] = 0; + return s2; +} + +#endif + diff --git a/utils/utils.h b/utils/utils.h index 3e5ed6318..cfc7d8edc 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf-browser.org/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2004 James Bursa + * Copyright 2004-2007 James Bursa * Copyright 2004 John Tytgat */ @@ -56,6 +56,10 @@ void unicode_transliterate(unsigned int c, char **r); char *human_friendly_bytesize(unsigned long bytesize); const char *rfc1123_date(time_t t); char *strcasestr(const char *haystack, const char *needle); +#ifdef __FreeBSD__ +/* FreeBSD lacks strndup */ +char *strndup(const char *s, size_t n); +#endif /* Platform specific functions */ void die(const char * const error); -- cgit v1.2.3