Name: Anonymous 2012-03-08 5:18
It is unsafe, verbose and not particularly fast. Why I'm writing much more readable code with Lisp, using the same API?
Lisp:
(defun folder-p (path) (w/opendir (dir path) (not (null-pointer-p dir))))
(defun file-p (path)
(unless (folder-p path)
(w/fopen (f path "r")
(not (null-pointer-p f)))))
C/C++:
int folderP(char *Name) {
DIR *Dir;
struct dirent *Ent;
if(!(Dir = opendir(Name))) return 0;
closedir(Dir);
return 1;
}
int fileP(char *Name) {
FILE *F;
if (folderP(Name)) return 0;
F = fopen(Name, "r");
unless (F) return 0;
fclose (F);
return 1;
}
Lisp:
(defun folder-p (path) (w/opendir (dir path) (not (null-pointer-p dir))))
(defun file-p (path)
(unless (folder-p path)
(w/fopen (f path "r")
(not (null-pointer-p f)))))
C/C++:
int folderP(char *Name) {
DIR *Dir;
struct dirent *Ent;
if(!(Dir = opendir(Name))) return 0;
closedir(Dir);
return 1;
}
int fileP(char *Name) {
FILE *F;
if (folderP(Name)) return 0;
F = fopen(Name, "r");
unless (F) return 0;
fclose (F);
return 1;
}