Skip to content

Instantly share code, notes, and snippets.

@kkrolikowski
Last active April 9, 2017 11:46
Show Gist options
  • Save kkrolikowski/85bb313823ccaf8563e46206a88e3525 to your computer and use it in GitHub Desktop.
Save kkrolikowski/85bb313823ccaf8563e46206a88e3525 to your computer and use it in GitHub Desktop.
compatibile with XFS filesystem
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
void printdir(char * name);
int main(int argc, char *argv[]) {
printdir(argv[1]);
return 0;
}
void printdir(char * name) {
DIR * d;
struct dirent * entry;
struct stat n;
char buff[256];
memset(buff, '\0', 256);
strcpy(buff, name);
d = opendir(name);
stat(buff, &n);
while((entry = readdir(d)) != NULL) {
if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
continue;
strcat(buff, entry->d_name);
stat(buff, &n);
if(S_ISDIR(n.st_mode)) {
strcat(buff, "/");
printf("type: %ld, name: %s\n", (unsigned long) n.st_mode & S_IFMT, buff);
printdir(buff);
}
else
printf("type: %ld, name: %s\n", (unsigned long) n.st_mode & S_IFMT, buff);
memset(buff, '\0', 256);
strcpy(buff, name);
}
closedir(d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment