@eskimo I'm debugging some code in a cross-platform C app that is doing some wildcard substitution and manually allocating enough space to hold file names when concatenating file names together. Admittedly this is probably not the best way to do it and ideally we do dynamic allocation only after knowing how long of a name we have, and the code also needs some bounds checking to make sure it won't crash. But basically in this situation, we need to know the max file name size in order to do a static allocation.
From reading glibc at least (which Apple doesn't use) it seems that their limits are essentially suggestive and not guaranteed to be respected: https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html.
Anyway for the code I was looking at, it actually is calling readdir(). It's only the concatenation later that causes problems. If you do man dirent or look at usr/include/dirent.h the docs actually does say it's using 1024 bytes for a file name (there isn't a real constant you can use though), same as max path size, so that's probably what I will use for now, although the code probably should be refactored to not have to have to rely on such constants.
Edit: Just to add. Another reason why we are interested in the max file name is that we want to be able to append a postfix to the file name. So imagine we have a file some_long_name.txt, and we want to save a backup version called some_long_name.txt.backup. It's useful to be able to make the name as long as possible without truncation, but if the constant is wrong we could end up making too long of a name which fails the system call.