This problem is pretty involved, and perhaps no one will be able to help me, but I thought I would throw it out and see.

Before I get into the problem, I should ask if there is a function in standard C that will do the same thing as the 'du' command. I didn't find one, so I created a function that would take a path, open it with fts_open, and then total up the file sizes for each file in the directory (recursively).

The problem is that the function works great in test programs, but when I add it into the source of another, much larger program that runs through Apache, it bails. Here is the function:
long get_du(char *path) {
FTS *fileheir;
FTSENT *fsentry;
char **dirnames;
unsigned long size = 0;

dirnames = malloc(sizeof(char*));
dirnames[0] = path;

fileheir = fts_open(dirnames, FTS_PHYSICAL, NULL);
while ((fsentry = fts_read(fileheir)) != NULL) {
if (fsentry->fts_number == 0) {
size = size + fsentry->fts_statp->st_size;
fsentry->fts_number = 1;
return size;
Sorry about any bad formatting with the web forum, but the function is pretty short.

Thanks for any help.