Added new filecase test function

This commit is contained in:
Michiel Broek
2003-02-27 20:57:36 +00:00
parent 81aa0911a5
commit edad301e0a
4 changed files with 70 additions and 22 deletions

View File

@@ -283,6 +283,8 @@ long file_crc(char *path, int);
time_t file_time(char *path);
int mkdirs(char *name, mode_t);
int diskfree(int);
int getfilecase(char *, char *);
/*

View File

@@ -4,7 +4,7 @@
* Purpose ...............: Basic File I/O
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@@ -346,3 +346,34 @@ int diskfree(int needed)
}
/*
* Give a directory path and a filename, locate that filename in that
* directory and return the filename with the correct case. This is
* to be able to detect filename.ext, FILENAME.EXT and FiLeNaMe.ExT
*/
int getfilecase(char *path, char *file)
{
DIR *dp;
struct dirent *de;
int i, rc = FALSE;
if ((dp = opendir(path)) == NULL) {
WriteError("$Can't opendir(%s)", path);
return rc;
}
while ((de = readdir(dp))) {
if (strcasecmp(de->d_name, file) == 0) {
for (i = 0; i < strlen(de->d_name); i++)
file[i] = de->d_name[i];
rc = TRUE;
break;
}
}
closedir(dp);
return rc;
}