From 9b8d6f45eb07dfb71b9c12c126b23c7378b4613a Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sat, 14 Mar 2009 18:02:34 +0000 Subject: [PATCH] Linux fastdir support. Fix problems without fastdir support (closes: 2671401) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3318 --- configure.in | 10 +++++++++ include/cross.h | 16 ++++++++------- src/misc/cross.cpp | 51 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/configure.in b/configure.in index 3cf4bc49..1d9f13a9 100644 --- a/configure.in +++ b/configure.in @@ -110,6 +110,16 @@ AC_MSG_CHECKING(if environ can be linked) AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern char ** environ;]],[[*environ;]])], [AC_MSG_RESULT(yes);AC_DEFINE(ENVIRON_LINKED,1,[environ can be linked])],AC_MSG_RESULT(no)) +AC_MSG_CHECKING([if dirent includes d_type]) +AC_COMPILE_IFELSE([ +#include +#include +void blah(){ +struct dirent d_test; +d_test.d_type = 0; +}],[AC_MSG_RESULT(yes);AC_DEFINE(DIRENT_HAS_D_TYPE,1,[struct dirent has d_type])],AC_MSG_RESULT(no)) + + dnl Check for powf if test x$target = xi386-pc-os2-emx ; then AC_MSG_CHECKING(for powf in libm); diff --git a/include/cross.h b/include/cross.h index 60473b8e..6a558e6f 100644 --- a/include/cross.h +++ b/include/cross.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: cross.h,v 1.20 2009-03-04 19:34:42 c2woody Exp $ */ +/* $Id: cross.h,v 1.21 2009-03-14 18:02:34 qbix79 Exp $ */ #ifndef DOSBOX_CROSS_H #define DOSBOX_CROSS_H @@ -79,22 +79,24 @@ public: #if defined (WIN32) -#if defined (WIN32) /* Win 32 */ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from #include -#endif typedef struct dir_struct { - HANDLE handle; - char base_path[MAX_PATH+4]; - WIN32_FIND_DATA search_data; + HANDLE handle; + char base_path[MAX_PATH+4]; + WIN32_FIND_DATA search_data; } dir_information; #else +//#include //Included above #include -typedef DIR dir_information; +typedef struct dir_struct { + DIR* dir; + char base_path[CROSS_LEN]; +} dir_information; #endif diff --git a/src/misc/cross.cpp b/src/misc/cross.cpp index d45e5b19..74ad66bc 100644 --- a/src/misc/cross.cpp +++ b/src/misc/cross.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: cross.cpp,v 1.4 2009-03-04 19:34:42 c2woody Exp $ */ +/* $Id: cross.cpp,v 1.5 2009-03-14 18:02:34 qbix79 Exp $ */ #include "dosbox.h" #include "cross.h" @@ -163,17 +163,15 @@ void close_directory(dir_information* dirp) { #else -#include "dirent.h" -//#include "stdio.h" - -typedef DIR dir_information; - dir_information* open_directory(const char* dirname) { - return opendir(dirname); + static dir_information dir; + dir.dir=opendir(dirname); + safe_strncpy(dir.base_path,dirname,CROSS_LEN); + return dir.dir?&dir:NULL; } bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory) { - struct dirent* dentry = readdir(dirp); + struct dirent* dentry = readdir(dirp->dir); if (dentry==NULL) { return false; } @@ -181,16 +179,30 @@ bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_dire // safe_strncpy(entry_name,dentry->d_name,(FILENAME_MAXd_name,CROSS_LEN); +#ifdef DIRENT_HAS_D_TYPE + if(dentry->d_type == DT_DIR) { + is_directory = true; + return true; + } else if(dentry->d_type == DT_REG) { + is_directory = false; + return true; + } +#endif + // probably use d_type here instead of a full stat() + static char buffer[2*CROSS_LEN] = { 0 }; + buffer[0] = 0; + strcpy(buffer,dirp->base_path); + strcat(buffer,entry_name); struct stat status; - if (stat(entry_name,&status)==0) is_directory = (S_ISDIR(status.st_mode)>0); + if (stat(buffer,&status)==0) is_directory = (S_ISDIR(status.st_mode)>0); else is_directory = false; return true; } bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory) { - struct dirent* dentry = readdir(dirp); + struct dirent* dentry = readdir(dirp->dir); if (dentry==NULL) { return false; } @@ -198,16 +210,31 @@ bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_direc // safe_strncpy(entry_name,dentry->d_name,(FILENAME_MAXd_name,CROSS_LEN); +#ifdef DIRENT_HAS_D_TYPE + if(dentry->d_type == DT_DIR) { + is_directory = true; + return true; + } else if(dentry->d_type == DT_REG) { + is_directory = false; + return true; + } +#endif + // probably use d_type here instead of a full stat() + static char buffer[2*CROSS_LEN] = { 0 }; + buffer[0] = 0; + strcpy(buffer,dirp->base_path); + strcat(buffer,entry_name); struct stat status; - if (stat(entry_name,&status)==0) is_directory = (S_ISDIR(status.st_mode)>0); + + if (stat(buffer,&status)==0) is_directory = (S_ISDIR(status.st_mode)>0); else is_directory = false; return true; } void close_directory(dir_information* dirp) { - closedir(dirp); + closedir(dirp->dir); } #endif