diff options
Diffstat (limited to 'src/file.c')
| -rw-r--r-- | src/file.c | 36 | 
1 files changed, 33 insertions, 3 deletions
| @@ -27,6 +27,12 @@  #if HAVE_UNISTD_H && HAVE_DIRENT_H +int is_dots(struct dirent* entry) +{ +  return entry->d_name && +    (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")); +} +  int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)  {  	struct dirent* ent = 0; @@ -52,9 +58,10 @@ int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)  		}  	}  #ifdef HAVE_FNMATCH -	while(0); +	while(is_dots(ent));  #else -	while(fnmatch(wildcard, ent->d_name, FNM_PATHNAME) == FNM_NOMATCH); +	while(is_dots(ent) || +          fnmatch(wildcard, ent->d_name, FNM_PATHNAME) == FNM_NOMATCH);  #endif  	if(ent) @@ -90,6 +97,12 @@ void dir_close(DIR* handle)  #include <direct.h>  #include <io.h> +int is_dots(struct _finddata_t* findinfo) +{ +  return findinfo->name && +    (!strcmp(findinfo->name, ".") || !strcmp(findinfo->name, "..")); +} +  static void copyDirStruct(struct _finddata_t* findinfo, struct dirent* entry)  {  	/* Copy the structure */ @@ -139,6 +152,18 @@ DIR* dir_first(const char* folder, const char* wildcard, struct dirent* entry)  		free(handle);  		return INVALID_DIR;  	} + +  /* We don't do dots */ +  else if(is_dots(&findinfo)) +  { +    if(dir_next(handle, wildcard, entry)) +      return handle; + +    errno = ENOENT; +    return INVALID_DIR; +  } + +  /* Copy the first file */  	else  	{  		copyDirStruct(&findinfo, entry); @@ -151,7 +176,12 @@ int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)  	struct _finddata_t findinfo;  	int ret = _findnext(*handle, &findinfo) == 0;  	if(ret) -		copyDirStruct(&findinfo, entry); +  { +    if(is_dots(&findinfo)) +      return dir_next(handle, wildcard, entry); +    else +		  copyDirStruct(&findinfo, entry); +  }  	return ret;  } | 
