Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way of checking if file system is case-insensitive in the preprocessors?

I want to make a check in the preprocessor if the file system is case-insensitive. Till now I was assuming macOS always has case-insensitive paths, but recently I read that it depends on file system. I just needed a way to make this check in #if, so I can set my array size accordingly.

like image 555
Mihir Luthra Avatar asked Jun 14 '19 15:06

Mihir Luthra


1 Answers

This would be a very bad idea unless you have very specific needs. One system can have multiple file systems, where some are case sensitive and some are not. That's not even unusual. This alone proves that the task is impossible to solve in the general case. It's theoretically possible to do this at compile time for a given path. But to make it even worse, these circumstances can change. Let's say that your program read and/or writes to /path/to/data, and then the user decides to replace the file system with something else. Now your program is broken.

The best solution for most problems related to this is probably to not assume anything about the case sensitiveness during compilation. Find out during execution instead.

But one thing worth mentioning is that modern case insensitive filesystems do preserve the original case of the filename. An example of a filesystem that is non case preserving is FAT used in the old MS-DOS, but that filesystem is very rare today. You will find it hard to find someone who is not a retro-fan using them.

like image 180
klutt Avatar answered Sep 23 '22 21:09

klutt