im working on a homework assignment. the assignment is to write a simple unix 'myFind' command with synopsis: find <filename>. it searches current directory and every subdirectory and prints the path of each file whos name is <filename>.
after some debugging, i thought it would be easier to basically make it a recursive 'ls' command, as my find isnt working. the 'ls' isnt working either. when i run from my home directory it seems to work fine. however, if i run from / or /usr (maybe more directories too) it does not work.
when i run from / it gets stuck searching in a weird directory (which doesnt exist) like /dev/fd/3/0/dev/fd/3/cpu/bin/dev/3...etc
when i run from /usr it also doesnt work properly. if i run it from /usr, as "./myFind | grep stdio.h" it returns no output. however, there are multiple files in subdirectories of this folder named stdio.h.
i have tried using stat but it isnt helping so i stopped with that. i have emailed my professor asking if we have to check if a file is a link, device, etc, and he said we dont have to, and also that we do not _have_ to use stat to do this assignment. i would like to do it without stat.
heres the code if you have time to check it out.
void search(char* path)
dp = opendir(path);
if (dp == NULL)
printf("cant open: %s\n",path);
struct dirent* dirp;
while( (dirp = readdir(dp)) != NULL )
if (strcmp(dirp->d_name,".") == 0 || strcmp(dirp->d_name,"..") == 0)
int main(int argc, char* argv)
thanks for your time.
from my home directory (with a deep arbitrarily copied hierarchy) it lists the files, including one named:
the reason im including this is to show that it is looking in complicated and deep subdirectories such as the one above. this (and the /dev/... thing above) leads me to think that there must be a problem with files that are not regular files or directories. however, my professor told me it can be done without checking for this.