Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 89 lines (71 sloc) 2.401 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/*
Application: CSS Optimizer
Copyright (C) 2005 Michael Bianco <software@mabwebdesign.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#import "fileSystemFunctions.h"
#import "recursiveFunctions.h"
#import "fileStripperFunctions.h"
#import "constants.h"

#import <stdio.h>
#import <dirent.h>
#import <sys/stat.h>
#import <stdlib.h>
#import <string.h>
#import <unistd.h>

int listDir(char *dirName, void (*funct)(char *)) {
if(access(dirName, R_OK | F_OK) == -1) {
printf("[listDir()]Not enough permissions to read directory:%s\n", dirName);
return -1;
}

DIR *dir;
if((dir = opendir(dirName)) == NULL) {
printf("[listDir()]Error Cannot read dir:%s\n", dirName);
return 0;
}

struct dirent *currFile;

while((currFile = readdir(dir)) != NULL) {
if(strcmp(currFile->d_name, ".") == 0 || strcmp(currFile->d_name, "..") == 0)
continue;
#if DEBUG >= 3
printf("[listDir()]Reading file name: %s From dir: %s\n", currFile->d_name, dirName);
#endif
char *tempString = (char *) malloc(strlen(currFile->d_name)+strlen(dirName)+2);

strcpy(tempString, dirName);
if(tempString[strlen(tempString)-1] != '/')
strcat(tempString, "/"); //add a slash if the directory path does not contain one
strcat(tempString, currFile->d_name);
#if DEBUG >= 2
printf("[listDir()]File: %s isDir:%i\n", tempString, isDir(tempString));
#endif

if(isDir(tempString) == 1) {
listDir(strdup(tempString), funct);
#if DEBUG >= 2
printf("[listDir()]Now searching %s Dir\n", tempString);
#endif
}

funct(tempString);
free(tempString);
}

free(dirName);
closedir(dir);
return 0;
}

int isLink(const char *name) {
struct stat file;
stat(name, &file);

if(S_ISLNK(file.st_mode))
return 1;
else
return 0;
}
Something went wrong with that request. Please try again.