Blender V4.5
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
137void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, const char *name)
138 ATTR_NONNULL(1, 3);
139
141
142/* -------------------------------------------------------------------- */
145
168int BLI_path_normalize(char *path) ATTR_NONNULL(1);
169
177int BLI_path_normalize_native(char *path) ATTR_NONNULL(1);
178
186int BLI_path_normalize_dir(char *dir, size_t dir_maxncpy) ATTR_NONNULL(1);
187
188#if defined(WIN32)
189void BLI_path_normalize_unc_16(wchar_t *path_16);
190void BLI_path_normalize_unc(char *path, int path_maxncpy);
191#endif
192
194
195/* -------------------------------------------------------------------- */
198
213int BLI_path_canonicalize_native(char *path, int path_maxncpy);
214
216
217/* -------------------------------------------------------------------- */
220
225bool BLI_path_filename_ensure(char *filepath, size_t filepath_maxncpy, const char *filename)
226 ATTR_NONNULL(1, 3);
227
240bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const char *sep)
241 ATTR_NONNULL(1, 3, 4);
242
244
245/* -------------------------------------------------------------------- */
248
252const char *BLI_path_slash_find(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
256const char *BLI_path_slash_rfind(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
262int BLI_path_slash_ensure_ex(char *path, size_t path_maxncpy, const size_t path_len)
263 ATTR_NONNULL(1);
268int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1);
272void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1);
276const char *BLI_path_slash_skip(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
280void BLI_path_slash_native(char *path) ATTR_NONNULL(1);
281
283
284/* -------------------------------------------------------------------- */
287
292void BLI_path_split_dir_file(const char *filepath,
293 char *dir,
294 size_t dir_maxncpy,
295 char *file,
296 size_t file_maxncpy) ATTR_NONNULL(1, 2, 4);
300void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy)
301 ATTR_NONNULL(1, 2);
307void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy)
308 ATTR_NONNULL(1, 2);
309
316const char *BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
317
319
320/* -------------------------------------------------------------------- */
323
328
330
331/* -------------------------------------------------------------------- */
334
339size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file)
340 ATTR_NONNULL(1, 3);
345size_t BLI_path_append_dir(char *__restrict dst, size_t dst_maxncpy, const char *__restrict dir)
346 ATTR_NONNULL(1, 3);
347
349
350/* -------------------------------------------------------------------- */
353
357size_t BLI_path_join_array(char *__restrict dst,
358 const size_t dst_maxncpy,
359 const char *path_array[],
360 const int path_array_num) ATTR_NONNULL(1, 3);
361
377#define BLI_path_join(...) VA_NARGS_CALL_OVERLOAD(_BLI_path_join_, __VA_ARGS__)
378
379#define _BLI_PATH_JOIN_ARGS_1 char *__restrict dst, size_t dst_maxncpy, const char *a
380#define _BLI_PATH_JOIN_ARGS_2 _BLI_PATH_JOIN_ARGS_1, const char *b
381#define _BLI_PATH_JOIN_ARGS_3 _BLI_PATH_JOIN_ARGS_2, const char *c
382#define _BLI_PATH_JOIN_ARGS_4 _BLI_PATH_JOIN_ARGS_3, const char *d
383#define _BLI_PATH_JOIN_ARGS_5 _BLI_PATH_JOIN_ARGS_4, const char *e
384#define _BLI_PATH_JOIN_ARGS_6 _BLI_PATH_JOIN_ARGS_5, const char *f
385#define _BLI_PATH_JOIN_ARGS_7 _BLI_PATH_JOIN_ARGS_6, const char *g
386#define _BLI_PATH_JOIN_ARGS_8 _BLI_PATH_JOIN_ARGS_7, const char *h
387#define _BLI_PATH_JOIN_ARGS_9 _BLI_PATH_JOIN_ARGS_8, const char *i
388#define _BLI_PATH_JOIN_ARGS_10 _BLI_PATH_JOIN_ARGS_9, const char *j
389
400
402{
403 const char *path_array[] = {a};
404 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
405}
407{
408 const char *path_array[] = {a, b};
409 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
410}
412{
413 const char *path_array[] = {a, b, c};
414 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
415}
417{
418 const char *path_array[] = {a, b, c, d};
419 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
420}
422{
423 const char *path_array[] = {a, b, c, d, e};
424 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
425}
427{
428 const char *path_array[] = {a, b, c, d, e, f};
429 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
430}
432{
433 const char *path_array[] = {a, b, c, d, e, f, g};
434 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
435}
437{
438 const char *path_array[] = {a, b, c, d, e, f, g, h};
439 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
440}
442{
443 const char *path_array[] = {a, b, c, d, e, f, g, h, i};
444 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
445}
447{
448 const char *path_array[] = {a, b, c, d, e, f, g, h, i, j};
449 return BLI_path_join_array(dst, dst_maxncpy, path_array, ARRAY_SIZE(path_array));
450}
451
452#undef _BLI_PATH_JOIN_ARGS_1
453#undef _BLI_PATH_JOIN_ARGS_2
454#undef _BLI_PATH_JOIN_ARGS_3
455#undef _BLI_PATH_JOIN_ARGS_4
456#undef _BLI_PATH_JOIN_ARGS_5
457#undef _BLI_PATH_JOIN_ARGS_6
458#undef _BLI_PATH_JOIN_ARGS_7
459#undef _BLI_PATH_JOIN_ARGS_8
460#undef _BLI_PATH_JOIN_ARGS_9
461#undef _BLI_PATH_JOIN_ARGS_10
462
464
465/* -------------------------------------------------------------------- */
468
473const char *BLI_path_extension_or_end(const char *filepath)
479const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
480
484bool BLI_path_extension_check(const char *path, const char *ext)
486bool BLI_path_extension_check_n(const char *path, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
490bool BLI_path_extension_check_array(const char *path, const char **ext_array)
496bool BLI_path_extension_check_glob(const char *path, const char *ext_fnmatch)
507bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL(1);
512bool BLI_path_extension_replace(char *path, size_t path_maxncpy, const char *ext)
513 ATTR_NONNULL(1, 3);
518bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1);
522bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext)
523 ATTR_NONNULL(1, 3);
524
526
527/* -------------------------------------------------------------------- */
530
531/* Path string comparisons: case-insensitive for Windows, case-sensitive otherwise. */
532#if defined(WIN32)
533# define BLI_path_cmp BLI_strcasecmp
534# define BLI_path_ncmp BLI_strncasecmp
535#else
536# define BLI_path_cmp strcmp
537# define BLI_path_ncmp strncmp
538#endif
539
551int BLI_path_cmp_normalized(const char *p1, const char *p2)
553
555bool BLI_path_contains(const char *container_path, const char *containee_path)
557
559
560/* -------------------------------------------------------------------- */
563
564#ifdef _WIN32
565bool BLI_path_program_extensions_add_win32(char *program_name, size_t program_name_maxncpy);
566#endif
571 size_t program_filepath_maxncpy,
572 const char *program_name) ATTR_NONNULL(1, 3);
573
575
576/* -------------------------------------------------------------------- */
579
584void BLI_path_sequence_encode(char *path,
585 size_t path_maxncpy,
586 const char *head,
587 const char *tail,
588 unsigned short numlen,
589 int pic);
590
602int BLI_path_sequence_decode(const char *path,
603 char *head,
604 size_t head_maxncpy,
605 char *tail,
606 size_t tail_maxncpy,
607 unsigned short *r_digits_len);
608
610
611/* -------------------------------------------------------------------- */
614
619bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1);
625bool BLI_path_frame_range(char *path, size_t path_maxncpy, int sta, int end, int digits)
626 ATTR_NONNULL(1);
630bool BLI_path_frame_get(const char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL(1, 2, 3);
637void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxncpy) ATTR_NONNULL(1, 2);
642
644
645/* -------------------------------------------------------------------- */
648
663#ifndef FILE_MAXDIR
664# define FILE_MAXDIR 768
665# define FILE_MAXFILE 256
666# define FILE_MAX 1024
667#endif
668
679bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1, 2);
684void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1);
685
691
693
694/* -------------------------------------------------------------------- */
697
712bool BLI_path_abs_from_cwd(char *path, size_t path_maxncpy) ATTR_NONNULL(1);
713
715
716/* -------------------------------------------------------------------- */
719
720#ifdef WIN32
721# define SEP '\\'
722# define ALTSEP '/'
723# define SEP_STR "\\"
724# define ALTSEP_STR "/"
725#else
726# define SEP '/'
727# define ALTSEP '\\'
728# define SEP_STR "/"
729# define ALTSEP_STR "\\"
730#endif
731
736{
737 /* On UNIX it only makes sense to treat `/` as a path separator.
738 * On WIN32 either may be used. */
739 if (ch == SEP) {
740 return true;
741 }
742#ifdef WIN32
743 if (ch == ALTSEP) {
744 return true;
745 }
746#endif
747 return false;
748}
749
751
752/* -------------------------------------------------------------------- */
757
762void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
769void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
778const char *BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
779
781
782/* -------------------------------------------------------------------- */
785
786/* Parent and current dir helpers. */
787#define FILENAME_PARENT ".."
788#define FILENAME_CURRENT "."
789
790/* Avoid calling `strcmp` on one or two chars! */
791#define FILENAME_IS_PARENT(_n) (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
792#define FILENAME_IS_CURRENT(_n) (((_n)[0] == '.') && ((_n)[1] == '\0'))
793#define FILENAME_IS_CURRPAR(_n) \
794 (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
795
#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:57
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
i
Definition text_draw.cc:230