> Bruce Momjian writes:
>
> > OK, I did the readdir() thing. I hope it is safe to unlink a file while
> > in a readdir() loop.
>
> The only portable member of struct dirent is d_name. (Do you really
> expect non-regular files in the sort directory?) Also, lots of error
> checks (after opendir, readdir, mkdir, unlink) are missing.
Error checks missing in my code or elsewhere? Also, what should I do on
an unlink failure? I thought of printing a message but wasn't sure:
if ((db_dir = opendir(db_path)) != NULL)
while ((db_de = readdir(db_dir)) != NULL)
{
snprintf(temp_path, sizeof(temp_path),
"%s/%s/%s/", db_path, db_de->d_name, SORT_TEMP_DIR);
if ((temp_dir = opendir(temp_path)) != NULL)
while ((temp_de = readdir(temp_dir)) != NULL)
{
if (strspn(temp_de->d_name, "0123456789.") ==
strlen(temp_de->d_name))
{
snprintf(rm_path, sizeof(temp_path),
"%s/%s/%s/%s",
db_path, db_de->d_name,
SORT_TEMP_DIR, temp_de->d_name);
unlink(rm_path);
}
}
}
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026