Skip to content
Snippets Groups Projects
Commit 08981f18 authored by Benedikt Meurer's avatar Benedikt Meurer
Browse files

2005-07-25 Benedikt Meurer <benny@xfce.org>

	* thunar-vfs/thunar-vfs-sysdep.{c,h}: Add _thunar_vfs_sysdep_readdir()
	  as a portable, thread-safe readdir replacement.
	* thunar-vfs/thunar-vfs-job-listdir.c(thunar_vfs_job_listdir_execute):
	  Use _thunar_vfs_sysdep_readdir().
	* thunar-vfs/Makefile.am: Add the sysdep component to the build
	  framework.




(Old svn revision: 16412)
parent 6ed41f15
No related branches found
No related tags found
No related merge requests found
2005-07-25 Benedikt Meurer <benny@xfce.org>
* thunar-vfs/thunar-vfs-sysdep.{c,h}: Add _thunar_vfs_sysdep_readdir()
as a portable, thread-safe readdir replacement.
* thunar-vfs/thunar-vfs-job-listdir.c(thunar_vfs_job_listdir_execute):
Use _thunar_vfs_sysdep_readdir().
* thunar-vfs/Makefile.am: Add the sysdep component to the build
framework.
2005-07-24 Benedikt Meurer <benny@xfce.org>
* thunar/thunar-desktop-view.c,
......
......@@ -40,6 +40,8 @@ libthunar_vfs_la_SOURCES = \
thunar-vfs-mime-parser.h \
thunar-vfs-mime-parser.c \
thunar-vfs-monitor.c \
thunar-vfs-sysdep.c \
thunar-vfs-sysdep.h \
thunar-vfs-trash.c \
thunar-vfs-user.c \
thunar-vfs-util.c \
......
......@@ -43,6 +43,7 @@
#endif
#include <thunar-vfs/thunar-vfs-job-listdir.h>
#include <thunar-vfs/thunar-vfs-sysdep.h>
......@@ -183,20 +184,13 @@ thunar_vfs_job_listdir_execute (ThunarVfsJob *job)
*/
for (;;)
{
if (G_UNLIKELY (readdir_r (dp, &d_buffer, &d) < 0))
{
error = g_error_new_literal (G_FILE_ERROR, g_file_error_from_errno (errno), g_strerror (errno));
break;
}
if (G_UNLIKELY (!_thunar_vfs_sysdep_readdir (dp, &d_buffer, &d, &error)))
break;
/* check for end of directory */
if (G_UNLIKELY (d == NULL))
break;
/* ignore "." and ".." entries */
if (G_UNLIKELY (d->d_name[0] == '.' && (d->d_name[1] == '\0' || (d->d_name[1] == '.' && d->d_name[2] == '\0'))))
continue;
names = g_slist_insert_sorted (names, g_string_chunk_insert (names_chunk, d->d_name), (GCompareFunc) strcmp);
}
......
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <thunar-vfs/thunar-vfs-sysdep.h>
/**
* _thunar_vfs_sysdep_readdir:
* @dirp : the %DIR pointer.
* @entry : the buffer to store the dir entry to.
* @result : result pointer.
* @error : return location for errors or %NULL.
*
* This function provides a thread-safe way to read the
* next directory entry from a %DIR pointer. The caller
* must provide a buffer where the result can be stored
* to (the @entry parameter). If the operation succeeds,
* %TRUE will be returned, and @result will be set to
* point to %NULL or @result, depending on whether the
* end of the directory was reached.
*
* This function will never return directory entries
* for '.' and '..', as they aren't used throughout
* Thunar.
*
* Return value: %FALSE if an error occurred, else %TRUE.
**/
gboolean
_thunar_vfs_sysdep_readdir (gpointer dirp,
struct dirent *entry,
struct dirent **result,
GError **error)
{
#ifndef HAVE_READDIR_R
G_LOCK_DEFINE_STATIC (readdir);
#endif
g_return_val_if_fail (dirp != NULL, FALSE);
g_return_val_if_fail (entry != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
for (;;)
{
#ifdef HAVE_READDIR_R
if (G_UNLIKELY (readdir_r (dirp, entry, result) < 0))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
g_strerror (errno));
return FALSE;
}
#else
G_LOCK (readdir);
*result = readdir (dirp);
if (G_LIKELY (*result != NULL))
*result = memcpy (entry, *result, sizeof (*entry));
G_UNLOCK (readdir);
#endif
/* ignore "." and ".." entries */
if (G_LIKELY (*result != NULL))
{
const gchar *name = entry->d_name;
if (G_UNLIKELY (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))))
continue;
}
/* we got our next entry */
break;
}
return TRUE;
}
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __THUNAR_VFS_SYSDEP_H__
#define __THUNAR_VFS_SYSDEP_H__
#include <glib.h>
G_BEGIN_DECLS;
gboolean _thunar_vfs_sysdep_readdir (gpointer dirp,
struct dirent *entry,
struct dirent **result,
GError **error);
G_END_DECLS;
#endif /* !__THUNAR_VFS_SYSDEP_H__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment