1 /**************************************************************************\
2 *  HighLnk 0.2                            http://www.thpinfo.com/highlnk/  *
3 *      This source code is released under the terms in the LICENSE file.   *
4 *  Copyright (c) 2004 Thomas Perl <perl.thomas@aon.at>                     *
5 \**************************************************************************/
6 
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <dirent.h>
10 #include <sys/syslimits.h>
11 
12 #include "md5.h"
13 #include "finder.h"
14 #include "highlnk.h"
15 
findFiles(const char * path,RESULTFUNC results)16 void findFiles( const char *path, RESULTFUNC results)
17 {
18   DIR *d;               // directory
19   struct dirent *e;     // entry
20   static struct stat s; // stat
21   char *n;              // name
22 
23   stat( path, &s);
24   (*results)( path, &s);
25 
26   if( !(d = opendir( path)))
27   {
28     fprintf( stderr, "findFiles: Cannot open directory: %s\n", path);
29     return;
30   }
31 
32   while( e = readdir( d))
33   {
34     if( 0 == strcmp( e->d_name, "..") || 0 == strcmp( e->d_name, "."))
35       continue;
36 
37     n = (char*)malloc( strlen( path) + strlen( e->d_name) + 2);
38     strcpy( n, path);
39     strcat( n, "/");
40     strcat( n, e->d_name);
41 
42     stat( n, &s);
43 
44     if( S_ISDIR( s.st_mode))
45       findFiles( n, results);
46     else
47       (*results)( n, &s);
48 
49     free( n);
50   }
51 
52   closedir( d);
53 }
54 
55