Subversion Repositories wimsdev

Rev

Rev 10 | Rev 8160 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
7840 bpr 18
/* directory manipulation routines. */
10 reyssat 19
 
7840 bpr 20
/* remove a tree */
10 reyssat 21
int remove_tree(char *dirname)
22
{
23
    DIR *sdir;
24
    struct dirent *f;
25
    struct stat dst;
26
 
27
    sdir=opendir(dirname);
28
    if(sdir==NULL) {   /* Cannot open session directory. */
7840 bpr 29
      return -1;
10 reyssat 30
    }
31
    while((f=readdir(sdir))!=NULL) {
7840 bpr 32
      char fname[MAX_LINELEN+1];
33
      if(strcmp(".",f->d_name)==0 || strcmp("..",f->d_name)==0) continue;
34
      snprintf(fname,sizeof(fname),"%s/%s",dirname,f->d_name);
35
      if(lstat(fname,&dst)) continue;
36
      if(S_ISDIR(dst.st_mode)) remove_tree(fname);
37
      else remove(fname);
10 reyssat 38
    }
39
    closedir(sdir);
7840 bpr 40
    if(rmdir(dirname)<0) { /* Cannot remove directory. */
41
      return -1;
10 reyssat 42
    }
43
    return 0;
44
}
45
 
7840 bpr 46
/* recursively generate a directory structure */
10 reyssat 47
void mkdirs(char *s)
48
{
49
    struct stat st;
50
    if(stat(s,&st)==-1) {
7840 bpr 51
      if(strrchr(s,'/')!=NULL) {
52
          char buf[MAX_FNAME+1];
53
          mystrncpy(buf,s,sizeof(buf));
54
          *strrchr(buf,'/')=0; mkdirs(buf);
55
      }
56
      mkdir(s,S_IRWXU|S_IRWXG|S_IRWXO);
10 reyssat 57
    }
58
}
59