diff -Naur grep/ChangeLog grep_build/ChangeLog
--- grep/ChangeLog	2005-03-09 14:11:28.000000000 +0100
+++ grep_build/ChangeLog	2005-03-20 11:30:50.000000000 +0100
@@ -1,3 +1,11 @@
+2005-03-16  Claudio Fontana  <sick_soul@users.sourceforge.net>
+
+	* src/savedir_exclude.c (new file): new savedir_exclude() function
+	* src/savedir_exclude.h (new_file): likewise
+	* src/grep.c: use custom savedir_exclude() instead of savedir,
+	  to fix mismatch between proto and functionality between versions.
+	* src/Makefile.am: added new files
+
 2005-03-09  Stepan Kasal  <kasal@ucw.cz>
 
 	* src/search.c (EGexecute, Fexecute): Use xmalloc, not malloc.
diff -Naur grep/src/Makefile.am grep_build/src/Makefile.am
--- grep/src/Makefile.am	2004-11-23 13:49:36.000000000 +0100
+++ grep_build/src/Makefile.am	2005-03-20 11:30:50.000000000 +0100
@@ -7,8 +7,9 @@
 bin_SCRIPTS = egrep fgrep
 CLEANFILES = egrep fgrep
 grep_SOURCES = grep.c dfa.c kwset.c search.c \
-               grepmat.c
-noinst_HEADERS = grep.h dfa.h kwset.h getpagesize.h system.h mbsupport.h
+               grepmat.c savedir_exclude.c
+noinst_HEADERS = grep.h dfa.h kwset.h getpagesize.h system.h mbsupport.h \
+                 savedir_exclude.h
 
 LDADD = @INTLLIBS@ ../lib/libgreputils.a
 datadir = $(prefix)/@DATADIRNAME@
diff -Naur grep/src/grep.c grep_build/src/grep.c
--- grep/src/grep.c	2005-02-26 16:20:00.000000000 +0100
+++ grep_build/src/grep.c	2005-03-20 11:30:50.000000000 +0100
@@ -41,7 +41,7 @@
 #include "getopt.h"
 #include "getpagesize.h"
 #include "grep.h"
-#include "savedir.h"
+#include "savedir_exclude.h"
 #include "xstrtol.h"
 #include "xalloc.h"
 #include "error.h"
@@ -1040,8 +1040,7 @@
 	  return 1;
 	}
 
-  name_space = savedir (dir, stats->stat.st_size, included_patterns,
-			excluded_patterns);
+  name_space = savedir_exclude (dir, included_patterns, excluded_patterns);
 
   if (! name_space)
     {
@@ -1788,8 +1787,7 @@
 	do
 	{
 	  char *file = argv[optind];
-	  if ((included_patterns || excluded_patterns)
-	      && !isdir (file))
+	  if (included_patterns || excluded_patterns)
 	    {
 	      if (included_patterns &&
 		  ! excluded_filename (included_patterns, file, 0))
diff -Naur grep/src/savedir_exclude.c grep_build/src/savedir_exclude.c
--- grep/src/savedir_exclude.c	1970-01-01 01:00:00.000000000 +0100
+++ grep_build/src/savedir_exclude.c	2005-03-20 11:31:31.000000000 +0100
@@ -0,0 +1,143 @@
+/* savedir_exclude.c -- save the list of files in a directory in a string,
+                        eventually excluding certain filenames.
+
+   This is a slightly modified version of savedir.c, adapted for grep.
+
+   Copyright 2005 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 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* savedir.c written by David MacKenzie <djm@gnu.ai.mit.edu>,
+   Copyright 1990, 1997, 1998, 1999, 2000, 2001, 2003, 2004 Free
+   Software Foundation, Inc. */
+
+/* savedir_exclude.c adaptation for grep by 
+   Claudio Fontana <sick_soul@users.sourceforge.net>               */
+
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+
+#include <errno.h>
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+#else
+# define dirent direct
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
+
+#ifdef CLOSEDIR_VOID
+/* Fake a return value. */
+# define CLOSEDIR(d) (closedir (d), 0)
+#else
+# define CLOSEDIR(d) closedir (d)
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "xalloc.h"
+#include "savedir_exclude.h"
+
+/* Return a freshly allocated string containing the filenames
+   in directory DIR, separated by '\0' characters;
+   the end is marked by two '\0' characters in a row.
+   Return NULL (setting errno) if DIR cannot be opened, read, or closed.  */
+
+#ifndef NAME_SIZE_DEFAULT
+# define NAME_SIZE_DEFAULT 512
+#endif
+
+char *
+savedir_exclude (const char *dir, struct exclude *i, struct exclude* e)
+{
+  DIR *dirp;
+  struct dirent *dp;
+  char *name_space;
+  size_t allocated = NAME_SIZE_DEFAULT;
+  size_t used = 0;
+  int save_errno;
+  
+  dirp = opendir (dir);
+  if (dirp == NULL)
+    return NULL;
+
+  name_space = xmalloc (allocated);
+
+  errno = 0;
+  while ((dp = readdir (dirp)) != NULL)
+    {
+      /* Skip "", ".", and "..".  "" is returned by at least one buggy
+         implementation: Solaris 2.4 readdir on NFS file systems.  */
+      char const *entry = dp->d_name;
+      if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
+	{
+	  size_t entry_size = strlen (entry) + 1;
+
+	  /* exclude patterns */
+
+	  if (i || e)
+	    {
+	      if (i && !excluded_filename (i, entry, 0))
+		continue;
+	      if (e && excluded_filename (e, entry, 0))
+		continue;
+	    }
+
+	  if (used + entry_size < used)
+	    xalloc_die ();
+	  if (allocated <= used + entry_size)
+	    {
+	      do
+		{
+		  if (2 * allocated < allocated)
+		    xalloc_die ();
+		  allocated *= 2;
+		}
+	      while (allocated <= used + entry_size);
+
+	      name_space = xrealloc (name_space, allocated);
+	    }
+	  memcpy (name_space + used, entry, entry_size);
+	  used += entry_size;
+	}
+    }
+  name_space[used] = '\0';
+  save_errno = errno;
+  if (CLOSEDIR (dirp) != 0)
+    save_errno = errno;
+  if (save_errno != 0)
+    {
+      free (name_space);
+      errno = save_errno;
+      return NULL;
+    }
+  return name_space;
+}
+
+
diff -Naur grep/src/savedir_exclude.h grep_build/src/savedir_exclude.h
--- grep/src/savedir_exclude.h	1970-01-01 01:00:00.000000000 +0100
+++ grep_build/src/savedir_exclude.h	2005-03-20 11:30:50.000000000 +0100
@@ -0,0 +1,35 @@
+/* savedir_exclude.h -- save the list of files in a directory in a string,
+                        eventually excluding certain filenames.
+
+   This is a slightly modified version of savedir.h, adapted for grep.
+
+   Copyright 2005 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 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* savedir.h written by David MacKenzie <djm@gnu.ai.mit.edu>,
+   Copyright 1997, 1999, 2001, 2003 Free Software Foundation, Inc. */
+
+/* savedir_exclude.h adaptation for grep by 
+   Claudio Fontana <sick_soul@users.sourceforge.net>               */
+
+#if !defined SAVEDIR_EXCLUDE_H_
+# define SAVEDIR_EXCLUDE_H_
+
+#include "exclude.h"
+
+char *savedir_exclude (const char *dir, struct exclude *i, struct exclude* e);
+
+#endif
