Created
March 18, 2012 18:27
-
-
Save sahib/2079395 to your computer and use it in GitHub Desktop.
corrected trav.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fts.h> | |
#include <glib.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/stat.h> | |
typedef struct | |
{ | |
char * path; | |
size_t size; | |
ino_t inode; | |
dev_t dev_id; | |
GChecksum * cksum; | |
} Node; | |
void traverse_paths(char * const * path_argv, GList ** list) | |
{ | |
FTS* tree = fts_open(path_argv,FTS_LOGICAL,NULL); | |
FTSENT * node; | |
g_assert(list); | |
while ((node = fts_read(tree)) != NULL) | |
{ | |
Node * data_node = g_slice_new(Node); | |
data_node->path = g_strdup(node->fts_path); | |
data_node->size = node->fts_statp->st_size; | |
data_node->inode = node->fts_statp->st_ino; | |
data_node->dev_id = node->fts_statp->st_dev; | |
*list = g_list_append(*list,data_node); | |
} | |
fts_close(tree); | |
} | |
void print_glist(GList * list) | |
{ | |
while(list != NULL) | |
{ | |
Node * node = list->data; | |
printf("PATH: %s\n",node->path); | |
printf("SIZE: %lu\n",(unsigned long)node->size); | |
printf("INODE: %lu\n",(unsigned long)node->inode); | |
printf("DEV_ID: %lu\n",(unsigned long)node->dev_id); | |
printf("\n"); | |
list = g_list_next(list); | |
} | |
} | |
void free_data(gpointer data) | |
{ | |
Node * node = (Node*)data; | |
g_free(node->path); | |
g_slice_free(Node,node); | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
char * path[argc+1]; | |
path[argc] = NULL; | |
memcpy(path,argv,argc*sizeof(char*)); | |
GList * list = NULL; | |
traverse_paths(path,&list); | |
print_glist(list); | |
g_list_free_full(list,free_data); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment