lsflib/src/md5recursive.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:58:02 +0100
changeset 9 c3fecc82ade6
parent 6 c3dc3eb3b541
child 77 49e0babccb23
permissions -rw-r--r--
standard tags for git projects committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
     1
/**
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
     2
 * test/demos/lsflib/src/md5recursive.c
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
6
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <dirent.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
#include <sys/types.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
#include <sys/stat.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
#include <unistd.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
#include <string.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
#include <lsf.h>
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
void md5recursive (char *root, int recursive)
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
{
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
    struct dirent *entry;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
    DIR *directory;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
    char *list;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
    unsigned char *value;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
    int i;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
    if (!isDir (root))
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
        return;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
    if ((directory = opendir (root)) == NULL) {
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
        perror (root);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
        return;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
    }
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    while ((entry = readdir (directory))) {
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
        list = (char *)malloc (strlen (root) + 1 + strlen (entry->d_name) + 1);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
        if (list == NULL) {
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
            perror ("malloc");
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
            return;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
        }
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
        sprintf (list, "%s/%s", root, entry->d_name);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
        if (!strcmp (entry->d_name, "."))
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
            continue;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
        if (!strcmp (entry->d_name, ".."))
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
            continue;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
        if (isDir (list)) {
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
            fprintf (stderr, "Directory: %s\n", list);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
            if (recursive) {
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
                md5recursive (list, recursive);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
            }
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
            continue;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
        }
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
        if ((value = md5sum (list)) == NULL) {
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
            continue;
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
        }
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
        for (i = 0; i < 16; i++)
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
            printf ("%02x", value[i]);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
        printf ("  %s\n", list);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
        free (value);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
    }
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
    free (list);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
    closedir (directory);
c3dc3eb3b541 a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
}