equal
deleted
inserted
replaced
|
1 /* |
|
2 * $Id: md5recursive.c 94 2008-04-05 01:27:30Z mbroeker $ |
|
3 * $URL: http://localhost/svn/c/lsflib/trunk/src/md5recursive.c $ |
|
4 * |
|
5 */ |
|
6 |
|
7 #include <stdio.h> |
|
8 #include <stdlib.h> |
|
9 #include <dirent.h> |
|
10 #include <sys/types.h> |
|
11 #include <sys/stat.h> |
|
12 #include <unistd.h> |
|
13 #include <string.h> |
|
14 |
|
15 #include <lsf.h> |
|
16 |
|
17 void md5recursive (char *root, int recursive) |
|
18 { |
|
19 struct dirent *entry; |
|
20 DIR *directory; |
|
21 char *list; |
|
22 unsigned char *value; |
|
23 int i; |
|
24 |
|
25 if (!isDir (root)) |
|
26 return; |
|
27 |
|
28 if ((directory = opendir (root)) == NULL) { |
|
29 perror (root); |
|
30 return; |
|
31 } |
|
32 |
|
33 while ((entry = readdir (directory))) { |
|
34 list = (char *)malloc (strlen (root) + 1 + strlen (entry->d_name) + 1); |
|
35 |
|
36 if (list == NULL) { |
|
37 perror ("malloc"); |
|
38 return; |
|
39 } |
|
40 |
|
41 sprintf (list, "%s/%s", root, entry->d_name); |
|
42 |
|
43 if (!strcmp (entry->d_name, ".")) |
|
44 continue; |
|
45 |
|
46 if (!strcmp (entry->d_name, "..")) |
|
47 continue; |
|
48 |
|
49 if (isDir (list)) { |
|
50 fprintf (stderr, "Directory: %s\n", list); |
|
51 if (recursive) { |
|
52 md5recursive (list, recursive); |
|
53 } |
|
54 continue; |
|
55 } |
|
56 |
|
57 if ((value = md5sum (list)) == NULL) { |
|
58 continue; |
|
59 } |
|
60 |
|
61 for (i = 0; i < 16; i++) |
|
62 printf ("%02x", value[i]); |
|
63 printf (" %s\n", list); |
|
64 free (value); |
|
65 } |
|
66 |
|
67 free (list); |
|
68 closedir (directory); |
|
69 } |