diff --git a/qse/include/qse/fs/dir.h b/qse/include/qse/fs/dir.h index eb0760cc..c78f134b 100644 --- a/qse/include/qse/fs/dir.h +++ b/qse/include/qse/fs/dir.h @@ -43,8 +43,8 @@ struct qse_dir_ent_t enum { QSE_DIR_ENT_UNKNOWN, - QSE_DIR_ENT_DIRECTORY, - QSE_DIR_ENT_REGULAR, + QSE_DIR_ENT_DIR, + QSE_DIR_ENT_REG, QSE_DIR_ENT_FIFO, QSE_DIR_ENT_CHAR, QSE_DIR_ENT_BLOCK, diff --git a/qse/lib/cmn/syscall.h b/qse/lib/cmn/syscall.h index e16eb7dc..76d91626 100644 --- a/qse/lib/cmn/syscall.h +++ b/qse/lib/cmn/syscall.h @@ -88,7 +88,7 @@ # define QSE_LLSEEK(handle,hoffset,loffset,out,whence) _llseek(handle,hoffset,loffset,out,whence) #endif -#if defined(SYS_lseek65) +#if defined(SYS_lseek64) # define QSE_LSEEK64(handle,offset,whence) syscall(SYS_lseek64,handle,offset,whence) #elif defined(HAVE_lseek64) # define QSE_LSEEK64(handle,offset,whence) lseek64(handle,offset,whence) @@ -100,6 +100,18 @@ # define QSE_LSEEK(handle,offset,whence) lseek(handle,offset,whence) #endif +#if defined(SYS_lstat64) +# define QSE_LSTAT64(path,stbuf) syscall(SYS_lstat64,path,stbuf) +#elif defined(HAVE_lstat64) +# define QSE_LSTAT64(path,stbuf) lstat64(path,stbuf) +#endif + +#if defined(SYS_lstat) +# define QSE_LSTAT(path,stbuf) syscall(SYS_lstat,path,stbuf) +#else +# define QSE_LSTAT(path,stbuf) lstat(path,stbuf) +#endif + #if !defined(_LP64) && defined(SYS_ftruncate64) # define QSE_FTRUNCATE(handle,size) syscall(SYS_ftruncate64,handle,size) #elif defined(SYS_ftruncate) diff --git a/qse/lib/fs/dir.c b/qse/lib/fs/dir.c index 4915d4c7..81021b57 100644 --- a/qse/lib/fs/dir.c +++ b/qse/lib/fs/dir.c @@ -30,8 +30,7 @@ #elif defined(__DOS__) # error NOT IMPLEMENTED #else -# include -# include +# include "../cmn/syscall.h" # include # include #endif @@ -487,7 +486,7 @@ qse_dir_ent_t* qse_dir_read (qse_dir_t* dir) info_t* info; struct dirent* ent; int x; -#if defined(HAVE_LSTAT64) +#if defined(QSE_LSTAT64) struct stat64 st; #else struct stat st; @@ -526,11 +525,11 @@ qse_dir_ent_t* qse_dir_read (qse_dir_t* dir) return QSE_NULL; } - #if defined(HAVE_LSTAT64) - x = lstat64 (mfname, &st); - #else - x = lstat (mfname, &st); - #endif +#if defined(QSE_LSTAT64) + x = QSE_LSTAT64 (mfname, &st); +#else + x = QSE_LSTAT (mfname, &st); +#endif QSE_MMGR_FREE (dir->mmgr, mfname); @@ -542,16 +541,15 @@ qse_dir_ent_t* qse_dir_read (qse_dir_t* dir) if (set_entry_name (dir, ent->d_name) <= -1) return QSE_NULL; - if (S_ISDIR(st.st_mode)) - { - dir->ent.size = 0; - dir->ent.type = QSE_DIR_ENT_DIRECTORY; - } - else - { - dir->ent.size = st.st_size; - dir->ent.type = QSE_DIR_ENT_UNKNOWN; - } + + dir->ent.size = st.st_size; + +#define IS_TYPE(st,type) ((st.st_mode & S_IFMT) == S_IFDIR) + dir->ent.type = IS_TYPE(st,S_IFDIR)? QSE_DIR_ENT_DIR: + IS_TYPE(st,S_IFCHR)? QSE_DIR_ENT_CHAR: + IS_TYPE(st,S_IFBLK)? QSE_DIR_ENT_BLOCK: + QSE_DIR_ENT_UNKNOWN; + #endif diff --git a/qse/samples/fs/dir01.c b/qse/samples/fs/dir01.c index 62d2cb5d..e479596a 100644 --- a/qse/samples/fs/dir01.c +++ b/qse/samples/fs/dir01.c @@ -39,7 +39,6 @@ static void list (qse_dir_t* dir, const qse_char_t* name) int dir_main (int argc, qse_char_t* argv[]) { - int n; qse_dir_t* dir; if (argc != 2) @@ -59,7 +58,7 @@ int dir_main (int argc, qse_char_t* argv[]) list (dir, QSE_T("..")); qse_dir_close (dir); - return n; + return 0; } int qse_main (int argc, qse_achar_t* argv[])