I'm working on crossplatform library which will be used to file manipulations (create, rename, delete, ...) on optical media. So I have questions related to path handling.
Currently开发者_Go百科 I have no restriction on path length in my library, so user can create folder with very long path which is not supported by OS. For example in windows user can create folder with pathlen bigger that
MAX_PATH
characters. So what I must do in this situation?Solution for first question, maybe checking new path len which will created after file/folder copying. But there is another problem, caused by different values of MAX_PATH and PATH_MAX in windows and linux.
C
defines a standard macro FILENAME_MAX
.
"This macro constant expands to an integral expression corresponding to the size needed for an array of char elements to hold the longest file name string allowed by the system. Or, if the system imposes no such restriction, it is set to the recommended size for character arrays intended to hold any file name."
This should be large enough to specify a string which holds the longest name which can be used for a file name. It's a macro so that its value is platform-dependent.
Most OS APIS should return a speicific error indicating that the name is too handle, you can properly handle it and report back to user.
精彩评论