summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/ServerI.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-05-30 18:03:47 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-05-30 18:03:47 +0000
commit98157cb50455bac3a83780287f764ac9ffbaff3d (patch)
tree18df4c0087dddd996be220d8b392973b1e5edb6b /cpp/src/IceGrid/ServerI.cpp
parentNew login/logout icons (diff)
downloadice-98157cb50455bac3a83780287f764ac9ffbaff3d.tar.bz2
ice-98157cb50455bac3a83780287f764ac9ffbaff3d.tar.xz
ice-98157cb50455bac3a83780287f764ac9ffbaff3d.zip
Fixed SunOS compile issues
Diffstat (limited to 'cpp/src/IceGrid/ServerI.cpp')
-rw-r--r--cpp/src/IceGrid/ServerI.cpp47
1 files changed, 37 insertions, 10 deletions
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index 2544c99dad5..08b8015d2cd 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -24,14 +24,14 @@
#include <sys/stat.h>
#ifdef _WIN32
-# include <direct.h>
-# include <signal.h>
+# include <direct.h>
+# include <signal.h>
#else
-# include <sys/wait.h>
-# include <pwd.h> // for getpwnam
-# include <signal.h>
-# include <unistd.h>
-# include <dirent.h>
+# include <sys/wait.h>
+# include <pwd.h> // for getpwnam
+# include <signal.h>
+# include <unistd.h>
+# include <dirent.h>
#endif
#include <fstream>
@@ -46,9 +46,36 @@ namespace IceGrid
void
chownRecursive(const string& path, uid_t uid, gid_t gid)
{
- struct dirent **namelist;
- int n = scandir(path.c_str(), &namelist, 0, alphasort);
- if(n < 0)
+ struct dirent **namelist = 0;
+ DIR* d;
+ if((d = opendir(path.c_str())) == 0)
+ {
+ throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ }
+
+ struct dirent* entry;
+ int n = 0;
+ while((entry = readdir(d)) != 0)
+ {
+ namelist = (struct dirent**)realloc((void*)namelist, (size_t)((n + 1) * sizeof(struct dirent*)));
+ if(namelist == 0)
+ {
+ closedir(d);
+ throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ }
+
+ size_t entrysize = sizeof(struct dirent) - sizeof(entry->d_name) + strlen(entry->d_name) + 1;
+ namelist[n] = (struct dirent*)malloc(entrysize);
+ if(namelist[n] == 0)
+ {
+ closedir(d);
+ throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
+ }
+ memcpy(namelist[n], entry, entrysize);
+ ++n;
+ }
+
+ if(closedir(d))
{
throw "cannot read directory `" + path + "':\n" + IcePatch2::lastError();
}