We are now porting a program from linux to solaris. In the linux
version, i wrote a function to remove a dir recursively, the code is
showed as follows:
void remove_dir(char* sz_dir)
{
char subname[256];
DIR *pdir = NULL;
struct dirent *pdirent = NULL;
pdir = opendir(sz_dir);
if (pdir) {
//printf("into dir %s\n", sz_dir);
while ((pdirent = readdir(pdir)) != NULL) {
//printf("type is %d\n", pdirent->d_type);
//printf("name is %s\n", pdirent->d_name);
if (pdirent->d_type == 8) {
sprintf(subname, "%s/%s", sz_dir, pdirent->d_name);
remove(subname);
}
if (pdirent->d_type == 4
&& strcmp(pdirent->d_name, ".") != 0
&& strcmp(pdirent->d_name, "..") != 0) {
sprintf(subname, "%s/%s", sz_dir, pdirent->d_name);
remove_dir(subname);
}
}
closedir(pdir);
remove(sz_dir);
}
else {
printf("Error in reading %s : %s\n", sz_dir, strerror(errno));
}
I found the struct dirent in solaris doesn't have field d_type! I amQuote:}
not familiar with solaris, so, please tell me how to remove a dir in
solaris, thanks a lot.