mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -04:00
nasmlib: add path name comparison function
Add nasm_compare_paths(). At this point, the only effect is wide character/case insensitivity canonicalization on Windows, but in the future it might be doing things like comparing st_dev:st_inode pairs on Unix or compare nasm_realpath(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
parent
86c6b34bd3
commit
1c3d3dc554
2 changed files with 40 additions and 0 deletions
|
|
@ -527,6 +527,9 @@ void nasm_set_binary_mode(FILE *f);
|
|||
/* Probe for existence of a file */
|
||||
bool nasm_file_exists(const char *filename);
|
||||
|
||||
/* Compare two pathnames */
|
||||
int nasm_compare_paths(const char *a, const char *b);
|
||||
|
||||
/* Missing fseeko/ftello */
|
||||
#ifndef HAVE_FSEEKO
|
||||
# undef off_t /* Just in case it is a macro */
|
||||
|
|
|
|||
|
|
@ -102,6 +102,12 @@ static inline void os_set_binary_mode(FILE *f) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline int os_compare_paths(const os_filename a, const os_filename b)
|
||||
{
|
||||
return CompareStringOrdinal(a, -1, b, -1, TRUE);
|
||||
}
|
||||
#define os_compare_paths os_compare_paths
|
||||
|
||||
#else /* not _WIN32 */
|
||||
|
||||
typedef const char *os_filename;
|
||||
|
|
@ -425,3 +431,34 @@ int nasm_remove(const char *pathname)
|
|||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to determine if two paths are the same. This test must not have
|
||||
* false positives; false negatives are OK but (obviously) not ideal.
|
||||
*/
|
||||
#ifdef os_compare_paths
|
||||
int nasm_compare_paths(const char *a, const char *b)
|
||||
{
|
||||
os_filename oa, ob;
|
||||
/* A direct string comparison is usually quick */
|
||||
int rv = strcmp(a, b);
|
||||
|
||||
if (!rv)
|
||||
return rv;
|
||||
|
||||
oa = os_mangle_filename(a);
|
||||
ob = os_mangle_filename(b);
|
||||
|
||||
rv = os_compare_paths(oa, ob);
|
||||
|
||||
os_free_filename(oa);
|
||||
os_free_filename(ob);
|
||||
|
||||
return rv;
|
||||
}
|
||||
#else
|
||||
int nasm_compare_paths(const char *a, const char *b)
|
||||
{
|
||||
return strcmp(a, b);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue