From 545a9474c2f822f13b25204af0bc0b3d556f1c47 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 10 Apr 2011 20:46:25 +0000 Subject: applying patko's patch #3283782 to fix for Win32 svn path=/trunk/externals/unauthorized/; revision=15068 --- playlist/playlist.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/playlist/playlist.c b/playlist/playlist.c index fce68a8..4576267 100644 --- a/playlist/playlist.c +++ b/playlist/playlist.c @@ -37,17 +37,60 @@ #include #include #include +#include #include "m_pd.h" #include "m_imp.h" #include "g_canvas.h" - +#include #ifdef _WIN32 #include +#include +#include + +int scandir(const char *dir, struct dirent ***namelist, + int (*select)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)) { + DIR *d; + struct dirent *entry; + register int i=0; + size_t entrysize; + + if ((d=opendir(dir)) == NULL) + return(-1); + + *namelist=NULL; + while ((entry=readdir(d)) != NULL) + { + if (select == NULL || (select != NULL && (*select)(entry))) + { + *namelist=(struct dirent **)realloc((void *)(*namelist), + (size_t)((i+1)*sizeof(struct dirent *))); + if (*namelist == NULL) return(-1); + entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1; + (*namelist)[i]=(struct dirent *)malloc(entrysize); + if ((*namelist)[i] == NULL) return(-1); + memcpy((*namelist)[i], entry, entrysize); + i++; + } + } + if (closedir(d)) return(-1); + if (i == 0) return(-1); + if (compar != NULL) + qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar); + + return(i); +} + +int alphasort(const struct dirent **a, const struct dirent **b) { + return(strcmp((*a)->d_name, (*b)->d_name)); + } + +int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); +int alphasort(const struct dirent **, const struct dirent **); + #else #include -#include -#include #endif t_widgetbehavior playlist_widgetbehavior; @@ -844,7 +887,19 @@ static t_playlist *playlist_new(t_symbol *s, int argc, t_atom *argv ) // get current directory full path x->x_curdir = ( char * ) getbytes( MAX_DIR_LENGTH ); - if ( ( tmpcurdir = getenv( "PWD" ) ) == NULL ) + +#ifdef _WIN32 + char path[_MAX_DIR]; + + _getcwd (path, _MAX_DIR); + post ("Current directory is: %s", path); + tmpcurdir = path; + +#else + tmpcurdir = getenv( "PWD" ); +#endif + + if ( tmpcurdir == NULL ) { post( "playlist : could not get current directory ( where the hell are you ??? )" ); return NULL; -- cgit v1.2.1