diff options
author | Marc Laukien <marc@zeroc.com> | 2003-02-28 18:36:23 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2003-02-28 18:36:23 +0000 |
commit | ad3b72f47b9c3acf4e3a4edd87230b5be4dccd5c (patch) | |
tree | b37f17f20793ab35d2df9afc333615c859a59787 /cpp | |
parent | minor (diff) | |
download | ice-ad3b72f47b9c3acf4e3a4edd87230b5be4dccd5c.tar.bz2 ice-ad3b72f47b9c3acf4e3a4edd87230b5be4dccd5c.tar.xz ice-ad3b72f47b9c3acf4e3a4edd87230b5be4dccd5c.zip |
scandir
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/CHANGES | 7 | ||||
-rw-r--r-- | cpp/src/IcePatch/Util.cpp | 70 |
2 files changed, 75 insertions, 2 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 925d139d1ba..9f303a66b7b 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -4,8 +4,11 @@ Changes since version 1.0.1 - Compatibility fixes for GCC 2.96. - Added `option' and `vm-option' elements to IcePack server - descriptors. These elements are used to pass command line options - to server processes. + descriptors. These elements are used to pass command line options to + server processes. + +- Added scandir() and alphasort() for Sun-OS and other Unix systems + that do not have these BSD calls. Changes since version 1.0.0 --------------------------- diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp index 60f7a9536c8..691fb7c1ad4 100644 --- a/cpp/src/IcePatch/Util.cpp +++ b/cpp/src/IcePatch/Util.cpp @@ -41,6 +41,76 @@ # undef max #endif +// +// Sun-OS doesn't have scandir() or alphasort(). +// +#ifdef SUNOS + +static int +scandir(const char* dir, struct dirent*** namelist, + int (*select)(const struct dirent*), + int (*compar)(const void*, const void*)) +{ + DIR* d; + struct dirent* entry; + register int i = 0; + size_t entrysize; + + if((d=opendir(dir)) == 0) + { + return -1; + } + + *namelist = 0; + while((entry=readdir(d)) != 0) + { + if(select == 0 || (select != 0 && (*select)(entry))) + { + *namelist = (struct dirent**)realloc((void*)(*namelist), (size_t)((i + 1) * sizeof(struct dirent*))); + if(*namelist == 0) + { + return -1; + } + + entrysize = sizeof(struct dirent) - sizeof(entry->d_name) + strlen(entry->d_name) + 1; + (*namelist)[i] = (struct dirent*)malloc(entrysize); + if((*namelist)[i] == 0) + { + return -1; + } + memcpy((*namelist)[i], entry, entrysize); + ++i; + } + } + + if(closedir(d)) + { + return -1; + } + + if(i == 0) + { + return -1; + } + + if(compar != 0) + { + qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar); + } + + return i; +} + +static int +alphasort(const void* v1, const void* v2) +{ + const struct dirent **a = (const struct dirent **)v1; + const struct dirent **b = (const struct dirent **)v2; + return(strcmp((*a)->d_name, (*b)->d_name)); +} + +#endif + using namespace std; using namespace Ice; using namespace IcePatch; |