Blender V5.0
BLI_path_utils.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
10#include "BLI_compiler_attrs.h"
11#include "BLI_compiler_compat.h"
12#include "BLI_utildefines.h"
14
15/* -------------------------------------------------------------------- */
18
31bool BLI_path_name_at_index(const char *__restrict path,
32 int index,
33 int *__restrict r_offset,
34 int *__restrict r_len) ATTR_NONNULL(1, 3, 4) ATTR_WARN_UNUSED_RESULT;
35
40
41bool BLI_path_is_win32_drive(const char *path);
42bool BLI_path_is_win32_drive_only(const char *path);
43bool BLI_path_is_win32_drive_with_slash(const char *path);
44
46
47/* -------------------------------------------------------------------- */
50
59bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1);
67
79const char *BLI_path_parent_dir_end(const char *path, size_t path_len)
81
83
84/* -------------------------------------------------------------------- */
87
119bool BLI_path_make_safe_filename_ex(char *filename, bool allow_tokens) ATTR_NONNULL(1);
120bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1);
121
131bool BLI_path_make_safe(char *path) ATTR_NONNULL(1);
132
139void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, const char *name)
140 ATTR_NONNULL(1, 3);
141
143
144/* -------------------------------------------------------------------- */
147
170int BLI_path_normalize(char *path) ATTR_NONNULL(1);
171
179int BLI_path_normalize_native(char *path) ATTR_NONNULL(1);
180
188int BLI_path_normalize_dir(char *dir, size_t dir_maxncpy) ATTR_NONNULL(1);
189
190#if defined(WIN32)
191void BLI_path_normalize_unc_16(wchar_t *path_16);
192void BLI_path_normalize_unc(char *path, int path_maxncpy);
193#endif
194
196
197/* -------------------------------------------------------------------- */
200
215int BLI_path_canonicalize_native(char *path, int path_maxncpy);
216
218
219/* -------------------------------------------------------------------- */
222
227bool BLI_path_filename_ensure(char *filepath, size_t filepath_maxncpy, const char *filename)
228 ATTR_NONNULL(1, 3);
229
242bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const char *sep)
243 ATTR_NONNULL(1, 3, 4);
244
246
247/* -------------------------------------------------------------------- */
250
254const char *BLI_path_slash_find(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
258const char *BLI_path_slash_rfind(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
264int BLI_path_slash_ensure_ex(char *path, size_t path_maxncpy, const size_t path_len)
265 ATTR_NONNULL(1);
270int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1);
274void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1);
278const char *BLI_path_slash_skip(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
282void BLI_path_slash_native(char *path) ATTR_NONNULL(1);
283
285
286/* -------------------------------------------------------------------- */
289
294void BLI_path_split_dir_file(const char *filepath,
295 char *dir,
296 size_t dir_maxncpy,
297 char *file,
298 size_t file_maxncpy) ATTR_NONNULL(1, 2, 4);
302void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy)
303 ATTR_NONNULL(1, 2);
309void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy)
310 ATTR_NONNULL(1, 2);
311
318const char *BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
319
321
322/* -------------------------------------------------------------------- */
325
330
332
333/* -------------------------------------------------------------------- */
336
341size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file)
342 ATTR_NONNULL(1, 3);
347size_t BLI_path_append_dir(char *__restrict dst, size_t dst_maxncpy, const char *__restrict dir)
348 ATTR_NONNULL(1, 3);
349
351
352/* -------------------------------------------------------------------- */
355
359size_t BLI_path_join_array(char *__restrict dst,
360 const size_t dst_maxncpy,
361 const char *path_array[],
362 const int path_array_num) ATTR_NONNULL(1, 3);
363
379#define BLI_path_join(...) VA_NARGS_CALL_OVERLOAD(_BLI_path_join_, __VA_ARGS__)
380
381#define _BLI_PATH_JOIN_ARGS_1 char *__restrict dst, size_t dst_maxncpy, const char *a
382#define _BLI_PATH_JOIN_ARGS_2 _BLI_PATH_JOIN_ARGS_1, const char *b
383#define _BLI_PATH_JOIN_ARGS_3 _BLI_PATH_JOIN_ARGS_2, const char *c
384#define _BLI_PATH_JOIN_ARGS_4 _BLI_PATH_JOIN_ARGS_3, const char *d
385#define _BLI_PATH_JOIN_ARGS_5 _BLI_PATH_JOIN_ARGS_4, const char *e
386#define _BLI_PATH_JOIN_ARGS_6 _BLI_PATH_JOIN_ARGS_5, const char *f
387#define _BLI_PATH_JOIN_ARGS_7 _BLI_PATH_JOIN_ARGS_6, const char *g
388#define _BLI_PATH_JOIN_ARGS_8 _BLI_PATH_JOIN_ARGS_7, const char *h
389#define _BLI_PATH_JOIN_ARGS_9 _BLI_PATH_JOIN_ARGS_8, const char *i
390#define _BLI_PATH_JOIN_ARGS_10 _BLI_PATH_JOIN_ARGS_9, const char *j
391
402
404{
405 const char *path_array[] = {a};
406 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
407}
409{
410 const char *path_array[] = {a, b};
411 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
412}
414{
415 const char *path_array[] = {a, b, c};
416 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
417}
419{
420 const char *path_array[] = {a, b, c, d};
421 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
422}
424{
425 const char *path_array[] = {a, b, c, d, e};
426 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
427}
429{
430 const char *path_array[] = {a, b, c, d, e, f};
431 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
432}
434{
435 const char *path_array[] = {a, b, c, d, e, f, g};
436 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
437}
439{
440 const char *path_array[] = {a, b, c, d, e, f, g, h};
441 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
442}
444{
445 const char *path_array[] = {a, b, c, d, e, f, g, h, i};
446 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
447}
449{
450 const char *path_array[] = {a, b, c, d, e, f, g, h, i, j};
451 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
452}
453
454#undef _BLI_PATH_JOIN_ARGS_1
455#undef _BLI_PATH_JOIN_ARGS_2
456#undef _BLI_PATH_JOIN_ARGS_3
457#undef _BLI_PATH_JOIN_ARGS_4
458#undef _BLI_PATH_JOIN_ARGS_5
459#undef _BLI_PATH_JOIN_ARGS_6
460#undef _BLI_PATH_JOIN_ARGS_7
461#undef _BLI_PATH_JOIN_ARGS_8
462#undef _BLI_PATH_JOIN_ARGS_9
463#undef _BLI_PATH_JOIN_ARGS_10
464
466
467/* -------------------------------------------------------------------- */
470
475const char *BLI_path_extension_or_end(const char *filepath)
481const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
482
486bool BLI_path_extension_check(const char *path, const char *ext)
488bool BLI_path_extension_check_n(const char *path, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
492bool BLI_path_extension_check_array(const char *path, const char **ext_array)
498bool BLI_path_extension_check_glob(const char *path, const char *ext_fnmatch)
509bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL(1);
514bool BLI_path_extension_replace(char *path, size_t path_maxncpy, const char *ext)
515 ATTR_NONNULL(1, 3);
520bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1);
524bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext)
525 ATTR_NONNULL(1, 3);
526
528
529/* -------------------------------------------------------------------- */
532
533/* Path string comparisons: case-insensitive for Windows, case-sensitive otherwise. */
534#if defined(WIN32)
535# define BLI_path_cmp BLI_strcasecmp
536# define BLI_path_ncmp BLI_strncasecmp
537#else
538# define BLI_path_cmp strcmp
539# define BLI_path_ncmp strncmp
540#endif
541
553int BLI_path_cmp_normalized(const char *p1, const char *p2)
555
557bool BLI_path_contains(const char *container_path, const char *containee_path)
559
561
562/* -------------------------------------------------------------------- */
565
566#ifdef _WIN32
567bool BLI_path_program_extensions_add_win32(char *program_name, size_t program_name_maxncpy);
568#endif
573 size_t program_filepath_maxncpy,
574 const char *program_name) ATTR_NONNULL(1, 3);
575
577
578/* -------------------------------------------------------------------- */
581
586void BLI_path_sequence_encode(char *path,
587 size_t path_maxncpy,
588 const char *head,
589 const char *tail,
590 unsigned short numlen,
591 int pic);
592
604int BLI_path_sequence_decode(const char *path,
605 char *head,
606 size_t head_maxncpy,
607 char *tail,
608 size_t tail_maxncpy,
609 unsigned short *r_digits_len);
610
612
613/* -------------------------------------------------------------------- */
616
621bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1);
627bool BLI_path_frame_range(char *path, size_t path_maxncpy, int sta, int end, int digits)
628 ATTR_NONNULL(1);
632bool BLI_path_frame_get(const char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL(1, 2, 3);
639void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxncpy) ATTR_NONNULL(1, 2);
644
646
647/* -------------------------------------------------------------------- */
650
665#ifndef FILE_MAXDIR
666# define FILE_MAXDIR 768
667# define FILE_MAXFILE 256
668# define FILE_MAX 1024
669#endif
670
681bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1, 2);
686void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1);
687
693
695
696/* -------------------------------------------------------------------- */
699
714bool BLI_path_abs_from_cwd(char *path, size_t path_maxncpy) ATTR_NONNULL(1);
715
717
718/* -------------------------------------------------------------------- */
721
722#ifdef WIN32
723# define SEP '\\'
724# define ALTSEP '/'
725# define SEP_STR "\\"
726# define ALTSEP_STR "/"
727#else
728# define SEP '/'
729# define ALTSEP '\\'
730# define SEP_STR "/"
731# define ALTSEP_STR "\\"
732#endif
733
738{
739 /* On UNIX it only makes sense to treat `/` as a path separator.
740 * On WIN32 either may be used. */
741 if (ch == SEP) {
742 return true;
743 }
744#ifdef WIN32
745 if (ch == ALTSEP) {
746 return true;
747 }
748#endif
749 return false;
750}
751
753
754/* -------------------------------------------------------------------- */
759
764void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
771void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
780const char *BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
781
783
784/* -------------------------------------------------------------------- */
787
788/* Parent and current dir helpers. */
789#define FILENAME_PARENT ".."
790#define FILENAME_CURRENT "."
791
792/* Avoid calling `strcmp` on one or two chars! */
793#define FILENAME_IS_PARENT(_n) (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
794#define FILENAME_IS_CURRENT(_n) (((_n)[0] == '.') && ((_n)[1] == '\0'))
795#define FILENAME_IS_CURRPAR(_n) \
796 (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
797
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_SENTINEL(arg_pos)
#define ATTR_RETURNS_NONNULL
#define ATTR_NONNULL(...)
#define BLI_INLINE
BLI_INLINE size_t _BLI_path_join_11(_BLI_PATH_JOIN_ARGS_9) ATTR_NONNULL()
BLI_INLINE size_t _BLI_path_join_6(_BLI_PATH_JOIN_ARGS_4) ATTR_NONNULL()
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL(1)
#define ALTSEP
bool void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxncpy) ATTR_NONNULL(1
#define _BLI_PATH_JOIN_ARGS_7
#define _BLI_PATH_JOIN_ARGS_4
BLI_INLINE size_t _BLI_path_join_7(_BLI_PATH_JOIN_ARGS_5) ATTR_NONNULL()
bool BLI_path_make_safe(char *path) ATTR_NONNULL(1)
size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file) ATTR_NONNULL(1
bool BLI_path_filename_ensure(char *filepath, size_t filepath_maxncpy, const char *filename) ATTR_NONNULL(1
bool bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const char *sep) ATTR_NONNULL(1
bool bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1)
bool void bool BLI_path_frame_check_chars(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define _BLI_PATH_JOIN_ARGS_9
#define _BLI_PATH_JOIN_ARGS_3
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
BLI_INLINE size_t _BLI_path_join_9(_BLI_PATH_JOIN_ARGS_7) ATTR_NONNULL()
void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, const char *name) ATTR_NONNULL(1
#define _BLI_PATH_JOIN_ARGS_8
int BLI_path_normalize_dir(char *dir, size_t dir_maxncpy) ATTR_NONNULL(1)
bool BLI_path_has_hidden_component(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check_array(const char *path, const char **ext_array) ATTR_NONNULL(1
int BLI_path_slash_ensure_ex(char *path, size_t path_maxncpy, const size_t path_len) ATTR_NONNULL(1)
#define FILE_MAX
bool BLI_path_extension_replace(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1)
void BLI_path_slash_native(char *path) ATTR_NONNULL(1)
bool BLI_path_program_search(char *program_filepath, size_t program_filepath_maxncpy, const char *program_name) ATTR_NONNULL(1
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
const char * BLI_path_extension_or_end(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_is_win32_drive(const char *path)
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void void void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy) ATTR_NONNULL(1
int BLI_path_canonicalize_native(char *path, int path_maxncpy)
#define _BLI_PATH_JOIN_ARGS_1
BLI_INLINE size_t _BLI_path_join_10(_BLI_PATH_JOIN_ARGS_8) ATTR_NONNULL()
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define SEP
BLI_INLINE size_t _BLI_path_join_12(_BLI_PATH_JOIN_ARGS_10) ATTR_NONNULL()
bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL(1)
#define _BLI_PATH_JOIN_ARGS_5
bool BLI_path_frame_get(const char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL(1
#define _BLI_PATH_JOIN_ARGS_10
const char * BLI_path_slash_skip(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
const char * BLI_path_slash_find(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
BLI_INLINE bool BLI_path_slash_is_native_compat(const char ch)
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
Definition path_utils.cc:58
const char * BLI_path_parent_dir_end(const char *path, size_t path_len) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
size_t BLI_path_join_array(char *__restrict dst, const size_t dst_maxncpy, const char *path_array[], const int path_array_num) ATTR_NONNULL(1
void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
bool BLI_path_extension_check_n(const char *path,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
BLI_INLINE size_t _BLI_path_join_8(_BLI_PATH_JOIN_ARGS_6) ATTR_NONNULL()
bool BLI_path_is_win32_drive_only(const char *path)
bool BLI_path_make_safe_filename_ex(char *filename, bool allow_tokens) ATTR_NONNULL(1)
BLI_INLINE size_t _BLI_path_join_3(_BLI_PATH_JOIN_ARGS_1) ATTR_NONNULL()
size_t size_t BLI_path_append_dir(char *__restrict dst, size_t dst_maxncpy, const char *__restrict dir) ATTR_NONNULL(1
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
#define _BLI_PATH_JOIN_ARGS_6
bool BLI_path_is_win32_drive_with_slash(const char *path)
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
bool BLI_path_abs_from_cwd(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
#define _BLI_PATH_JOIN_ARGS_2
const char * BLI_path_slash_rfind(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_frame_range(char *path, size_t path_maxncpy, int sta, int end, int digits) ATTR_NONNULL(1)
const char * BLI_path_extension(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_path_normalize_native(char *path) ATTR_NONNULL(1)
bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1)
bool BLI_path_extension_check_glob(const char *path, const char *ext_fnmatch) ATTR_NONNULL(1
bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_name_at_index(const char *__restrict path, int index, int *__restrict r_offset, int *__restrict r_len) ATTR_NONNULL(1
BLI_INLINE size_t _BLI_path_join_5(_BLI_PATH_JOIN_ARGS_3) ATTR_NONNULL()
BLI_INLINE size_t _BLI_path_join_4(_BLI_PATH_JOIN_ARGS_2) ATTR_NONNULL()
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
#define ARRAY_SIZE(arr)
char program_filepath[FILE_MAX]
Definition appdir.cc:66
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
const char * name
i
Definition text_draw.cc:230