diff options
author | Bryan Jurish <mukau@users.sourceforge.net> | 2009-05-14 19:30:51 +0000 |
---|---|---|
committer | Bryan Jurish <mukau@users.sourceforge.net> | 2009-05-14 19:30:51 +0000 |
commit | ba2c80c91cfd8390ced743f8ee899612acb72b24 (patch) | |
tree | 17ae05bcbfc0d70fb892609631537ff79920f931 /readdir/src/readdir.c | |
parent | 67b63ce6c08bffaea091063e8f106a81eb456bc6 (diff) |
+ win32 fixes: check for dirent.d_type and DT_* decls
+ minor improvements: report errors with pd_error() instead of error()
+ todo (maybe): use stat() to get file types when dirent.d_type is unavailable?
- mabe better delegate this to a different external entirely (e.g. 'stat')
svn path=/trunk/externals/moocow/; revision=11365
Diffstat (limited to 'readdir/src/readdir.c')
-rw-r--r-- | readdir/src/readdir.c | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/readdir/src/readdir.c b/readdir/src/readdir.c index a2bdbb8..0dbd73d 100644 --- a/readdir/src/readdir.c +++ b/readdir/src/readdir.c @@ -93,7 +93,7 @@ static void readdir_close(t_readdir *x) { if (!x->x_dir) return; if (0 != closedir(x->x_dir)) { - error("readdir: cannot close %s: %s", x->x_dirname->s_name, strerror(errno)); + pd_error(x, "readdir: cannot close %s: %s", x->x_dirname->s_name, strerror(errno)); return; } x->x_dir = NULL; @@ -111,7 +111,7 @@ static void readdir_open(t_readdir *x, t_symbol *dirname) if (x->x_dir) readdir_close(x); if ( !(x->x_dir = opendir(dirname->s_name)) ) { - error("readdir: cannot open %s: %s", dirname->s_name, strerror(errno)); + pd_error(x, "readdir: cannot open %s: %s", dirname->s_name, strerror(errno)); return; } x->x_dirname = dirname; @@ -127,7 +127,7 @@ static void readdir_next(t_readdir *x) if ( !x->x_dir || !(result = readdir(x->x_dir)) ) { if (errno == EBADF) { //-- real error - error("readdir: cannot read from %s: %s", x->x_dirname->s_name, strerror(errno)); + pd_error(x, "readdir: cannot read from %s: %s", x->x_dirname->s_name, strerror(errno)); } else { //-- end of directory @@ -136,37 +136,44 @@ static void readdir_next(t_readdir *x) return; } - //-- get type +#if HAVE_STRUCT_DIRENT_D_TYPE + //-- get type (if this OS supports it, e.g. if we're not on windoof) switch (result->d_type) { - case DT_REG: - sel = sp_file; - break; +#if HAVE_DECL_DT_REG + case DT_REG: sel = sp_file; break; +#endif - case DT_DIR: - sel = sp_dir; - break; +#if HAVE_DECL_DT_DIR + case DT_DIR: sel = sp_dir; break; +#endif - case DT_FIFO: - sel = sp_fifo; - break; +#if HAVE_DECL_DT_FIFO + case DT_FIFO: sel = sp_fifo; break; +#endif - case DT_SOCK: - sel = sp_sock; - break; +#if HAVE_DECL_DT_SOCK + case DT_SOCK: sel = sp_sock; break; +#endif - case DT_CHR: - sel = sp_chrdev; - break; +#if HAVE_DECL_DT_CHR + case DT_CHR: sel = sp_chrdev; break; +#endif - case DT_BLK: - sel = sp_blkdev; - break; +#if HAVE_DECL_DT_BLK + case DT_BLK: sel = sp_blkdev; break; +#endif +#if HAVE_DECL_DT_UNKNOWN + case DT_UNKNOWN: +#endif default: sel = sp_unknown; break; } +#else /* if !HAVE_STRUCT_DIRENT_D_TYPE */ + sel = sp_unknown; +#endif /* HAVE_STRUCT_DIRENT_D_TYPE */ x->x_eatom.a_w.w_symbol = gensym(result->d_name); outlet_anything(x->x_ent_outlet, sel, 1, &x->x_eatom); @@ -199,7 +206,7 @@ static void readdir_tell(t_readdir *x) static void readdir_seek(t_readdir *x, t_floatarg pos) { if (!x->x_dir) { - error("readdir: seek %f: no directory opened!", pos); + pd_error(x, "readdir: seek %g: no directory opened!", pos); return; } seekdir(x->x_dir, (off_t)pos); |