All of them should compile via "make $SHORT" where $SHORT is the name without the ".c" extension...at least on Alpine Linux, or other musl-based systems.
On glibc-based distros like Puppy, some might require CFLAGS="-D_XOPEN_SOURCE=700 -D_BSD_SOURCE" to compile.
I'm releasing all of these as public domain.
Readdir example:
Code: Select all
#include <dirent.h>
#include <stdio.h>
int main(int argc,char **argv)
{
DIR *crd;
struct dirent *cre;
char crt[2] = "?";
char **dirs = (char *[]){".", NULL};
if (argc-1) dirs = argv + 1;
for( ; *dirs; dirs++) {
crd = opendir(dirs[0]);
if (!crd) continue;
do {
if ((cre = readdir(crd)) != NULL) {
if (cre->d_type == DT_BLK) {
*crt = 'b';
} else if (cre->d_type == DT_CHR) {
*crt = 'c';
} else if (cre->d_type == DT_DIR) {
*crt = 'd';
} else if (cre->d_type == DT_FIFO) {
*crt = 'p';
} else if (cre->d_type == DT_LNK) {
*crt = 'l';
} else if (cre->d_type == DT_REG) {
*crt = 'f';
} else if (cre->d_type == DT_SOCK) {
*crt = 's';
} else { *crt ='?'; }
printf("%lld\t%s\t%s\n", cre->d_ino, crt,
cre->d_name);
}
} while (cre);
closedir(crd);
}
return 0;
}
If it can't detect file type, you get '?'.