From: <enl...@li...> - 2003-01-19 13:17:58
|
Enlightenment CVS committal Author : technikolor Project : e17 Module : libs/ewl Dir : e17/libs/ewl/src Modified Files: ewl_fileselector.c Log Message: Code added and config changes for Solaris. Scandir function added to ewl_fileselector.c, these functions were written by Joerg-R. Hill for Viewmol. I have recieved his blessings to use this code. configure.ac and acconfig.h changes setup the defs for HAVE_SUN to inject the new code. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_fileselector.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- ewl_fileselector.c 25 May 2002 05:46:40 -0000 1.4 +++ ewl_fileselector.c 19 Jan 2003 13:17:57 -0000 1.5 @@ -1,6 +1,10 @@ - #include <Ewl.h> +#ifdef HAVE_CONFIG_H +#include "ewl-config.h" +#endif + + void __ewl_fileselector_realize(Ewl_Widget * w, void *ev_data, void *user_data); @@ -9,6 +13,60 @@ void __directory_clicked(Ewl_Widget * w, void *ev_data, void *user_data); void __process_directory(Ewl_Fileselector * fs, char *dir); + + +/** Addition for Solaris compatablity in scandir dep. -benr **/ +/** Code written originally by Joerg-R. Hill for Viewmol used with permission and covered by GPL **/ +#ifdef HAVE_SUN + +#include<dirent.h> +#include<stdlib.h> +#include<string.h> +#include<sys/types.h> + +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)); +} + +#endif +/* *************************************** */ + /** * ewl_fileselector_new - create a new fileselector |