[maemo-commits] [maemo-commits] r18733 - in projects/haf/trunk/osso-gnome-vfs2: debian modules
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Jun 16 09:44:55 EEST 2009
- Previous message: [maemo-commits] r18732 - projects/haf/trunk/hildon-thumbnail
- Next message: [maemo-commits] r18734 - in projects/haf/trunk/gtk+: . gtk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: richard Date: 2009-06-16 09:44:44 +0300 (Tue, 16 Jun 2009) New Revision: 18733 Modified: projects/haf/trunk/osso-gnome-vfs2/debian/changelog projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.c projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.h projects/haf/trunk/osso-gnome-vfs2/modules/osso_case_in.c Log: Use readdir_r Modified: projects/haf/trunk/osso-gnome-vfs2/debian/changelog =================================================================== --- projects/haf/trunk/osso-gnome-vfs2/debian/changelog 2009-06-15 16:34:31 UTC (rev 18732) +++ projects/haf/trunk/osso-gnome-vfs2/debian/changelog 2009-06-16 06:44:44 UTC (rev 18733) @@ -1,3 +1,9 @@ +osso-gnome-vfs2 (2.16.3-2osso4) unstable; urgency=low + + * Fixes: NB#122894, Readdir (g_dir_read_name) is used instead of readdir_r + + -- Richard Hult <richard at imendio.com> Fri, 19 Jun 2009 08:42:00 +0200 + osso-gnome-vfs2 (2.16.3-2osso3) unstable; urgency=low * Fixes: NB#106000, SIGSEGV in do_read_directory Modified: projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.c =================================================================== --- projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.c 2009-06-15 16:34:31 UTC (rev 18732) +++ projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.c 2009-06-16 06:44:44 UTC (rev 18733) @@ -19,6 +19,8 @@ */ #include <config.h> +#include <sys/types.h> +#include <dirent.h> #include <glib.h> #include <libgnomevfs/gnome-vfs.h> #include <string.h> @@ -36,15 +38,60 @@ G_LOCK_DEFINE_STATIC (cache); static GHashTable *fds = NULL; +#ifdef PATH_MAX +#define GET_PATH_MAX() PATH_MAX +#else +static int +GET_PATH_MAX (void) +{ + static unsigned int value; + + /* This code is copied from GNU make. It returns the maximum + path length by using `pathconf'. */ + + if (value == 0) { + long int x = pathconf(G_DIR_SEPARATOR_S, _PC_PATH_MAX); + + if (x > 0) + value = x; + else + return MAXPATHLEN; + } + + return value; +} +#endif + +struct dirent * +caseless_file_method_allocate_dirent (void) +{ + return g_malloc (sizeof (struct dirent) + GET_PATH_MAX() + 1); +} + +const char * +caseless_file_method_readdir_wrapper (DIR *dir, struct dirent *entry) +{ + struct dirent *result = NULL; + + if (readdir_r (dir, entry, &result) != 0) { + return NULL; + } + + if (result == NULL) { + return NULL; + } + + return entry->d_name; +} + static void get_pid_fds_foreach (const gchar *pid, GHashTable *fds) { - gchar *parent_dir; - GDir *dir; - const gchar *entry; - gchar *filename; - gchar *filename_from_link; + gchar *parent_dir; + DIR *dir; + struct dirent *entry; + const gchar *name; parent_dir = g_build_path (G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S, @@ -53,16 +100,19 @@ FD_DIR, NULL); - dir = g_dir_open (parent_dir, 0, NULL); + dir = opendir (parent_dir); if (!dir) { g_free (parent_dir); return; } - for (entry = g_dir_read_name (dir); - entry != NULL; - entry = g_dir_read_name (dir)) { - filename = g_build_filename (parent_dir, entry, NULL); + entry = caseless_file_method_allocate_dirent (); + + while ((name = caseless_file_method_readdir_wrapper (dir, entry)) != NULL) { + gchar *filename; + gchar *filename_from_link; + + filename = g_build_filename (parent_dir, name, NULL); filename_from_link = g_file_read_link (filename, NULL); g_free (filename); @@ -76,40 +126,43 @@ } } - g_dir_close (dir); + g_free (entry); + closedir (dir); g_free (parent_dir); } static GSList * get_pid_dirs (void) { - GSList *dirs = NULL; - GDir *dir; - const gchar *entry; - gchar *parent_dir; + gchar *parent_dir; + DIR *dir; + struct dirent *entry; + GSList *dirs = NULL; + const gchar *name; parent_dir = g_build_path (G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S, PROC_DIR, NULL); - dir = g_dir_open (parent_dir, 0, NULL); + dir = opendir (parent_dir); g_return_val_if_fail (dir != NULL, NULL); - for (entry = g_dir_read_name (dir); - entry != NULL; - entry = g_dir_read_name (dir)) { + entry = caseless_file_method_allocate_dirent (); + + while ((name = caseless_file_method_readdir_wrapper (dir, entry)) != NULL) { /* We just do a simple check for the first character * to see if it is a digit since it is unlikely we get a * directory with <number><string> combination, and even * if we do, the extra lookup will not be noticed. */ - if (g_ascii_isdigit (entry[0])) { - dirs = g_slist_append (dirs, g_strdup (entry)); + if (g_ascii_isdigit (name[0])) { + dirs = g_slist_append (dirs, g_strdup (name)); } } - g_dir_close (dir); + g_free (entry); + closedir (dir); g_free (parent_dir); return dirs; Modified: projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.h =================================================================== --- projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.h 2009-06-15 16:34:31 UTC (rev 18732) +++ projects/haf/trunk/osso-gnome-vfs2/modules/caseless-file-method-utils.h 2009-06-16 06:44:44 UTC (rev 18733) @@ -21,6 +21,9 @@ #ifndef __CASELESS_FILE_METHOD_UTILS_H__ #define __CASELESS_FILE_METHOD_UTILS_H__ +#include <libgnomevfs/gnome-vfs.h> +#include <dirent.h> + gboolean caseless_file_method_is_file_open (const gchar *filename); void caseless_file_method_clear_cache (void); GnomeVFSURI *caseless_file_method_create_unescaped_uri (const GnomeVFSURI *uri); @@ -28,5 +31,10 @@ gconstpointer b); guint caseless_file_method_uri_hash (gconstpointer p); + +struct dirent *caseless_file_method_allocate_dirent (void); +const char * caseless_file_method_readdir_wrapper (DIR *dir, + struct dirent *entry); + #endif /* __CASELESS_FILE_METHOD_UTILS_H__ */ Modified: projects/haf/trunk/osso-gnome-vfs2/modules/osso_case_in.c =================================================================== --- projects/haf/trunk/osso-gnome-vfs2/modules/osso_case_in.c 2009-06-15 16:34:31 UTC (rev 18732) +++ projects/haf/trunk/osso-gnome-vfs2/modules/osso_case_in.c 2009-06-16 06:44:44 UTC (rev 18733) @@ -18,13 +18,16 @@ * Boston, MA 02111-1307, USA. */ -#include "stdio.h" -#include "string.h" - +#include <config.h> +#include <sys/types.h> +#include <dirent.h> +#include <string.h> #include <glib.h> #include "osso_case_in.h" +#include "caseless-file-method-utils.h" + #define d(x) static gchar * get_file_system_real_part (const gchar *file, @@ -41,25 +44,23 @@ static gchar * get_file_system_real_part (const gchar *file, const gchar *directory) { - GDir *dir; - GError *error; - const gchar *r_file; - gchar *file_case; - gchar *ret_val; + DIR *dir; + struct dirent *entry; + const gchar *r_file; + gchar *file_case; + gchar *ret_val; - error = NULL; - - dir = g_dir_open (directory, 0, &error); + dir = opendir (directory); if (!dir) { - d(g_print ("%s\n", error->message)); - g_error_free (error); return NULL; } file_case = g_utf8_casefold (file, -1); ret_val = NULL; - while ((r_file = g_dir_read_name (dir)) != NULL) { + entry = caseless_file_method_allocate_dirent (); + + while ((r_file = caseless_file_method_readdir_wrapper (dir, entry)) != NULL) { gchar *r_file_utf8; gchar *r_file_case; @@ -84,7 +85,8 @@ } g_free (file_case); - g_dir_close (dir); + g_free (entry); + closedir (dir); return ret_val; }
- Previous message: [maemo-commits] r18732 - projects/haf/trunk/hildon-thumbnail
- Next message: [maemo-commits] r18734 - in projects/haf/trunk/gtk+: . gtk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]