opendir() failes with trailing \

Cameron Gregory <[email protected]>
Newsgroups gmane.comp.video.gimp.windows.devel
Message-ID <[email protected]>
G'Day,
	I tracked down the plugins
not loading to opendir() failing.

#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>

int main(int a, char **b)
{
  DIR   *dir;
  dir = opendir("/target");
  if (dir == NULL)
        printf("null");
  else
        printf("ok");

}

the above works .. as does:
  dir = opendir("c:\\target");
but this fails
  dir= opendir("c:\\target\\");


So, then opendir files on "plugins" and all the other dirs...
My only guess is the current version uses a different opendir()??
tor: any insight there?

anyway, here is a patched datafiles_read_directories()...

thanks,

Cameron

void
datafiles_read_directories (gchar                  *path_str,
			    GimpDataFileLoaderFunc  loader_func,
			    GimpDataFileFlags       flags)
{
  gchar *local_path;
  GList *path;
  GList *list;
  gchar *filename;
  gint   err;
  DIR   *dir;
  struct dirent *dir_ent;

  if (path_str == NULL)
    return;

  local_path = g_strdup (path_str);

#ifdef __EMX__
  /*
   *  Change drive so opendir works.
   */
  if (local_path[1] == ':')
    {
      _chdrive (local_path[0]);
    }
#endif  

  path = gimp_path_parse (local_path, 16, TRUE, NULL);

  for (list = path; list; list = g_list_next (list))
    {
	if (list->data != NULL && ((gchar *)list->data)[strlen(list->data)-1]
== G_DIR_SEPARATOR) {
		char *x = strdup(list->data);
		if (x != NULL) {
			x[strlen(x)-1]='\0';
      			dir = opendir (x);
			free(x);
		}
		else
			dir = NULL;
		
	}
	else {
      		/* Open directory */
      		dir = opendir ((gchar *) list->data);
	} 

      if (!dir)
	{
	  g_message ("error reading datafiles directory \"%s\"",
		     (gchar *) list->data);
	}
      else
	{
	  while ((dir_ent = readdir (dir)))
	    {
	      filename = g_strdup_printf ("%s%s",
					  (gchar *) list->data,
					  dir_ent->d_name);

	      /* Check the file and see that it is not a sub-directory */
	      err = stat (filename, &filestat);

	      if (!err && S_ISREG (filestat.st_mode) &&
		  (!(flags & MODE_EXECUTABLE) ||
		   (filestat.st_mode & S_IXUSR) ||
		   is_script (filename)))
		{
		  filestat_valid = TRUE;
		  (*loader_func) (filename);
		  filestat_valid = FALSE;
		}

	      g_free (filename);
	    }

	  closedir (dir);
	}
    }

  gimp_path_free (path);
  g_free (local_path);
}

-- 
Please include previous messages in reply so I can follow the thread.

---------------------------------------------------------------------
Cameron Gregory
http://www.flamingtext.com/
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.