~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/clean_dir.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#include "clean_dir.h"
 
9
#include "stringtools.h"
 
10
 
 
11
#include <dirent.h>
 
12
#include <limits.h>
 
13
#include <stdlib.h>
 
14
#include <string.h>
 
15
#include <stdio.h>
 
16
#include <unistd.h>
 
17
 
 
18
int clean_dir( const char *dirname, const char *delete_pattern )
 
19
{
 
20
        char subdir[PATH_MAX];
 
21
        struct dirent *d;
 
22
        DIR *dir;
 
23
 
 
24
        dir = opendir(dirname);
 
25
        if(!dir) return 0;
 
26
 
 
27
        while((d=readdir(dir))) {
 
28
                if(!strcmp(d->d_name,".")) continue;
 
29
                if(!strcmp(d->d_name,"..")) continue;
 
30
                sprintf(subdir,"%s/%s",dirname,d->d_name);
 
31
                clean_dir(subdir,delete_pattern);
 
32
                if(string_match(delete_pattern,d->d_name)) {
 
33
                        unlink(d->d_name);
 
34
                }
 
35
        }
 
36
 
 
37
        closedir(dir);
 
38
 
 
39
        return 1;
 
40
}