Yes. You need to use opendir and stat. See 'man 3 opendir', and 'man 2 stat'.
In a nutshell:
#include <dirent.h>
#include <sys/stat.h>
// etc...
void the_du_c_function() {
struct dirent direntBuf;
struct dirent* dirEntry = 0;
const char* theDir = ".";
DIR* dir = opendir(theDir);
while (readdir_r(dir,&direntBuf,dirEntry) && dirEntry) {
struct stat filestat;
char filename[1024];
snprintf(filename,sizeof(filename),"%s/%s",theDir,dirEntry.d_name);
stat(filename,&filestat);
fprintf(stdout,"%s - %u bytes\n",filename,filestat.st_size);
}
}
I just typed that code segment. I did not compile it, but that's the gist of it.