BLI_path: include FILE_MAX in BLI_path_{abs,rel} function signatures

These are now the only two BLI_path functions which assume paths are
FILE_MAX size which makes sense as they're using the `//` file prefix.
Something that's specific to file paths stored in DNA.

Use FILE_MAX in the function signature as a form of documentation.
This commit is contained in:
Campbell Barton
2023-05-15 09:16:51 +10:00
parent e225a53e54
commit ab2dfc842a
2 changed files with 45 additions and 26 deletions

View File

@@ -425,17 +425,6 @@ bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL(1);
const char *BLI_path_parent_dir_end(const char *path, size_t path_len)
ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
/**
* If path begins with "//", strips that and replaces it with `basepath` directory.
*
* \note Also converts drive-letter prefix to something more sensible
* if this is a non-drive-letter-based system.
*
* \param path: The path to convert.
* \param basepath: The directory to base relative paths with.
* \return true if the path was relative (started with "//").
*/
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL(1, 2);
/**
* Replaces "#" character sequence in last slash-separated component of `path`
* with frame as decimal integer, with leading zeroes as necessary, to make digits.
@@ -478,17 +467,6 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED
* In most cases #BLI_path_abs should be used instead.
*/
bool BLI_path_abs_from_cwd(char *path, size_t path_maxncpy) ATTR_NONNULL(1);
/**
* Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given
* the same `basename`, will convert it back to its original value.
*/
void BLI_path_rel(char *path, const char *basename) ATTR_NONNULL(1);
/**
* Does path begin with the special "//" prefix that Blender uses to indicate
* a path relative to the .blend file.
*/
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
/**
* Return true if the path is a UNC share.
*/
@@ -544,14 +522,55 @@ bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const
int BLI_path_cmp_normalized(const char *p1, const char *p2)
ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
/* These values need to be hard-coded in structs, dna does not recognize defines */
/* also defined in `DNA_space_types.h`. */
/* -------------------------------------------------------------------- */
/** \name Blend File Relative Paths
* \{ */
/**
* These values need to be hard-coded in structs, dna does not recognize defines
* (also defined in `DNA_space_types.h`).
*
* \note In general path functions should *not* depend on these hard coded limits,
* there is an exception for:
* - #BLI_path_abs
* - #BLI_path_rel
* These functions deal specifically with `.blend` file paths,
* where #FILE_MAX assumed to be the limit of all paths passes into these functions.
*
* Some parts of the API which use #FILE_MAX which aren't specifically handling blend file paths,
* in most cases these can be updated to use #PATH_MAX or a platform specific limit.
*/
#ifndef FILE_MAXDIR
# define FILE_MAXDIR 768
# define FILE_MAXFILE 256
# define FILE_MAX 1024
#endif
/**
* If path begins with "//", strips that and replaces it with `basepath` directory.
*
* \note Also converts drive-letter prefix to something more sensible
* if this is a non-drive-letter-based system.
*
* \param path: The path to convert.
* \param basepath: The directory to base relative paths with.
* \return true if the path was relative (started with "//").
*/
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1, 2);
/**
* Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given
* the same `basename`, will convert it back to its original value.
*/
void BLI_path_rel(char path[FILE_MAX], const char *basename) ATTR_NONNULL(1);
/**
* Does path begin with the special "//" prefix that Blender uses to indicate
* a path relative to the .blend file.
*/
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
/** \} */
#ifdef WIN32
# define SEP '\\'
# define ALTSEP '/'

View File

@@ -592,7 +592,7 @@ void BLI_path_normalize_unc_16(wchar_t *path_16)
}
#endif
void BLI_path_rel(char *path, const char *basename)
void BLI_path_rel(char path[FILE_MAX], const char *basename)
{
BLI_string_debug_size_after_nil(path, FILE_MAX);
@@ -1025,7 +1025,7 @@ void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, cons
}
}
bool BLI_path_abs(char *path, const char *basepath)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath)
{
BLI_string_debug_size_after_nil(path, FILE_MAX);